LockedHow To - Launch a batch (.BAT or .CMD) file as an alert

Author
IPSentrySupport
Support Guy
  • Total Posts : 2072
  • Scores: 0
  • Reward points: 0
  • Joined: 2006/05/16 21:55:52
  • Status: offline
2007/08/20 21:23:01 (permalink)
0

How To - Launch a batch (.BAT or .CMD) file as an alert

The Launch App functionality in IPSentry is quite simple in most cases.  Problems do arise however, when you are attempting to launch batch or command files (.BAT or .CMD) to perform various tasks for the alert sequence rather than just an executable.
 
Depending on your system environment configuration and security issues, you may be able to specify the batch file directly.  In other instances, you will need to specify the command interpreter as the application and the batch file as part of the command line.
We will also cover command line parameters in our example to familiarize you with the IPSentry Keyword functionality as it relates to this alert option.
 
In our example, we have a batch file  that performs a trace-route to the host and then performs some external logging function (not sure exactly what it does, but it needs to be executed) and then exits.  To accomplish the trace-route, we will need the IP Address of the server we are monitoring to be passed to the batch file.  We also need to know if the batch is being executed because of a failure or because the problem was corrected (alert recovery).  

Note: This example assumes we are running Windows NT.

The batch file we will execute is called ROUTELOG.BAT looks like this:
::--------------------------------------------------------
::routelog.bat
::
::Logs traceroute results to our temporary log file
::and then executes ptlog.exe.
::
::ptlog.exe is an in-house utility that parses the
::log file and stores important routing information
::in our proprietary database.
::
::The command line should contain the IP Address of
::the machine, and the state of the machine as OK or CRITICAL
::eg: routelog x.x.x.x OK
::--------------------------------------------------------

E:
CD\IPSentry\Etc

Set CurIP=%1
Set CurState=%2

If %CurState%!==OK! Goto SkipTrace

Tracert -d %CurIP%>PTLOG.DAT

::--------------------------------------------------------
:: ptlog takes the IP and State as parameters.
::--------------------------------------------------------
:SkipTrace
ptlog %CurIP% %CurState%


:SkipTrace
Exit

::--------------------------------------------------------

The only functionality of the above batch file that concerns us in this example is the fact that we need to pass the IP Address and the machine state on the command line.  The rest is merely batch processing and beyond the scope of this document.
 
If we are at a command prompt and wanted to start this process for a failed machine at IP 10.1.1.1, we would enter the command routelog.bat 10.1.1.1 CRITICAL.
 
In order to accomplish this from IPSentry, we will need to execute the command interpreter (CMD.EXE) with a command line to start this batch process.  This would look something like this:

C:\WinNT\System32\CMD.EXE /CE:\IPSentry\Etc\RouteLog.BAT 10.1.1.1 CRITICAL
Note:  If the path or file name contains spaces, you will need to enclose the command in quotes.
e.g. "C:\Winnt\System32\cmd.exe" /C"E:\IPSentry\etc\routelog.bat 10.1.1.1 CRITICAL"

So, how do we get this into IPSentry so that the IP Address and state of the machine are sent on this command line?

  1. Starting in the Launch Application tab of the Alerts tab of the Entry Editor.
     

  2. Select Enabled in the Alert Status box.
     

  3. Select the Trigger on Recovery option so that it is checked.
     

  4. In the Command Line field, enter the following:
    "C:\Winnt\System32\cmd.exe" /C"E:\IPSentry\etc\routelog.bat %%mach.net.address%% %%mach.state%%"
     


  5. Set the Alert Schedule as required.

Notice the use of %%mach.net.address%% and %%mach.state%% ?  These are IPSentry Keyword that will be converted to the IP Address and Machine State of the current device whenever this alert is triggered.  Use of these keys will depend on the type of system being monitored such that NT Service monitoring does not make use of the IP Address definition.

When IPSentry detects a failure, it will launch the above command while replacing %%mach.net.address%% with the IP Address of the current machine and replacing %%mach.state%% with CRITICAL.  If alert success is checked, this will again be executed when the problem has been corrected with %%mach.state%% replaced with "OK".
 
Within the command line, IPSentry keywords are replaced before any processing of the command is performed.  You can use keywords as part of file names thus causing IPSentry to launch differently named processes based on machine state.
 
For example, if you want to launch MYPROGCRITICAL.EXE when the alert is triggered due to failure, the command line could be simply MYPROG%%mach.state%%.EXE - And when the same alert was triggered due to the alert success feature, it would be converted to MYPROGOK.EXE. 

---
IPSentry Support
RGE, Inc.
http://www.ipsentry.com
http://forum.ipsentry.com

IPSentry® is a Registered Trademark of RGE, Inc.
#1

0 Replies Related Threads

    Jump to:
    © 2020 APG vNext Commercial Version 5.5