Annotation of embedaddon/smartmontools/smartd_warning.sh.in, revision 1.1.1.1
1.1 misho 1: #! /bin/sh
2: #
3: # smartd warning script
4: #
5: # Copyright (C) 2012-13 Christian Franke <smartmontools-support@lists.sourceforge.net>
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: #
15: # $Id: smartd_warning.sh.in 3784 2013-03-06 22:02:54Z chrfranke $
16: #
17:
18: set -e
19:
20: # Set by config.status
21: PACKAGE="@PACKAGE@"
22: VERSION="@VERSION@"
23: prefix="@prefix@"
24: sysconfdir="@sysconfdir@"
25:
26: # Default mailer
27: os_mailer="@os_mailer@"
28:
29: # Plugin directory
30: plugindir="$sysconfdir/smartd_warning.d"
31:
32: # Parse options
33: dryrun=
34: case $1 in
35: --dryrun) dryrun=t; shift ;;
36: esac
37:
38: if [ $# != 0 ]; then
39: cat <<EOF
40: smartd $VERSION warning message script
41:
42: Usage:
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'
55: $0 [--dryrun]
56: EOF
57: exit 1
58: fi
59:
60: if [ -z "${SMARTD_ADDRESS}${SMARTD_MAILER}" ]; then
61: echo "$0: SMARTD_ADDRESS or SMARTD_MAILER must be set" >&2
62: exit 1
63: fi
64:
65: # Get host and domain names
66: for cmd in 'hostname' 'uname -n' 'echo "${HOSTNAME?unset}"' 'echo "[Unknown]"'; do
67: hostname=`eval $cmd 2>/dev/null` || continue
68: test -n "$hostname" || continue
69: break
70: done
71:
72: dnsdomain=${hostname#*.}
73: if [ "$dnsdomain" != "$hostname" ]; then
74: # BSD 'hostname' prints FQDN
75: hostname=${hostname%%.*}
76: else
77: # Linux Cygwin
78: for cmd in 'dnsdomainname' 'echo "${USERDNSDOMAIN?unset}"' 'echo'; do
79: dnsdomain=`eval $cmd 2>/dev/null` || continue
80: break
81: done
82: fi
83:
84: for cmd in 'nisdomainname' 'ypdomainname' 'domainname' 'echo'; do
85: nisdomain=`eval $cmd 2>/dev/null` || continue
86: break
87: done
88: test "$nisdomain" != "(none)" || nisdomain=
89:
90: case $OS in
91: Windows*) windomain=$USERDOMAIN ;;
92: *) windomain= ;;
93: esac
94:
95: # Format subject
96: export SMARTD_SUBJECT="SMART error (${SMARTD_FAILTYPE-[SMARTD_FAILTYPE]}) detected on host: $hostname"
97:
98: # Format message
99: fullmessage=`
100: echo "This message was generated by the smartd daemon running on:"
101: echo
102: echo " host name: $hostname"
103: echo " DNS domain: ${dnsdomain:-[Empty]}"
104: test -z "$nisdomain" ||
105: echo " NIS domain: $nisdomain"
106: test -z "$windomain" ||
107: echo " Win domain: $windomain"
108: echo
109: echo "The following warning/error was logged by the smartd daemon:"
110: echo
111: echo "${SMARTD_MESSAGE-[SMARTD_MESSAGE]}"
112: echo
113: echo "Device info:"
114: echo "${SMARTD_DEVICEINFO-[SMARTD_DEVICEINFO]}"
115: echo
116: echo "For details see host's SYSLOG."
117: if [ "$SMARTD_FAILTYPE" != "EmailTest" ]; then
118: echo
119: echo "You can also use the smartctl utility for further investigation."
120: test "$SMARTD_PREVCNT" = "0" ||
121: echo "The original message about this issue was sent at ${SMARTD_TFIRST-[SMARTD_TFIRST]}"
122: case $SMARTD_NEXTDAYS in
123: '') echo "No additional messages about this problem will be sent." ;;
124: 1) echo "Another message will be sent in 24 hours if the problem persists." ;;
125: *) echo "Another message will be sent in $SMARTD_NEXTDAYS days if the problem persists." ;;
126: esac
127: fi
128: `
129:
130: # Export message with trailing newline
131: export SMARTD_FULLMESSAGE="$fullmessage
132: "
133:
134: # Run plugin scripts if requested
135: case " $SMARTD_ADDRESS" in
136: *\ @*)
137: if [ -n "$dryrun" ]; then
138: echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
139: echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
140: fi
141:
142: # Run ALL scripts if requested
143: case " $SMARTD_ADDRESS " in
144: *\ @ALL\ *)
145: for cmd in "$plugindir"/*; do
146: if [ -f "$cmd" ] && [ -x "$cmd" ]; then
147: if [ -n "$dryrun" ]; then
148: echo "$cmd </dev/null"
149: else
150: "$cmd" </dev/null
151: fi
152: fi
153: done
154: ;;
155: esac
156:
157: # Run selected scripts
158: addrs=$SMARTD_ADDRESS
159: SMARTD_ADDRESS=
160: for ad in $addrs; do
161: case $ad in
162: @ALL)
163: ;;
164: @?*)
165: cmd="$plugindir/${ad#@}"
166: if [ -f "$cmd" ] && [ -x "$cmd" ]; then
167: if [ -n "$dryrun" ]; then
168: echo "$cmd </dev/null"
169: else
170: "$cmd" </dev/null
171: fi
172: elif [ ! -e "$cmd" ]; then
173: echo "$cmd: Not found" >&2
174: fi
175: ;;
176: *)
177: SMARTD_ADDRESS="${SMARTD_ADDRESS:+ }$ad"
178: ;;
179: esac
180: done
181:
182: # Send email to remaining addresses
183: test -n "$SMARTD_ADDRESS" || exit 0
184: ;;
185: esac
186:
187: # Send mail or run command
188: if [ -n "$SMARTD_ADDRESS" ]; then
189:
190: # Send mail, use platform mailer by default
191: test -n "$SMARTD_MAILER" || SMARTD_MAILER=$os_mailer
192: if [ -n "$dryrun" ]; then
193: echo "exec '$SMARTD_MAILER' -s '$SMARTD_SUBJECT' $SMARTD_ADDRESS <<EOF
194: $fullmessage
195: EOF"
196: else
197: exec "$SMARTD_MAILER" -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS <<EOF
198: $fullmessage
199: EOF
200: fi
201:
202: elif [ -n "$SMARTD_MAILER" ]; then
203:
204: # Run command
205: if [ -n "$dryrun" ]; then
206: echo "export SMARTD_SUBJECT='$SMARTD_SUBJECT'"
207: echo "export SMARTD_FULLMESSAGE='$SMARTD_FULLMESSAGE'"
208: echo "exec '$SMARTD_MAILER' </dev/null"
209: else
210: unset SMARTD_ADDRESS
211: exec "$SMARTD_MAILER" </dev/null
212: fi
213:
214: fi
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>