]>
Commit | Line | Data |
---|---|---|
ee38a438 GI |
1 | #! /bin/sh |
2 | # | |
3 | # smartd warning script | |
4 | # | |
f9e10201 JD |
5 | # Home page of code is: http://www.smartmontools.org |
6 | # | |
7 | # Copyright (C) 2012-16 Christian Franke | |
ee38a438 | 8 | # |
ff28b140 | 9 | # SPDX-License-Identifier: GPL-2.0-or-later |
ee38a438 | 10 | # |
ff28b140 | 11 | # $Id: smartd_warning.sh.in 4839 2018-11-27 18:26:08Z chrfranke $ |
ee38a438 GI |
12 | # |
13 | ||
14 | set -e | |
15 | ||
16 | # Set by config.status | |
f9e10201 | 17 | @ENABLE_SCRIPTPATH_TRUE@export PATH="@scriptpath@" |
ee38a438 GI |
18 | PACKAGE="@PACKAGE@" |
19 | VERSION="@VERSION@" | |
20 | prefix="@prefix@" | |
21 | sysconfdir="@sysconfdir@" | |
d2e702cf | 22 | smartdscriptdir="@smartdscriptdir@" |
ee38a438 GI |
23 | |
24 | # Default mailer | |
25 | os_mailer="@os_mailer@" | |
26 | ||
d2e702cf GI |
27 | # Plugin directory (disabled if empty) |
28 | plugindir="@smartdplugindir@" | |
ee38a438 GI |
29 | |
30 | # Parse options | |
31 | dryrun= | |
32 | case $1 in | |
33 | --dryrun) dryrun=t; shift ;; | |
34 | esac | |
35 | ||
36 | if [ $# != 0 ]; then | |
37 | cat <<EOF | |
38 | smartd $VERSION warning message script | |
39 | ||
40 | Usage: | |
41 | export SMARTD_MAILER='Path to external script, empty for "$os_mailer"' | |
ff28b140 | 42 | export SMARTD_ADDRESS='Space separated mail addresses, empty if none' |
ee38a438 GI |
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' | |
53 | $0 [--dryrun] | |
54 | EOF | |
55 | exit 1 | |
56 | fi | |
57 | ||
58 | if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then | |
59 | echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2 | |
60 | exit 1 | |
61 | fi | |
62 | ||
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 | |
67 | break | |
68 | done | |
69 | ||
70 | dnsdomain=${hostname#*.} | |
71 | if [ "$dnsdomain" != "$hostname" ]; then | |
72 | # hostname command printed FQDN | |
73 | hostname=${hostname%%.*} | |
74 | else | |
75 | for cmd in @os_dnsdomainname@ 'echo'; do | |
76 | dnsdomain=`eval $cmd 2>/dev/null` || continue | |
77 | break | |
78 | done | |
79 | test "$dnsdomain" != "(none)" || dnsdomain= | |
80 | fi | |
81 | ||
82 | for cmd in @os_nisdomainname@ 'echo'; do | |
83 | nisdomain=`eval $cmd 2>/dev/null` || continue | |
84 | break | |
85 | done | |
86 | test "$nisdomain" != "(none)" || nisdomain= | |
87 | ||
88 | # Format subject | |
89 | export SMARTD_SUBJECT="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname" | |
90 | ||
91 | # Format message | |
92 | fullmessage=` | |
93 | echo "This message was generated by the smartd daemon running on:" | |
94 | echo | |
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" | |
101 | echo | |
102 | echo "The following warning/error was logged by the smartd daemon:" | |
103 | echo | |
104 | echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}" | |
105 | echo | |
106 | echo "Device info:" | |
107 | echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}" | |
108 | echo | |
109 | echo "For details see host's SYSLOG." | |
110 | if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then | |
111 | echo | |
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." ;; | |
119 | esac | |
120 | fi | |
121 | ` | |
122 | ||
123 | # Export message with trailing newline | |
124 | export SMARTD_FULLMESSAGE="$fullmessage | |
125 | " | |
126 | ||
127 | # Run plugin scripts if requested | |
d2e702cf GI |
128 | if test -n "$plugindir"; then |
129 | case " $SMARTD_ADDRESS" in | |
ee38a438 GI |
130 | *\ @*) |
131 | if [ -n "$dryrun" ]; then | |
132 | echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'" | |
133 | echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'" | |
134 | fi | |
135 | ||
136 | # Run ALL scripts if requested | |
137 | case " $SMARTD_ADDRESS " in | |
138 | *\ @ALL\ *) | |
139 | for cmd in "$plugindir"/*; do | |
140 | if [ -f "$cmd" ] && [ -x "$cmd" ]; then | |
141 | if [ -n "$dryrun" ]; then | |
142 | echo "$cmd </dev/null" | |
143 | else | |
144 | "$cmd" </dev/null | |
145 | fi | |
146 | fi | |
147 | done | |
148 | ;; | |
149 | esac | |
150 | ||
151 | # Run selected scripts | |
152 | addrs=$SMARTD_ADDRESS | |
153 | SMARTD_ADDRESS= | |
154 | for ad in $addrs; do | |
155 | case $ad in | |
156 | @ALL) | |
157 | ;; | |
158 | @?*) | |
159 | cmd="$plugindir/${ad#@}" | |
160 | if [ -f "$cmd" ] && [ -x "$cmd" ]; then | |
161 | if [ -n "$dryrun" ]; then | |
162 | echo "$cmd </dev/null" | |
163 | else | |
164 | "$cmd" </dev/null | |
165 | fi | |
166 | elif [ ! -e "$cmd" ]; then | |
167 | echo "$cmd: Not found" >&2 | |
168 | fi | |
169 | ;; | |
170 | *) | |
171 | SMARTD_ADDRESS="${SMARTD_ADDRESS:+ }$ad" | |
172 | ;; | |
173 | esac | |
174 | done | |
175 | ||
176 | # Send email to remaining addresses | |
177 | test -n "$SMARTD_ADDRESS" || exit 0 | |
178 | ;; | |
d2e702cf GI |
179 | esac |
180 | fi | |
ee38a438 GI |
181 | |
182 | # Send mail or run command | |
183 | if [ -n "$SMARTD_ADDRESS" ]; then | |
184 | ||
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 | |
189 | $fullmessage | |
190 | EOF" | |
191 | else | |
192 | exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS <<EOF | |
193 | $fullmessage | |
194 | EOF | |
195 | fi | |
196 | ||
197 | elif [ -n "$SMARTD_MAILER" ]; then | |
198 | ||
199 | # Run command | |
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" | |
204 | else | |
205 | unset SMARTD_ADDRESS | |
206 | exec "$SMARTD_MAILER" </dev/null | |
207 | fi | |
208 | ||
209 | fi |