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