Monday, September 8, 2014

PatrolCli - Part 3: Run PatrolCli commands from an OS script

In order to execute PatrolCli commands automatically on a schedule, you will need to put them in an OS script - e.g., shell script on UNIX or batch script on Windows.  Once PatrolCli commands are in an OS script, you can schedule to run the script periodically by using any vendor's scheduling utility or native OS scheduling utility (such as cron on UNIX or admin tool on Windows).

PatrolCli has a '-f' option to execute commands in batch mode.  You can use the following format to supply all PatrolCli commands in an input text file instead of typing them interactively at 'PCli%' prompt:

PatrolCli -f input.txt

Often we want to capture the output of the above command and send it out as an email.  Or you can use it as the input to call 'msend' API and generate an event in BPPM cell.  In the following example running on Windows, we want to detect if VSM_VC KM has stopped collecting data for at least 15 minutes on host 'server1'.  If so, an email will be sent from PatrolCli@yourcompany.com to bppm_admin@yourcompany.com.

Step 1: Create a text file called input.txt as follows:

user patrol password
connect server1 3181
execpsl int(time()-get("/VSM_VC/crpvms1vcenter2.yourcompnay.com/Comm_Status/time"));
exit

Step 2: Create a batch script called VSM_VC_Check.cmd as follows:

@ECHO OFF
PatrolCli -f input.txt > output.txt
set /p result= <output.txt
del output.txt

if %result% GEQ 900 (
echo No VSM_VC data collected for %result% seconds > tmp.txt
smail.exe tmp.txt -t bppm_admin@yourcompany.com -s "VSM_VC data collection stopped" -server <SMTP_Server> -f PatrolCli@yourcompany.com
del tmp.txt
)

Step 3: Schedule script VSM_VC_Check.cmd with Windows admin tool to run it periodically (e.g. every 15 minutes).

No comments:

Post a Comment