IPSentry Version 4

Home |   help index | Screen Shot

Related Topics Screen Shots Email to support@ipsentry.com Go to ipsentry.com

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.

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 success).  

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 UP or DOWN
::eg: routelog x.x.x.x UP
::--------------------------------------------------------

E:
CD\IPSentry\Etc

Set CurIP=%1
Set CurState=%2

If %CurState%!==UP! 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 DOWN.

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 DOWN

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 DOWN"

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. From the Edit menu, select Options.
     

  2. Select the Server/Machine Monitoring tab.
     

  3. Highlight a device and click on the Properties button.
     

  4. Select the Launch App tab.
     

  5. Select Yes in the Enabled status box.
     

  6. Select the Alert Success option so that it is checked.
     

  7. In the Command Line field, enter the following:
    "C:\Winnt\System32\cmd.exe" /C"E:\IPSentry\etc\routelog.bat %IPS_ADDRESS% %IPS_M_STAT%"
     

  8. Set the Alert Schedule as required.

Notice the use of %IPS_ADDRESS% and %IPS_M_STAT% ?  These are IPSentry keywords 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 %IPS_ADDRESS% with the IP Address of the current machine and replacing %IPS_M_STAT% with down.  If alert success is checked, this will again be executed when the problem has been corrected with %IPS_M_STAT% replaced with "UP".

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 MYPROGDOWN.EXE when the alert is triggered due to failure, the command line could be simply MYPROG%IPS_M_STAT%.EXE - And when the same alert was triggered due to the alert success feature, it would be converted to MYPROGUP.EXE. 


Related Topics Related Topics

Home  |  Product Info  |  Download  |  Pricing  |  Order Now   |  Support  |  Contact Us

Contact: support@ipsentry.com  https://ipsentry.com © 2006 by RGE, Inc. - All Rights Reserved