The Alert Service supports a method for running an external program to facilitate custom processing of alerts. An external program can be called on each occurrence of an alert or warning, with the same data fields that are supplied to the other forms of messaging, such as email and Event Log.
Note: The program to be started must be an executable file.
Selection of data and formatting of the command line are defined through AlertShellCmd.xsl.
When an alert occurs and the Shell Command check box for that alert was selected, Alert Service runs a CreateProcess()
statement that causes execution of the custom program with command-line arguments obtained from AlertShellCmd.xsl
and with Creation Flags consisting of the following:
CREATE_NO_WINDOW CREATE_NEW_CONSOLE NORMAL_PRIORITY_CLASS
Typically, a custom program processes the command line and then exits.
The Alert Service can also run Windows™ command-line .bat
files. When the batch file runs, the active directory is the same one that contains the TLAlertSrv.exe that is typically <install_directory>\Portal.
Note: Each exit point of a batch file must include an exit
command. Otherwise, multiple instances of cmd.exe
may persist.
When inserted into AlertShellCmd.xsl
, the following configuration starts a batch file called test.bat
. Parameters in the form of name=value
must be written as "name=value"
.
<xsl:template name="CommandString">
cmd /c test.bat "AlertLevel=<xsl:value-of select="ThresholdCategory"/>"
"LogVersion=1" "Description=<xsl:value-of select="EventTitle"/>"
</xsl:template>
If the test.bat
file is the following example, it appends the three names value parameters to the file test.txt
before running the LogShell program.
echo %1 %2 %3 >> test.txt
LogShell %1 %2 %3
exit
Example XSL
The following example file was created by running the Alert Service program, TLAlertSrv.exe
. It lists all the available data fields and implements an example passing two arguments to a program that might echo the command line to a log file.
The generated AlertShellCmd.xsl
should be replaced with the customer's own file that controls execution of the customer application.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="no" omit-xml-declaration="yes"
encoding="iso-8859-1"/>
<!-- XML format for Alert Messaging -->
<!-- <AlertServiceAlertMessage MessageType="Default"> -->
<!-- <AlertServiceAlertMessage MessageType="TopMovers"> -->
<!-- <AlertServiceAlertMessage MessageType="SubjectDefault"> -->
<!-- <AlertID>1</AlertID> -->
<!-- <EventID>1</EventID> -->
<!-- <AlertTime>0</AlertTime> -->
<!-- <Title>*** TEALEAF ALERT ***</Title> -->
<!-- <SubTitle>WARNING DETAILS</SubTitle> -->
<!-- <AlertTitle>Alert Name</AlertTitle> -->
<!-- <EventTitle>Event Name</EventTitle> -->
<!-- <AlertGroup>Alert Group</AlertGroup> -->
<!-- <ThresholdValue>1.0</ThresholdValue> -->
<!-- <LastValue>2.0</LastValue> -->
<!-- <ThresholdType>Positive or Negative</ThresholdType> -->
<!-- <ThresholdCategory>Alert or Warning</ThresholdCategory> -->
<!-- <AlertTimeStamp>Monday, July 02, 2007 08:00</AlertTimeStamp> -->
<!-- <AlertTimeStampShort>07/02/07 08:00:00</AlertTimeStampShort> -->
<!-- <ReportPeriod>Monday, July 02, 2007 08:00</ReportPeriod> -->
<!-- <PortalURL>http://localhost/portal</PortalURL> -->
<!-- <AlertEngineVersion>4.0.0.4500</AlertEngineVersion> -->
<!-- <AlertEngineTimeStamp>Monday, July 02, 2007 08:00:00
</AlertEngineTimeStamp> -->
<!-- <CanistersLagging>george, sam, bobo</CanistersLagging> -->
<!-- <LaggingCount>3</LaggingCount> -->
<!-- <CanistersStopped>fox, hound</CanistersStopped> -->
<!-- <StoppedCount>2</StoppedCount> -->
<!-- The below are only populated for MessageType="TopMovers" -->
<!-- <Frequency>Hourly or Daily</Frequency> -->
<!-- <ReportID>1</ReportID> -->
<!-- <DimensionID>1</DimensionID> -->
<!-- <DimValueID>1</DimValueID> -->
<!-- <ReportTitle>Report Name</ReportTitle> -->
<!-- <FullName>NAMESPACE.INTERNALNAME</FullName> -->
<!-- <DimensionTitle>Dimension Name</DimensionTitle> -->
<!-- <DimValueTitle>Value Name </DimValueTitle> -->
<!-- </AlertServiceAlertMessage> -->
<!-- Note: only the Default selection is currently effective, Test is
never invoked-->
<xsl:template match="AlertServiceAlertMessage">
<xsl:choose>
<xsl:when test="@MessageType[.='Default']">
<xsl:call-template name="CommandString"/>
</xsl:when>
<xsl:when test="@MessageType[.='TopMovers']">
<xsl:call-template name="CommandString"/>
</xsl:when>
<xsl:when test="@MessageType[.='Test']">
<xsl:call-template name="CommandString"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--Main Text body. Remember, the space and new lines are taken literally!
-->
<xsl:template name="CommandString">
LogShell AlertLevel=<xsl:value-of select="ThresholdCategory"/> LogVersion=1
"Description=<xsl:value-of select="EventTitle"/>"
</xsl:template>
<!-- The following is a method to invoke a batch file rather than an
application. -->
<!-- Note that parameters of the form name=value must be written as"name=value".
-->
<!-- -->
<!-- <xsl:template name="CommandString"> -->
<!--cmd /c test.bat "AlertLevel=<xsl:value-of select="ThresholdCategory"/>
""LogVersion=1" "Description=<xsl:value-of select="EventTitle"/>" -->
<!-- </xsl:template> -->
<!-- -->
<!-- The test.bat file below will append the three name=value params to the
file -->
<!-- test.txt and then execute the LogShell program as does the non-batch
example. -->
<!-- -->
<!-- !!!The exit command is important. Without it, multiple cmd.exe's
will persist!!! -->
<!-- -->
<!-- echo %1 %2 %3 >> test.txt -->
<!-- LogShell %1 %2 %3 -->
<!-- exit -->
<!-- -->
</xsl:stylesheet>
Note: If multiple alerts are configured for external command shell invocation, then AlertShellCmd.xsl
will be used for all the alerts. Specific alert handling should happen in the batch script configured in AlertShellCmd.xsl
.