]>
git.proxmox.com Git - mirror_smartmontools-debian.git/blob - smartd_warning.sh.in
1cc268357caf0b291f0f0cff1eefe1b870e31095
3 # smartd warning script
5 # Home page of code is: http://www.smartmontools.org
7 # Copyright (C) 2012-16 Christian Franke
9 # SPDX-License-Identifier: GPL-2.0-or-later
11 # $Id: smartd_warning.sh.in 4839 2018-11-27 18:26:08Z chrfranke $
16 # Set by config.status
17 @ENABLE_SCRIPTPATH_TRUE@
export PATH
="@scriptpath@"
21 sysconfdir
="@sysconfdir@"
22 smartdscriptdir
="@smartdscriptdir@"
25 os_mailer
="@os_mailer@"
27 # Plugin directory (disabled if empty)
28 plugindir
="@smartdplugindir@"
33 --dryrun) dryrun
=t
; shift ;;
38 smartd $VERSION warning message script
41 export SMARTD_MAILER='Path to external script, empty for "$os_mailer"'
42 export SMARTD_ADDRESS='Space separated mail addresses, empty if none'
43 export SMARTD_MESSAGE='Error Message'
44 export SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests'
45 export SMARTD_TFIRST='Date of first message sent, empty if none'
46 #export SMARTD_TFIRSTEPOCH='time_t format of above'
47 export SMARTD_PREVCNT='Number of previous messages, 0 if none'
48 export SMARTD_NEXTDAYS='Number of days until next message, empty if none'
49 export SMARTD_DEVICEINFO='Device identify information'
50 #export SMARTD_DEVICE='Device name'
51 #export SMARTD_DEVICESTRING='Annotated device name'
52 #export SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none'
58 if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then
59 echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2
63 # Get host and domain names
64 for cmd
in @os_hostname@
'echo "[Unknown]"'; do
65 hostname
=`eval $cmd 2>/dev/null` ||
continue
66 test -n "$hostname" ||
continue
70 dnsdomain
=${hostname#*.}
71 if [ "$dnsdomain" != "$hostname" ]; then
72 # hostname command printed FQDN
73 hostname
=${hostname%%.*}
75 for cmd
in @os_dnsdomainname@
'echo'; do
76 dnsdomain
=`eval $cmd 2>/dev/null` ||
continue
79 test "$dnsdomain" != "(none)" || dnsdomain
=
82 for cmd
in @os_nisdomainname@
'echo'; do
83 nisdomain
=`eval $cmd 2>/dev/null` ||
continue
86 test "$nisdomain" != "(none)" || nisdomain
=
89 export SMARTD_SUBJECT
="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"
93 echo "This message was generated by the smartd daemon running on:"
95 echo " host name: $hostname"
96 echo " DNS domain: ${dnsdomain:-[Empty]}"
97 test -z "$nisdomain" ||
98 echo " NIS domain: $nisdomain"
99 @OS_WIN32_TRUE@test -z "$USERDOMAIN" ||
100 @OS_WIN32_TRUE@ echo " Win domain: $USERDOMAIN"
102 echo "The following warning/error was logged by the smartd daemon:"
104 echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}"
107 echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}"
109 echo "For details see host's SYSLOG."
110 if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then
112 echo "You can also use the smartctl utility for further investigation."
113 test "$SMARTD_PREVCNT" = "0" ||
114 echo "The original message about this issue was sent at ${SMARTD_TFIRST-[SMARTD_TFIRST]}"
115 case $SMARTD_NEXTDAYS in
116 '') echo "No additional messages about this problem will be sent." ;;
117 1) echo "Another message will be sent in 24 hours if the problem persists." ;;
118 *) echo "Another message will be sent in $SMARTD_NEXTDAYS days if the problem persists." ;;
123 # Export message with trailing newline
124 export SMARTD_FULLMESSAGE
="$fullmessage
127 # Run plugin scripts if requested
128 if test -n "$plugindir"; then
129 case " $SMARTD_ADDRESS" in
131 if [ -n "$dryrun" ]; then
132 echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
133 echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
136 # Run ALL scripts if requested
137 case " $SMARTD_ADDRESS " in
139 for cmd
in "$plugindir"/*; do
140 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
141 if [ -n "$dryrun" ]; then
142 echo "$cmd </dev/null"
151 # Run selected scripts
152 addrs
=$SMARTD_ADDRESS
159 cmd
="$plugindir/${ad#@}"
160 if [ -f "$cmd" ] && [ -x "$cmd" ]; then
161 if [ -n "$dryrun" ]; then
162 echo "$cmd </dev/null"
166 elif [ ! -e "$cmd" ]; then
167 echo "$cmd: Not found" >&2
171 SMARTD_ADDRESS
="${SMARTD_ADDRESS:+ }$ad"
176 # Send email to remaining addresses
177 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