Enterprise Alert bietet “codeless” Integration mit einer ganzen Reihe von Standard-Tools, zum Beispiel Microsoft System Center, HP Operations Manager, HP Service Manager, usw. Darüber hinaus gibt es offene Schnittstellen / API s, wie, Kommandozeile, Web Service, SMTP und mehr. Diese ermöglichen eine einfache Integration mit fast jedem Backend-System.
Es gibt jedoch auch einen eleganten Weg zur Integration mittels Enterprise Alert Scripting Host. Das hat folgende Vorteile:
- Scripting ist sehr flexibel und eine enge Integration in viele Backend-Systeme ist einfack möglich (zum Beispiel per Datenbank, Web Service, Dateien, usw.)
- Verwendung dynamischer Event Parametern
- Die Script Integration verhält sich wie das Web Service Interface in Enterprise Alert und es können Alarmierungsrichtlinien zur Auswertung verwendet werden
- Zwei-Wege-Integration ist möglich, inklusive Updates und Reset Event
- Einfach anzupassen, zum Beispiel Hinzufügen von Event Parametern oder Anpassung der Implementierung bei Änderungen im Backend System
Das folgende Script ist ein Beispiel für das Lesen von Event-Daten aus einer Datenbank:
/*
=============================================================================
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();
Zusätzlich zu dem Script ist es noch notwendig einen entsprechenden Event Provider in der Datenbank anzulegen. Das kann mit dem folgenden Beispiel SQL Script geschehen:
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
Datensätze, die aus der Datenbank ausgelesen werden, kommen dann in Enterprise Alert als Events an. Für die Zwei-Implementierung kann der entsprechende Code in den Event Handler aufgenommen werden, zum Beispiel in OnTicketStatus().