]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd_warning.sh.in
4f9142519641ee1197ca7fba1d1e11da350ced75
3 # smartd warning script
5 # Home page of code is: http://www.smartmontools.org
7 # Copyright (C) 2012-16 Christian Franke
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # You should have received a copy of the GNU General Public License
15 # (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
17 # $Id: smartd_warning.sh.in 4351 2016-10-17 18:53:40Z chrfranke $
22 # Set by config.status
23 @ENABLE_SCRIPTPATH_TRUE@
export PATH
="@scriptpath@"
27 sysconfdir
="@sysconfdir@"
28 smartdscriptdir
="@smartdscriptdir@"
31 os_mailer
="@os_mailer@"
33 # Plugin directory (disabled if empty)
34 plugindir
="@smartdplugindir@"
39 --dryrun) dryrun
=t
; shift ;;
44 smartd $VERSION warning message script
47 export SMARTD_MAILER='Path to external script, empty for "$os_mailer"'
48 export SMARTD_ADDRESS='Space separated mail adresses, empty if none'
49 export SMARTD_MESSAGE='Error Message'
50 export SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests'
51 export SMARTD_TFIRST='Date of first message sent, empty if none'
52 #export SMARTD_TFIRSTEPOCH='time_t format of above'
53 export SMARTD_PREVCNT='Number of previous messages, 0 if none'
54 export SMARTD_NEXTDAYS='Number of days until next message, empty if none'
55 export SMARTD_DEVICEINFO='Device identify information'
56 #export SMARTD_DEVICE='Device name'
57 #export SMARTD_DEVICESTRING='Annotated device name'
58 #export SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none'
64 if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then
65 echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2
69 # Get host and domain names
70 for cmd
in @os_hostname@
'echo "[Unknown]"'; do
71 hostname
=`eval $cmd 2>/dev/null` ||
continue
72 test -n "$hostname" ||
continue
76 dnsdomain
=${hostname#*.}
77 if [ "$dnsdomain" != "$hostname" ]; then
78 # hostname command printed FQDN
79 hostname
=${hostname%%.*}
81 for cmd
in @os_dnsdomainname@
'echo'; do
82 dnsdomain
=`eval $cmd 2>/dev/null` ||
continue
85 test "$dnsdomain" != "(none)" || dnsdomain
=
88 for cmd
in @os_nisdomainname@
'echo'; do
89 nisdomain
=`eval $cmd 2>/dev/null` ||
continue
92 test "$nisdomain" != "(none)" || nisdomain
=
95 export SMARTD_SUBJECT
="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"
99 echo "This message was generated by the smartd daemon running on:"
101 echo " host name: $hostname"
102 echo " DNS domain: ${dnsdomain:-[Empty]}"
103 test -z "$nisdomain" ||
104 echo " NIS domain: $nisdomain"
105 @OS_WIN32_TRUE@test -z "$USERDOMAIN" ||
106 @OS_WIN32_TRUE@ echo " Win domain: $USERDOMAIN"
108 echo "The following warning/error was logged by the smartd daemon:"
110 echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}"
113 echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}"
115 echo "For details see host's SYSLOG."
116 if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then
118 echo "You can also use the smartctl utility for further investigation."
119 test "$SMARTD_PREVCNT" = "0" ||
120 echo "The original message about this issue was sent at ${SMARTD_TFIRST-[SMARTD_TFIRST]}"
121 case $SMARTD_NEXTDAYS in
122 '') echo "No additional messages about this problem will be sent." ;;
123 1) echo "Another message will be sent in 24 hours if the problem persists." ;;
124 *) echo "Another message will be sent in $SMARTD_NEXTDAYS days if the problem persists." ;;
129 # Export message with trailing newline
130 export SMARTD_FULLMESSAGE
="$fullmessage
133 # Run plugin scripts if requested
134 if test -n "$plugindir"; then
135 case " $SMARTD_ADDRESS" in
137 if [ -n "$dryrun" ]; then
138 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
139 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
142 # Run ALL scripts if requested
143 case " $SMARTD_ADDRESS " in
145 for cmd
in "$plugindir"/*; do
146 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
147 if [ -n "$dryrun" ]; then
148 echo "$cmd </dev/null"
157 # Run selected scripts
158 addrs
=$SMARTD_ADDRESS
165 cmd
="$plugindir/${ad#@}"
166 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
167 if [ -n "$dryrun" ]; then
168 echo "$cmd </dev/null"
172 elif [ ! -e "$cmd" ]; then
173 echo "$cmd: Not found" >&2
177 SMARTD_ADDRESS
="${SMARTD_ADDRESS:+ }$ad"
182 # Send email to remaining addresses
183 test -n "$SMARTD_ADDRESS" ||
exit 0
188 # Send mail or run command
189 if [ -n "$SMARTD_ADDRESS" ]; then
191 # Send mail, use platform mailer by default
192 test -n "$SMARTD_MAILER" || SMARTD_MAILER
=$os_mailer
193 if [ -n "$dryrun" ]; then
194 echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' $SMARTD_ADDRESS <<EOF
198 exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS <<EOF
203 elif [ -n "$SMARTD_MAILER" ]; then
206 if [ -n "$dryrun" ]; then
207 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
208 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
209 echo "exec '$SMARTD_MAILER' </dev/null"
212 exec "$SMARTD_MAILER" </dev
/null