1: @echo off
2: ::
3: :: smartd warning script
4: ::
5: :: Copyright (C) 2012 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.cmd,v 1.1.1.1 2013/07/22 01:17:36 misho Exp $
16: ::
17:
18: set err=
19:
20: :: Parse options
21: set dryrun=
22: if "%1" == "--dryrun" (
23: set dryrun=t
24: shift
25: )
26:
27: if not "%1" == "" (
28: echo smartd warning message script
29: echo.
30: echo Usage:
31: echo set SMARTD_MAILER='Path to external script, empty for "blat"'
32: echo set SMARTD_ADDRESS='Space separated mail adresses, empty if none'
33: echo set SMARTD_MESSAGE='Error Message'
34: echo set SMARTD_FAILTYPE='Type of failure, "EMailTest" for tests'
35: echo set SMARTD_TFIRST='Date of first message sent, empty if none'
36: echo set SMARTD_TFIRSTEPOCH='time_t format of above'
37: echo set SMARTD_PREVCNT='Number of previous messages, 0 if none'
38: echo set SMARTD_NEXTDAYS='Number of days until next message, empty if none'
39: echo set SMARTD_DEVICEINFO='Device identify information'
40: echo :: set SMARTD_DEVICE='Device name'
41: echo :: set SMARTD_DEVICESTRING='Annotated device name'
42: echo :: set SMARTD_DEVICETYPE='Device type from -d directive, "auto" if none'
43:
44: echo smartd_warning.cmd [--dryrun]
45: goto EOF
46: )
47:
48: if "%SMARTD_ADDRESS%%SMARTD_MAILER%" == "" (
49: echo smartd_warning.cmd: SMARTD_ADDRESS or SMARTD_MAILER must be set
50: goto EOF
51: )
52:
53: :: Format subject
54: set SMARTD_SUBJECT=SMART error (%SMARTD_FAILTYPE%) detected on host: %COMPUTERNAME%
55:
56: :: Temp file for message
57: if not "%TMP%" == "" set SMARTD_FULLMSGFILE=%TMP%\smartd_warning-%DATE%-%RANDOM%.txt
58: if "%TMP%" == "" set SMARTD_FULLMSGFILE=smartd_warning-%DATE%-%RANDOM%.txt
59:
60: :: Format message
61: (
62: echo This message was generated by the smartd service running on:
63: echo.
64: echo. host name: %COMPUTERNAME%
65: if not "%USERDNSDOMAIN%" == "" echo. DNS domain: %USERDNSDOMAIN%
66: if "%USERDNSDOMAIN%" == "" echo. DNS domain: [Empty]
67: if not "%USERDOMAIN%" == "" echo. Win domain: %USERDOMAIN%
68: echo.
69: echo The following warning/error was logged by the smartd service:
70: echo.
71: :: SMARTD_MESSAGE and SMARTD_DEVICEINFO may contain parentheses
72: for %%m in ("%SMARTD_MESSAGE%") do echo.%%~m
73: echo.
74: echo Device info:
75: for %%m in ("%SMARTD_DEVICEINFO%") do echo.%%~m
76: set m=
77: echo.
78: echo For details see the event log or log file of smartd.
79: if not "%SMARTD_FAILTYPE%" == "EmailTest" (
80: echo.
81: echo You can also use the smartctl utility for further investigation.
82: if not "%SMARTD_PREVCNT%" == "0" echo The original message about this issue was sent at %SMARTD_TFIRST%
83: if "%SMARTD_NEXTDAYS%" == "" (
84: echo No additional messages about this problem will be sent.
85: ) else ( if "%SMARTD_NEXTDAYS%" == "1" (
86: echo Another message will be sent in 24 hours if the problem persists.
87: ) else (
88: echo Another message will be sent in %SMARTD_NEXTDAYS% days if the problem persists.
89: ))
90: )
91: ) > "%SMARTD_FULLMSGFILE%"
92:
93: if not "%dryrun%" == "" (
94: echo %SMARTD_FULLMSGFILE%:
95: type "%SMARTD_FULLMSGFILE%"
96: echo --EOF--
97: )
98:
99: :: Check first address
100: set first=
101: for /F "tokens=1*" %%a in ("%SMARTD_ADDRESS%") do (set first=%%a)
102: set wtssend=
103: if "%first%" == "console" set wtssend=-c
104: if "%first%" == "active" set wtssend=-a
105: if "%first%" == "connected" set wtssend=-s
106: set first=
107:
108: if not "%wtssend%" == "" (
109: :: Show Message box(es) via WTSSendMessage()
110: if not "%dryrun%" == "" (
111: echo call wtssendmsg %wtssend% "%SMARTD_SUBJECT%" - ^< "%SMARTD_FULLMSGFILE%"
112: ) else (
113: call wtssendmsg %wtssend% "%SMARTD_SUBJECT%" - < "%SMARTD_FULLMSGFILE%"
114: if errorlevel 1 set err=t
115: )
116: :: Remove first address
117: for /F "tokens=1*" %%a in ("%SMARTD_ADDRESS%") do (set SMARTD_ADDRESS=%%b)
118: )
119: set wtssend=
120:
121: :: Make comma separated address list
122: set SMARTD_ADDRCSV=
123: if not "%SMARTD_ADDRESS%" == "" set SMARTD_ADDRCSV=%SMARTD_ADDRESS: =,%
124:
125: :: Use blat mailer by default
126: if not "%SMARTD_ADDRESS%" == "" if "%SMARTD_MAILER%" == "" set SMARTD_MAILER=blat
127:
128: :: Send mail or run command
129: if not "%SMARTD_ADDRCSV%" == "" (
130:
131: :: Send mail
132: if not "%dryrun%" == "" (
133: echo call "%SMARTD_MAILER%" - -q -subject "%SMARTD_SUBJECT%" -to "%SMARTD_ADDRCSV%" ^< "%SMARTD_FULLMSGFILE%"
134: ) else (
135: call "%SMARTD_MAILER%" - -q -subject "%SMARTD_SUBJECT%" -to "%SMARTD_ADDRCSV%" < "%SMARTD_FULLMSGFILE%"
136: if errorlevel 1 set err=t
137: )
138:
139: ) else ( if not "%SMARTD_MAILER%" == "" (
140:
141: :: Run command
142: if not "%dryrun%" == "" (
143: echo call "%SMARTD_MAILER%" ^<nul
144: ) else (
145: call "%SMARTD_MAILER%" <nul
146: if errorlevel 1 set err=t
147: )
148:
149: ))
150:
151: del "%SMARTD_FULLMSGFILE%" >nul 2>nul
152:
153: :EOF
154: if not "%err%" == "" goto ERROR 2>nul
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>