]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd_warning.sh.in
3 # smartd warning script
5 # Copyright (C) 2012-13 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 3809 2013-04-18 19:41:40Z chrfranke $
20 # Set by config.status
24 sysconfdir
="@sysconfdir@"
27 os_mailer
="@os_mailer@"
30 plugindir
="$sysconfdir/smartd_warning.d"
35 --dryrun) dryrun
=t
; shift ;;
40 smartd $VERSION warning message script
43 export SMARTD_MAILER='Path to external script, empty for "$os_mailer"'
44 export SMARTD_ADDRESS='Space separated mail adresses, empty if none'
45 export SMARTD_MESSAGE='Error Message'
46 export SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests'
47 export SMARTD_TFIRST='Date of first message sent, empty if none'
48 #export SMARTD_TFIRSTEPOCH='time_t format of above'
49 export SMARTD_PREVCNT='Number of previous messages, 0 if none'
50 export SMARTD_NEXTDAYS='Number of days until next message, empty if none'
51 export SMARTD_DEVICEINFO='Device identify information'
52 #export SMARTD_DEVICE='Device name'
53 #export SMARTD_DEVICESTRING='Annotated device name'
54 #export SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none'
60 if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then
61 echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2
65 # Get host and domain names
66 for cmd
in @os_hostname@
'echo "[Unknown]"'; do
67 hostname
=`eval $cmd 2>/dev/null` ||
continue
68 test -n "$hostname" ||
continue
72 dnsdomain
=${hostname#*.}
73 if [ "$dnsdomain" != "$hostname" ]; then
74 # hostname command printed FQDN
75 hostname
=${hostname%%.*}
77 for cmd
in @os_dnsdomainname@
'echo'; do
78 dnsdomain
=`eval $cmd 2>/dev/null` ||
continue
81 test "$dnsdomain" != "(none)" || dnsdomain
=
84 for cmd
in @os_nisdomainname@
'echo'; do
85 nisdomain
=`eval $cmd 2>/dev/null` ||
continue
88 test "$nisdomain" != "(none)" || nisdomain
=
91 export SMARTD_SUBJECT
="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"
95 echo "This message was generated by the smartd daemon running on:"
97 echo " host name: $hostname"
98 echo " DNS domain: ${dnsdomain:-[Empty]}"
99 test -z "$nisdomain" ||
100 echo " NIS domain: $nisdomain"
101 @OS_WIN32_TRUE@test -z "$USERDOMAIN" ||
102 @OS_WIN32_TRUE@ echo " Win domain: $USERDOMAIN"
104 echo "The following warning/error was logged by the smartd daemon:"
106 echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}"
109 echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}"
111 echo "For details see host's SYSLOG."
112 if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then
114 echo "You can also use the smartctl utility for further investigation."
115 test "$SMARTD_PREVCNT" = "0" ||
116 echo "The original message about this issue was sent at ${SMARTD_TFIRST-[SMARTD_TFIRST]}"
117 case $SMARTD_NEXTDAYS in
118 '') echo "No additional messages about this problem will be sent." ;;
119 1) echo "Another message will be sent in 24 hours if the problem persists." ;;
120 *) echo "Another message will be sent in $SMARTD_NEXTDAYS days if the problem persists." ;;
125 # Export message with trailing newline
126 export SMARTD_FULLMESSAGE
="$fullmessage
129 # Run plugin scripts if requested
130 case " $SMARTD_ADDRESS" in
132 if [ -n "$dryrun" ]; then
133 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
134 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
137 # Run ALL scripts if requested
138 case " $SMARTD_ADDRESS " in
140 for cmd
in "$plugindir"/*; do
141 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
142 if [ -n "$dryrun" ]; then
143 echo "$cmd </dev/null"
152 # Run selected scripts
153 addrs
=$SMARTD_ADDRESS
160 cmd
="$plugindir/${ad#@}"
161 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
162 if [ -n "$dryrun" ]; then
163 echo "$cmd </dev/null"
167 elif [ ! -e "$cmd" ]; then
168 echo "$cmd: Not found" >&2
172 SMARTD_ADDRESS
="${SMARTD_ADDRESS:+ }$ad"
177 # Send email to remaining addresses
178 test -n "$SMARTD_ADDRESS" ||
exit 0
182 # Send mail or run command
183 if [ -n "$SMARTD_ADDRESS" ]; then
185 # Send mail, use platform mailer by default
186 test -n "$SMARTD_MAILER" || SMARTD_MAILER
=$os_mailer
187 if [ -n "$dryrun" ]; then
188 echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' $SMARTD_ADDRESS <<EOF
192 exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS <<EOF
197 elif [ -n "$SMARTD_MAILER" ]; then
200 if [ -n "$dryrun" ]; then
201 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
202 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
203 echo "exec '$SMARTD_MAILER' </dev/null"
206 exec "$SMARTD_MAILER" </dev
/null