@ECHO OFF REM ************************************************************ REM REM Filename: CheckHpRaid.cmd REM Version: 1.1.3 REM Language: Windows batch file for Windows 2K/XP/2003/2008 REM Copyright: SysCo systèmes de communication sa REM Created: 2008-12-02 SysCo/al REM Last modified: 2010-03-20 SysCo/al REM Web site: http://developer.sysco.ch/hobbit/ REM Email: developer@sysco.ch REM REM SpecialThanks: "L.M.J" for the shell script version available REM here: http://code.google.com/p/hphwraid/ REM REM REM Description REM REM External batch script to autodect the amount of RAID Controllers, REM the amount of logical volume and the amount of plugged hard drive. REM Status is coming red if at least one disk or logical volume is REM down or rebuilding. REM Detail of the status is send (each controller, each disk, each volume) REM REM REM Usage REM REM The script has to be called by the Big Brother Client. It must be added REM in the Externals list (near the bottom of the Configuration Editor REM window of the Big Brother Client). The "Saved Logs Location" option of REM the client must be set to the same directory as the _bblogdir variable REM of the script. The first parameter (optional) can give the time validity (in minutes) REM REM Sample: CheckHpRaid.cmd +1500 REM REM REM External file needed REM REM HP ProLiant Array Configuration Utility (CLI) for Windows 2003 and up REM (ftp://ftp.hp.com/pub/softlib2/software1/sc-windows/p414707561/v47083/cp009103.exe) REM REM HP ProLiant Array Configuration Utility (CLI) Last version available for Windows 2000 REM (ftp://ftp.hp.com/pub/softlib2/software1/sc-windows/p308172811/v35552/cp006904.exe) REM REM If you are running Windows 2000, please copy the REG.EXE file from the CD-ROM REM (Support\Tools\REG.EXE) into the WINNT\system32 directory. REM REM REM External file created REM REM One log file in the configured location REM REM REM Special issues REM REM - The alarm name (currently raid) MUST be added in the REM svcerrlist list of the bbwarnsetup.cfg file of the server. REM REM - The script should be called in the "Externals list" of the client. REM REM - hostname environment variable can be used (see below) REM REM REM Licence REM REM Copyright (c) 2008-2010, SysCo systèmes de communication sa REM SysCo (tm) is a trademark of SysCo systèmes de communication sa REM (http://www.sysco.ch/) REM All rights reserved. REM REM This script is free software; you can redistribute it and/or REM modify it under the terms of the GNU Lesser General Public REM License as published by the Free Software Foundation; either REM version 2.1 of the License, or (at your option) any later version. REM REM This library is distributed in the hope that it will be useful, REM but WITHOUT ANY WARRANTY; without even the implied warranty of REM MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU REM Lesser General Public License for more details. REM REM You should have received a copy of the GNU Lesser General Public REM License along with this library; if not, write to the Free Software REM Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA REM (http://www.fsf.org/) REM REM REM Change Log REM REM 2010-03-20 1.1.3 SysCo/al Normalization REM 2010-02-19 1.1.2 SysCo/al Physical drive status was not reported correctly REM (if logical drive was down, all physical was reported red) REM More details if at least one disk is red REM 2009-03-23 1.1.1 SysCo/al Bug cleaning, thanks to Chris (initial line 227) REM 2009-02-04 1.1.0 SysCo/al The first parameter (optional) can give the time validity REM 2008-12-02 1.0.0 SysCo/al Initial release REM REM ************************************************************ REM ******************************************************** REM hpacucli command parameters (example) REM --------------------------- REM REM hpacucli ctrl all show REM Smart Array XXX in Slot N (sn: XXXXXXXXXXXX) REM REM hpacucli controller slot=2 physicaldrive all show status REM physicaldrive 1:0 (port 1:id 0, 18.2 GB): OK REM physicaldrive 1:1 (port 1:id 1, 18.2 GB): OK REM physicaldrive 1:2 (port 1:id 2, 18.2 GB): OK REM physicaldrive 1:3 (port 1:id 3, 36.4 GB): OK REM physicaldrive 1:4 (port 1:id 4, 36.4 GB): OK REM physicaldrive 1:5 (port 1:id 5, 36.4 GB): OK REM REM hpacucli controller slot=N logicaldrive all show status REM logicaldrive 1 (33.9 GB, RAID 5): OK REM logicaldrive 2 (67.8 GB, RAID 5): OK REM ******************************************************** SETLOCAL ENABLEDELAYEDEXPANSION REM ================================================== REM ========== OPTIONS MUST BE CHANGED HERE ========== IF NOT ""=="%1" SET _time_validity=%1 REM Define if you are still using the "regular" Big Brother client (SET _BBWin=0) REM or the GPL BBWin client (http://sourceforge.net/projects/bbwin) (SET _BBWin=1) SET _BBWin=1 REM Hostname sent to the server (string) REM If not defined, the environment variable hostname will be used SET _hostname= REM Logs location for external scripts (WITH the ending \) REM This folder must be the same has the one defined in the option REM "Saved Logs Location" of the Big Brother Client or the tmppath REM of the BBWin client. SET _bblogdir=C:\Logs\bbnt\ REM Auto-extraction of the tmppath of BBWin REM We are using the environment variable _bblogdir for backward compatibility REM If you are still running under Windows 2000 or before and you didn't copy REM the REG.EXE file, please comments these three lines and add an extra line REM SET _bblogdir=path_of_your_tmp_dir_for_BBWin IF NOT "!_BBWin!"=="1" GOTO NoBBWin FOR /f "tokens=2*" %%i, IN ('REG QUERY HKLM\SOFTWARE\BBWin /v tmppath ^| FIND "tmppath"') do SET _temp=%%j> NUL IF NOT "!_temp!"=="" SET _bblogdir=!_temp!\ :NoBBWin REM ========== END OF THE OPTIONS HERE ========== REM ============================================= REM ************************************************************ REM ************************************************************ REM REM Main part of the script, please do not change anything REM without knowing what you are doing !!! REM REM ************************************************************ REM ************************************************************ REM Alarm name (should not be changed) REM This name MUST be added in the svcerrlist list of the bbwarnsetup.cfg file of the server SET _alarmname=raid IF "!_hostname!"=="" SET _hostname=%hostname% SET _bblogfile="!_bblogdir!-!_alarmname!" IF "!_BBWin!"=="1" SET _bblogfile="!_bblogdir!!_alarmname!" SET _bblogtemp=%TEMP%\temp.temp SET _host_separator= IF NOT "!_hostname!"=="" SET _host_separator=: REM Extracting date and time information for /f "tokens=1,2*" %%i, in ('DATE /T') do SET _date=%%j IF "!_date!"=="" for /f "tokens=1*" %%i, in ('DATE /T') do SET _date=%%i for /f "tokens=1*" %%i, in ('TIME /T') do SET _time=%%i SET _hpacucli="C:\Program Files\Compaq\Hpacucli\Bin\hpacucli.exe" SET _status=green SET _message=Everything is working fine SET _name=No controller found SET _channel= SET _serial= REM Check if HPACUCLI executable exists REM ----------------------------------- IF EXIST !_hpacucli! GOTO checkctrl SET _status=red SET _message=HPACUCLI was not found on this machine. GOTO End :checkctrl TYPE NUL > "!_bblogtemp!" REM Detect the controllers and extract the serial numbers REM ----------------------------------------------------- SET _arg=ctrl all show FOR /f "tokens=1,2* delims=(" %%a, in ('!_hpacucli! !_arg!') DO ( SET _temp=%%b SET _temp=!_temp:sn: =! SET _temp=!_temp:^)=! SET _serial=!_temp! REM Extract the name and the channel of each controller REM --------------------------------------------------- FOR /f "tokens=1,2,3,4,5,6,7,8,9 delims= " %%d, in ("%%a") DO ( IF /I "%%f"=="Slot" SET _name=%%d IF /I "%%f"=="Slot" SET _channel=%%g IF /I "%%g"=="Slot" SET _name=%%d %%e IF /I "%%g"=="Slot" SET _channel=%%h IF /I "%%h"=="Slot" SET _name=%%d %%e %%f IF /I "%%h"=="Slot" SET _channel=%%i IF /I "%%i"=="Slot" SET _name=%%d %%e %%f %%g IF /I "%%i"=="Slot" SET _channel=%%j IF /I "%%j"=="Slot" SET _name=%%d %%e %%f %%g %%h IF /I "%%j"=="Slot" SET _channel=%%k IF /I "%%k"=="Slot" SET _name=%%d %%e %%f %%g %%h %%i IF /I "%%k"=="Slot" SET _channel=%%l ECHO Controller: !_name! >> "!_bblogtemp!" ECHO Channel: !_channel! >> "!_bblogtemp!" ECHO Serial number: !_serial! >> "!_bblogtemp!" ECHO. >> "!_bblogtemp!" REM Extract the status of each logical volume REM ----------------------------------------- SET _arg=controller slot=!_channel! logicaldrive all show status FOR /f "tokens=1,2* delims=)" %%a, in ('!_hpacucli! !_arg!') DO ( SET _log_disk=%%a^) SET _temp=%%b SET _temp=!_temp: =! SET _log_result=!_temp::=! REM FOR /f "tokens=1,2,3,4,5,6,7,8,9 delims= " %%d, in ("%%a") DO ( IF NOT "!_log_result!"=="OK" SET _status=red IF NOT "!_log_result!"=="OK" SET _message="At least one logical volume is in a failure state." SET _ministatus=green IF NOT "!_log_result!"=="OK" SET _ministatus=red ECHO ^&!_ministatus! !_log_disk!: !_log_result! >> "!_bblogtemp!" ) ECHO. >> "!_bblogtemp!" REM Extract the status of each physical drive REM ----------------------------------------- SET _drives_status=green SET _arg=controller slot=!_channel! physicaldrive all show status FOR /f "tokens=1,2* delims=)" %%a, in ('!_hpacucli! !_arg!') DO ( SET _phy_disk=%%a^) SET _temp=%%b SET _temp=!_temp: =! SET _phy_result=!_temp::=! REM FOR /f "tokens=1,2,3,4,5,6,7,8,9 delims= " %%d, in ("%%a") DO ( IF NOT "!_phy_result!"=="OK" SET _status=red IF NOT "!_phy_result!"=="OK" SET _message="At least one drive is in a failure state." SET _ministatus=green IF NOT "!_phy_result!"=="OK" SET _ministatus=red IF NOT "!_phy_result!"=="OK" SET _drives_status=red ECHO ^&!_ministatus! !_phy_disk!: !_phy_result! >> "!_bblogtemp!" ) ECHO. >> "!_bblogtemp!" ECHO. >> "!_bblogtemp!" REM Details if at least one disk fail SET _arg=controller slot=!_channel! physicaldrive all show detail IF NOT "!_drives_status!"=="green" !_hpacucli! !_arg! >> "!_bblogtemp!" IF NOT "!_drives_status!"=="green" ECHO. >> "!_bblogtemp!" IF NOT "!_drives_status!"=="green" ECHO. >> "!_bblogtemp!" ) ) :End IF NOT "!_BBWin!"=="1" ECHO !_hostname!!_host_separator!!_status!!_time_validity! !_date! !_time! [!_hostname!] > !_bblogfile! IF "!_BBWin!"=="1" ECHO !_status!!_time_validity! !_date! !_time! [!_hostname!] > !_bblogfile! ECHO !_message! >> !_bblogfile! ECHO. >> "!_bblogfile!" ECHO. >> "!_bblogfile!" TYPE "!_bblogtemp!" >> !_bblogfile! TYPE "!_bblogtemp!" DEL !_bblogtemp! ENDLOCAL