Enterprise Alert offers code-less integration with a variety of standard tools, e.g. Microsoft System Center, HP Operations Manager, HP Service Manager, etc. Besides this open API’s like command line, Web service, SMTP and more are available for easy integration almost every backend system.
There is also a neat way for integrating backend systems using the Enterprise Alert Scripting Host. This has the following advantages:
- Scripting is flexible and in-depth integration with a lot of backend systems is possible (e.g. access a database, Web services, files, etc.)
- You can define the event parameters as you need them
- The script integration behaves like Web service integration in Enterprise Alert and you can easily process them using policies
- Two-way integration is possible including updates and reset event
- Easy to adapt, e.g. for adding event parameters or changing the implementation to cope with changes in the backend system
The following script is a basic example for reading event data from a backend database:
/*
=============================================================================
CONFIGURATION
=============================================================================
*/
// The interval in milliseconds when the messages get read from the MMSEND database table
var APPCONFIG_CHECK_MESSAGES_INTERVAL = 10000;
// The script ID used for marking the field “EA_Status”. This is unique for each script running in a high-availability environment, e.g. 1001, 1002.
// Must be greater than 1000
var APPCONFIG_SCRIPT_ID = 1002;
// Enterprise Alert database connection string
var APPCONFIG_DBCONNECTIONSTRING = “Driver=SQL Server Native Client 11.0;Server=sqlserver;Trusted_Connection=Yes;Database=EnterpriseAlert2016;Connect Timeout=120;General Timeout=120”;
/*
=============================================================================
Main functions
=============================================================================
*/
EAScriptHost.LogInfo(“Script Interface process started”);
function CheckEvents()
{
while (true)
{
var oConn = null;
var oRs = null;
var bInTrans = false;
try
{
//Open the db connection
//
oConn = new ActiveXObject(“ADODB.Connection”);
oConn.IsolationLevel = 1048576; // Set the isolation level to Serializable
oConn.Open(APPCONFIG_DBCONNECTIONSTRING);
EAScriptHost.LogDebug(“Db Connection Opened”);
oConn.BeginTrans();
bInTrans = true;
oConn.Execute(“UPDATE EnterpriseAlert_Central_EventSync SET EA_Status = ” + APPCONFIG_SCRIPT_ID + “WHERE EA_Status = 0”);
// Get the details of the message
//
var iNumMessages = 0;
oRs = DbGetRS(oConn, “SELECT * FROM EnterpriseAlert_Central_EventSync WHERE EA_Status = ” + APPCONFIG_SCRIPT_ID + ” ORDER BY intID ASC”);
while (!oRs.EOF)
{
var iRecordId = oRs.Fields.Item(“intID”).Value;
// Create new event
EAScriptHost.LogDebug(“Script Interface: Create new event”);
objevent = EAScriptHost.CreateEvent();
objevent.SetEventType(“ConnectorEvent”);
objevent.SetEventName(“NewAlert”);
objevent.SetProperty(“serviceFrom”, “//q:mmwebservice/EventProviderAPI/Custom Script Interface/EnterpriseAlert_Central_EventSync”);
// Set event parameters and values
// objevent.SetProperty(“externalTicketId”, oRs.Fields.Item(“EventID”).Value == null ? “” : oRs.Fields.Item(“EventID”).Value);
objevent.SetEventParameter(“intID”, oRs.Fields.Item(“intID”).Value == null ? “” : oRs.Fields.Item(“intID”).Value);
objevent.SetEventParameter(“EventID”, oRs.Fields.Item(“EventID”).Value == null ? “” : oRs.Fields.Item(“EventID”).Value);
objevent.SetEventParameter(“Description”, oRs.Fields.Item(“Description”).Value == null ? “” : oRs.Fields.Item(“Description”).Value);
objevent.SetEventParameter(“MachineName”, oRs.Fields.Item(“MachineName”).Value == null ? “” : oRs.Fields.Item(“MachineName”).Value);
objevent.SetEventParameter(“EA_Status”, oRs.Fields.Item(“EA_Status”).Value == null ? “” : oRs.Fields.Item(“EA_Status”).Value);
// Send event
objevent.Send();
iNumMessages++;
oRs.MoveNext();
}
// Update the processed records
oConn.Execute(“UPDATE EnterpriseAlert_Central_EventSync SET EA_Status=1 WHERE EA_Status = ” + APPCONFIG_SCRIPT_ID);
// Delete the processed records
// oConn.Execute(“DELETE EnterpriseAlert_Central_EventSync WHERE EA_Status = ” + APPCONFIG_SCRIPT_ID);
EAScriptHost.LogDebug(“Number of events processed: ” + iNumMessages.toString());
oRs.Close();
oRs = null;
oConn.CommitTrans();
} catch (e) { // catch all thrown errors
try
{
EAScriptHost.LogError(“Error processing event. Error message (Exception): ” + e.message);
if (bInTrans == true && oConn != null)
{
oConn.RollbackTrans();
}
}
catch (e2)
{
EAScriptHost.LogError(“Error processing exception. ” + e2.message);
}
}
finally
{
try
{
// Release all resources at the end of message processing
//
if (oRs != null)
{
oRs.Close();
oRs = null;
}
if (oConn != null)
{
oConn.Close();
oConn = null;
}
EAScriptHost.LogDebug(“Resources released.”);
} catch (e3)
{
EAScriptHost.LogError(“Error releasing resources. ” + e3.message);
}
}
Sleep(APPCONFIG_CHECK_MESSAGES_INTERVAL);
}
}
// Returns an ADODB.Recordset object for the specified query
function DbGetRS(oConn, strSQL)
{
//Set some constants
var adOpenStatic = 3;
var adUseClient = 3;
var adLockBatchOptimistic = 4;
//Declare our variables
var oRS;
// Create the Recordset object
oRS = new ActiveXObject(“ADODB.Recordset”);
// Populate the Recordset object with a SQL query
oRS.Open(strSQL, oConn, adOpenStatic, adLockBatchOptimistic, 0);
// Return the Recordset
return oRS;
}
// Gets a date string for the date object
//
function GetDateString(date)
{
var strDate = date.getFullYear().toString() + “-” + GetDoubleDigit((date.getMonth() + 1).toString()) + “-” + GetDoubleDigit(date.getDate().toString()) + ” ” + GetDoubleDigit(date.getHours().toString()) + “:” + GetDoubleDigit(date.getMinutes().toString()) + “:” + GetDoubleDigit(date.getSeconds().toString());
return strDate;
}
// Gets a double digit for the date
//
function GetDoubleDigit(strText)
{
var strOutput;
if (strText.length == 1)
strOutput = “0” + strText;
else
strOutput = strText;
return strOutput;
}
// Run
CheckEvents();
Additionally to the script you would need to create a respective event provider in the database, e.g. using the following SQL statement:
BEGIN
IF NOT EXISTS (SELECT * FROM [dbo].[EventProviders] WHERE Name = ‘Custom Script Interface’)
BEGIN
INSERT INTO [dbo].[EventProviders] (Name, DisplayName, Description, DateCreated, Type, Options, UserID, ResponseAddress, LicenseName, ClientAddress)
VALUES (‘Custom Script Interface’, ‘Custom Script Interface’, ‘Custom Script Interface’, GETDATE(), 3, 2, 1, ”, null, ‘::1’)
END
BEGIN
DECLARE @ProviderID AS INT
SET @ProviderID = (SELECT ID FROM [dbo].[EventProviders] WHERE Name = ‘Custom NetIQ’)
INSERT INTO [dbo].[EventParameters] (ProviderID, Name, DisplayName, XPath, Description, Options, ForbiddenEvaluations) VALUES (@ProviderID, ‘intID’, ‘intID’, ”, ”, 0, 0)
INSERT INTO [dbo].[EventParameters] (ProviderID, Name, DisplayName, XPath, Description, Options, ForbiddenEvaluations) VALUES (@ProviderID, ‘EventID’, ‘EventID’, ”, ”, 0, 0)
INSERT INTO [dbo].[EventParameters] (ProviderID, Name, DisplayName, XPath, Description, Options, ForbiddenEvaluations) VALUES (@ProviderID, ‘Description’, ‘Description’, ”, ”, 0, 0)
INSERT INTO [dbo].[EventParameters] (ProviderID, Name, DisplayName, XPath, Description, Options, ForbiddenEvaluations) VALUES (@ProviderID, ‘MachineName’, ‘MachineName’, ”, ”, 0, 0)
INSERT INTO [dbo].[EventParameters] (ProviderID, Name, DisplayName, XPath, Description, Options, ForbiddenEvaluations) VALUES (@ProviderID, ‘EA_Status’, ‘EA_Status’, ”, ”, 0, 0)
END
END
Data read from the database will appear as events in Enterprise Alert then. For two-way integration you can implement the respective code in the event handler, e.g. in OnTicketStatus().