Appendix D - The Universal Connector

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1

Examples for Alert Message Integration Logic

As noted in the Using the Universal Connector section, integration logic must be developed to translate and transfer the alert message content, as saved by the Interop Provider, to the remote system that the Universal Connector is serving. The following are examples of Windows PowerShell script that can serve as a starting point in this task. In these samples the remote system is designated as the EMS Emulator.

Script for processing a new alert

#  Copyright (c) Microsoft Corporation.  All rights reserved.
# Sample script to process incoming alerts from Operations Manager 2007 R2
# forwarded via the Universal Connector.

## Path to alert XML files forwarded from Operations Manager.
$FromOMPath="C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\FromOpsMgr"

## Path to EMS Emulator.
$EMSPath="C:\Program Files\EMSEmulator"

## Path to the XML files to be sent to Operations Manager.
$ToOMPath = "C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\"

## Next ticket number from EMS Emulator Config.
$EMSConfigFile=$EMSPath + "\config\EMSEmulatorConfig.xml"
$EMSConfigxml = [xml] (get-content $EMSConfigFile) 
$NextTicket = [int] $EMSConfigxml.EMSConfig.NextTicket

## Read alert XML files from Operations Manager.
$alertfiles = (get-childitem -path $FromOMPath -include *.xml -recurse) 

foreach($alertfile in $alertfiles) {
$xml= [xml](get-content $alertfile)

# New Alert Processing - EventType = 0
if ($xml.UNVEvent.EventType = "0") {

# Add logic to insert alert into customer application.
# Simulation follows.
$newelem = $xml.CreateElement("TicketNumber")
$newelem.set_InnerText($NextTicket)
$xml.UNVEvent.AppendChild($newelem)
$newFile=$EMSPath + "\" + $NextTicket + ".xml"
$xml.save($newFile)

# Create the acknowledgement for the new alert, return TicketNumber.
$ackxml = new-object System.Xml.XmlDocument

# Create root node.
$ackroot = $ackxml.CreateElement("UNVEvent")
$ackxml.appendchild($ackroot)

# Add EventType to ackxml.
$ackelem = $ackxml.CreateElement("EventType")
$ackelem.set_InnerText("2")
$ackroot.AppendChild($ackelem)

# Add AlertId to ackxml.
$ackelem = $ackxml.CreateElement("AlertId")
$ackelem.set_InnerText($xml.UNVEvent.AlertId)
$ackroot.AppendChild($ackelem)

# Add EventID to ackxml.
$ackelem = $ackxml.CreateElement("EventId")
$ackelem.set_InnerText($NextTicket)
$ackroot.AppendChild($ackelem)

# Add ManagementGroup to ackxml.
$ackelem = $ackxml.CreateElement("ManagementGroupName")
$ackelem.set_InnerText($xml.UNVEvent.ManagementGroupName)
$ackroot.AppendChild($ackelem)

# Add XML introduction.
$xmlintro = $ackxml.CreateProcessingInstruction("xml", "version='1.0'")
$ackxml.InsertBefore($xmlintro, $ackroot)

# Check for MgmtGroup directory, create if it does not exist.
$MGdir = $ToOMPath + $xml.UNVEvent.ManagementGroupName
$ackFile = $MGdir + "\" + $NextTicket + ".xml"

if (!(Test-Path $MGdir)) { mkdir $MGdir }

$ackxml.save($ackFile)

remove-item $alertfile

$NextTicket++
}

}

# Update EMS Config File with new NextTicket value.
$EMSConfigxml.EMSConfig.NextTicket = [string] $NextTicket
$EMSConfigxml.save($EMSConfigFile)

Script for processing an Operations Manager alert update

#  Copyright (c) Microsoft Corporation.  All rights reserved.
# Sample script to process incoming alert updates from Operations Manager 2007 R2 
# forwarded via the Universal Connector.  

## Path to alert XML files forwarded from Operations Manager.
$FromOMPath="C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\FromOpsMgr"

## Path to EMS Emulator.
$EMSPath="C:\Program Files\EMSEmulator"

## Path to XML files to be sent to Operations Manager.
$ToOMPath = "C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\"

## Read alert XML files from Operations Manager.
$alertfiles = (get-childitem -path $FromOMPath -include *.xml -recurse)

foreach($alertfile in $alertfiles) {
$xml= [xml](get-content $alertfile)

# Alert Update Processing - EventType = 1
if ($xml.UNVEvent.EventType = "1") {

# Add logic to update the customer application with data from Operations Manager.
# Simulation follows.
# Find ticket that matches the one from the update.
$EMSfilename = $EMSPath + "\" + $xml.UNVEvent.EventId + ".xml"
if ((Test-Path $EMSfilename)) { 
# Get matched ticket.
$existingTicket = [xml] (Get-Content $EMSfilename)

# Update resolution state.
 $existingTicket.UNVEvent.ResolutionState = $xml.UNVEvent.ResolutionState
$existingTicket.save($EMSfilename)

}

# Create the acknowledgement for the new alert, return TicketNumber.
$ackxml = new-object System.Xml.XmlDocument

# Create root node.
$ackroot = $ackxml.CreateElement("UNVEvent")
$ackxml.appendchild($ackroot)

# Add EventType to ackxml.
$ackelem = $ackxml.CreateElement("EventType")
$ackelem.set_InnerText("3")
$ackroot.AppendChild($ackelem)

# Add AlertId to ackxml.
$ackelem = $ackxml.CreateElement("AlertId")
$ackelem.set_InnerText($xml.UNVEvent.AlertId)
$ackroot.AppendChild($ackelem)

# Add EventID to ackxml.
$ackelem = $ackxml.CreateElement("EventId")
$ackelem.set_InnerText($xml.UNVEvent.EventId)
$ackroot.AppendChild($ackelem)

# Add ManagementGroup to ackxml.
$ackelem = $ackxml.CreateElement("ManagementGroupName")
$ackelem.set_InnerText($xml.UNVEvent.ManagementGroupName)
$ackroot.AppendChild($ackelem)

# Add XML introduction.
$xmlintro = $ackxml.CreateProcessingInstruction("xml", "version='1.0'")
$ackxml.InsertBefore($xmlintro, $ackroot)

# Check for MgmtGroup directory, create if it does not exist.
$MGdir = $ToOMPath + $xml.UNVEvent.ManagementGroupName
$ackFile = $MGdir + "\" + $xml.UNVEvent.EventId + ".xml"

if (!(Test-Path $MGdir)) { mkdir $MGdir }

$ackxml.save($ackFile)

remove-item $alertfile

}

}

Script for processing a remote system update to Operations Manager

# Copyright (c) Microsoft Corporation.  All rights reserved.
# Sample script to simulate the closing of a ticket in the EMS Emulator and 
# to create the necessary file to close the corresponding alert in Operations Manager.
param($CloseTicket)

## Path to the alert XML files forwarded from Operations Manager.
$FromOMPath="C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\FromOpsMgr"

## Path to EMS Emulator.
$EMSPath="C:\Program Files\EMSEmulator"

## Path to XML files to be sent to Operations Manager.
$ToOMPath = "C:\Program Files\System Center Operations Manager 2007 Providers\Operations Manager 2007 Connector to Microsoft Universal Provider\UnvEvents\"

## Ticket number to close.
#$CloseTicket=$arg[0]

# Simulate the closing of a ticket in the EMS. 

# Add logic to update the customer application with data from Operations Manager.
# Simulation follows.
# Find ticket that matches the one from the update.
$EMSfilename = $EMSPath + "\" + $CloseTicket + ".xml"
if ((Test-Path $EMSfilename)) { 
# Get matched ticket.
$existingTicket = [xml] (Get-Content $EMSfilename)

# Update resolution state.
$existingTicket.UNVEvent.ResolutionState = "Closed"
$existingTicket.save($EMSfilename)

# Need to create the file to be picked up by Connector, and close the Operations Manager alert.
$closexml = new-object System.Xml.XmlDocument

# Create root node.
$closeroot = $closexml.CreateElement("UNVEvent")
$closexml.appendchild($closeroot)

# Add EventType to closexml.
$closeelem = $closexml.CreateElement("EventType")
$closeelem.set_InnerText("1")
$closeroot.AppendChild($closeelem)

# Add AlertId to closexml.
$closeelem = $closexml.CreateElement("AlertId")
$closeelem.set_InnerText($existingTicket.UNVEvent.AlertId)
$closeroot.AppendChild($closeelem)

# Add ManagementGroup to closexml.
$closeelem = $closexml.CreateElement("ManagementGroupName")
$closeelem.set_InnerText($existingTicket.UNVEvent.ManagementGroupName)
$closeroot.AppendChild($closeelem)

# Add ResolutionStateto closexml.
$closeelem = $closexml.CreateElement("ResolutionState")
$closeelem.set_InnerText($existingTicket.UNVEvent.ResolutionState)
$closeroot.AppendChild($closeelem)

# Add XML introduction.
$closeintro = $closexml.CreateProcessingInstruction("xml", "version='1.0'")
$closexml.InsertBefore($closeintro, $closeroot)

# Check for MgmtGroup directory, create if it does not exist.
$MGdir = $ToOMPath + $existingTicket.UNVEvent.ManagementGroupName
$closeFile = $MGdir + "\" + $existingTicket.UNVEvent.TicketNumber + ".xml"

if (!(Test-Path $MGdir)) { mkdir $MGdir }

$closexml.save($closeFile)

}  

Disclaimer

The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.