]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd_warning.sh.in
3 # smartd warning script
5 # Copyright (C) 2012-14 Christian Franke <smartmontools-support@lists.sourceforge.net>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # You should have received a copy of the GNU General Public License
13 # (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
15 # $Id: smartd_warning.sh.in 3932 2014-06-29 19:02:38Z chrfranke $
20 # Set by config.status
24 sysconfdir
="@sysconfdir@"
25 smartdscriptdir
="@smartdscriptdir@"
28 os_mailer
="@os_mailer@"
30 # Plugin directory (disabled if empty)
31 plugindir
="@smartdplugindir@"
36 --dryrun) dryrun
=t
; shift ;;
41 smartd $VERSION warning message script
44 export SMARTD_MAILER='Path to external script, empty for "$os_mailer"'
45 export SMARTD_ADDRESS='Space separated mail adresses, empty if none'
46 export SMARTD_MESSAGE='Error Message'
47 export SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests'
48 export SMARTD_TFIRST='Date of first message sent, empty if none'
49 #export SMARTD_TFIRSTEPOCH='time_t format of above'
50 export SMARTD_PREVCNT='Number of previous messages, 0 if none'
51 export SMARTD_NEXTDAYS='Number of days until next message, empty if none'
52 export SMARTD_DEVICEINFO='Device identify information'
53 #export SMARTD_DEVICE='Device name'
54 #export SMARTD_DEVICESTRING='Annotated device name'
55 #export SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none'
61 if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then
62 echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2
66 # Get host and domain names
67 for cmd
in @os_hostname@
'echo "[Unknown]"'; do
68 hostname
=`eval $cmd 2>/dev/null` ||
continue
69 test -n "$hostname" ||
continue
73 dnsdomain
=${hostname#*.}
74 if [ "$dnsdomain" != "$hostname" ]; then
75 # hostname command printed FQDN
76 hostname
=${hostname%%.*}
78 for cmd
in @os_dnsdomainname@
'echo'; do
79 dnsdomain
=`eval $cmd 2>/dev/null` ||
continue
82 test "$dnsdomain" != "(none)" || dnsdomain
=
85 for cmd
in @os_nisdomainname@
'echo'; do
86 nisdomain
=`eval $cmd 2>/dev/null` ||
continue
89 test "$nisdomain" != "(none)" || nisdomain
=
92 export SMARTD_SUBJECT
="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"
96 echo "This message was generated by the smartd daemon running on:"
98 echo " host name: $hostname"
99 echo " DNS domain: ${dnsdomain:-[Empty]}"
100 test -z "$nisdomain" ||
101 echo " NIS domain: $nisdomain"
102 @OS_WIN32_TRUE@test -z "$USERDOMAIN" ||
103 @OS_WIN32_TRUE@ echo " Win domain: $USERDOMAIN"
105 echo "The following warning/error was logged by the smartd daemon:"
107 echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}"
110 echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}"
112 echo "For details see host's SYSLOG."
113 if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then
115 echo "You can also use the smartctl utility for further investigation."
116 test "$SMARTD_PREVCNT" = "0" ||
117 echo "The original message about this issue was sent at ${SMARTD_TFIRST-[SMARTD_TFIRST]}"
118 case $SMARTD_NEXTDAYS in
119 '') echo "No additional messages about this problem will be sent." ;;
120 1) echo "Another message will be sent in 24 hours if the problem persists." ;;
121 *) echo "Another message will be sent in $SMARTD_NEXTDAYS days if the problem persists." ;;
126 # Export message with trailing newline
127 export SMARTD_FULLMESSAGE
="$fullmessage
130 # Run plugin scripts if requested
131 if test -n "$plugindir"; then
132 case " $SMARTD_ADDRESS" in
134 if [ -n "$dryrun" ]; then
135 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
136 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
139 # Run ALL scripts if requested
140 case " $SMARTD_ADDRESS " in
142 for cmd
in "$plugindir"/*; do
143 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
144 if [ -n "$dryrun" ]; then
145 echo "$cmd </dev/null"
154 # Run selected scripts
155 addrs
=$SMARTD_ADDRESS
162 cmd
="$plugindir/${ad#@}"
163 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
164 if [ -n "$dryrun" ]; then
165 echo "$cmd </dev/null"
169 elif [ ! -e "$cmd" ]; then
170 echo "$cmd: Not found" >&2
174 SMARTD_ADDRESS
="${SMARTD_ADDRESS:+ }$ad"
179 # Send email to remaining addresses
180 test -n "$SMARTD_ADDRESS" ||
exit 0
185 # Send mail or run command
186 if [ -n "$SMARTD_ADDRESS" ]; then
188 # Send mail, use platform mailer by default
189 test -n "$SMARTD_MAILER" || SMARTD_MAILER
=$os_mailer
190 if [ -n "$dryrun" ]; then
191 echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' $SMARTD_ADDRESS <<EOF
195 exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS <<EOF
200 elif [ -n "$SMARTD_MAILER" ]; then
203 if [ -n "$dryrun" ]; then
204 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
205 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
206 echo "exec '$SMARTD_MAILER' </dev/null"
209 exec "$SMARTD_MAILER" </dev
/null