]> git.proxmox.com Git - mirror_smartmontools-debian.git/blame - os_win32/smartd_warning.cmd
Correct maintscript syntax
[mirror_smartmontools-debian.git] / os_win32 / smartd_warning.cmd
CommitLineData
ee38a438
GI
1@echo off
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::
3d17a85c 15:: $Id: smartd_warning.cmd 3816 2013-06-09 16:16:11Z chrfranke $
ee38a438
GI
16::
17
18set err=
19
20:: Parse options
21set dryrun=
22if "%1" == "--dryrun" (
23 set dryrun=t
24 shift
25)
26
27if 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
48if "%SMARTD_ADDRESS%%SMARTD_MAILER%" == "" (
49 echo smartd_warning.cmd: SMARTD_ADDRESS or SMARTD_MAILER must be set
50 goto EOF
51)
52
53:: USERDNSDOMAIN may be unset if running as service
54if "%USERDNSDOMAIN%" == "" (
55 for /f "delims== tokens=2 usebackq" %%d in (`WMIC PATH Win32_Computersystem WHERE "PartOfDomain=TRUE" GET Domain /VALUE 2^>nul ^| find "Domain=" 2^>nul`) do set USERDNSDOMAIN=%%~d
56)
57
58:: Format subject
59set SMARTD_SUBJECT=SMART error (%SMARTD_FAILTYPE%) detected on host: %COMPUTERNAME%
60
61:: Temp file for message
3d17a85c
GI
62if not "%TMP%" == "" set SMARTD_FULLMSGFILE=%TMP%\smartd_warning-%RANDOM%.txt
63if "%TMP%" == "" set SMARTD_FULLMSGFILE=smartd_warning-%RANDOM%.txt
ee38a438
GI
64
65:: Format message
66(
67 echo This message was generated by the smartd service running on:
68 echo.
69 echo. host name: %COMPUTERNAME%
70 if not "%USERDNSDOMAIN%" == "" echo. DNS domain: %USERDNSDOMAIN%
71 if "%USERDNSDOMAIN%" == "" echo. DNS domain: [Empty]
72 if not "%USERDOMAIN%" == "" echo. Win domain: %USERDOMAIN%
73 echo.
74 echo The following warning/error was logged by the smartd service:
75 echo.
76 :: SMARTD_MESSAGE and SMARTD_DEVICEINFO may contain parentheses
77 for %%m in ("%SMARTD_MESSAGE%") do echo.%%~m
78 echo.
79 echo Device info:
80 for %%m in ("%SMARTD_DEVICEINFO%") do echo.%%~m
81 set m=
82 echo.
83 echo For details see the event log or log file of smartd.
84 if not "%SMARTD_FAILTYPE%" == "EmailTest" (
85 echo.
86 echo You can also use the smartctl utility for further investigation.
87 if not "%SMARTD_PREVCNT%" == "0" echo The original message about this issue was sent at %SMARTD_TFIRST%
88 if "%SMARTD_NEXTDAYS%" == "" (
89 echo No additional messages about this problem will be sent.
90 ) else ( if "%SMARTD_NEXTDAYS%" == "1" (
91 echo Another message will be sent in 24 hours if the problem persists.
92 ) else (
93 echo Another message will be sent in %SMARTD_NEXTDAYS% days if the problem persists.
94 ))
95 )
96) > "%SMARTD_FULLMSGFILE%"
97
98if not "%dryrun%" == "" (
99 echo %SMARTD_FULLMSGFILE%:
100 type "%SMARTD_FULLMSGFILE%"
101 echo --EOF--
102)
103
104:: Check first address
105set first=
106for /F "tokens=1*" %%a in ("%SMARTD_ADDRESS%") do (set first=%%a)
107set wtssend=
108if "%first%" == "console" set wtssend=-c
109if "%first%" == "active" set wtssend=-a
110if "%first%" == "connected" set wtssend=-s
111set first=
112
113if not "%wtssend%" == "" (
114 :: Show Message box(es) via WTSSendMessage()
115 if not "%dryrun%" == "" (
116 echo call wtssendmsg %wtssend% "%SMARTD_SUBJECT%" - ^< "%SMARTD_FULLMSGFILE%"
117 ) else (
118 call wtssendmsg %wtssend% "%SMARTD_SUBJECT%" - < "%SMARTD_FULLMSGFILE%"
119 if errorlevel 1 set err=t
120 )
121 :: Remove first address
122 for /F "tokens=1*" %%a in ("%SMARTD_ADDRESS%") do (set SMARTD_ADDRESS=%%b)
123)
124set wtssend=
125
126:: Make comma separated address list
127set SMARTD_ADDRCSV=
128if not "%SMARTD_ADDRESS%" == "" set SMARTD_ADDRCSV=%SMARTD_ADDRESS: =,%
129
130:: Use blat mailer by default
131if not "%SMARTD_ADDRESS%" == "" if "%SMARTD_MAILER%" == "" set SMARTD_MAILER=blat
132
133:: Send mail or run command
134if not "%SMARTD_ADDRCSV%" == "" (
135
136 :: Send mail
137 if not "%dryrun%" == "" (
138 echo call "%SMARTD_MAILER%" - -q -subject "%SMARTD_SUBJECT%" -to "%SMARTD_ADDRCSV%" ^< "%SMARTD_FULLMSGFILE%"
139 ) else (
140 call "%SMARTD_MAILER%" - -q -subject "%SMARTD_SUBJECT%" -to "%SMARTD_ADDRCSV%" < "%SMARTD_FULLMSGFILE%"
141 if errorlevel 1 set err=t
142 )
143
144) else ( if not "%SMARTD_MAILER%" == "" (
145
146 :: Run command
147 if not "%dryrun%" == "" (
148 echo call "%SMARTD_MAILER%" ^<nul
149 ) else (
150 call "%SMARTD_MAILER%" <nul
151 if errorlevel 1 set err=t
152 )
153
154))
155
156del "%SMARTD_FULLMSGFILE%" >nul 2>nul
157
158:EOF
159if not "%err%" == "" goto ERROR 2>nul