Po$H Pete | Those who can… $cript
16Jan/113

Powershell and CA Unicenter Alert Forwarding

A while ago I was asked to come up with a way to push alerts into a CA Unicenter rig. I set to reading the documentation, but unfortunately, it's all geared up for someone to write the connector in Java or C++, which is no use when I wanted to write mine in powershell!

After a bit more digging through the documentation, I came across an executable which would take an XML input for the alert to test with, but again this ran a compiled Java script, grrrrr! Time to break out Wireshark to start some packet tracing.

Wireshark unveiled that the Java app was sending a SOAP envelope with the relevant data to the Axis2 GenericConnectorService on the Unicentre rig. I then transposed this SOAP format into some Powershell and Bob's your uncle, here are the functions I came up with:

Function Add-CAUnicenterEvent($ServerAddress,$ClassName,$DeviceID,$Severity,$SiloAlarmID,$SituationMessage,$EventDetail)
{
 
	$ThePath = $ServerAddress
	$TheData = "<?xml version=""1.0"" encoding=""utf-8""?>"
	$TheData += "<soapenv:Envelope xmlns:soapenv=""http://www.w3.org/2003/05/soap-envelope"">"
	$TheData += "<soapenv:Body>"
	$TheData += "<ns2:addEvents xmlns:ns2=""http://webservice.generic.connector.ifw.sam.ca.com"">"
	$TheData += "<ns2:statusEvents>"
	$TheData += "<ns1:className xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$ClassName</ns1:className>"
	$TheData += "<ns1:deviceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$DeviceID</ns1:deviceID>"
	$TheData += "<ns1:instanceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">" + $ClassName + ":" + $DeviceID.ToString().Trim() + "</ns1:instanceID>"
	$TheData += "<ns1:severity xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$Severity</ns1:severity>"
	$TheData += "<ns1:siloAlarmID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$SiloAlarmID</ns1:siloAlarmID>"
	$TheData += "<ns1:situationMessage xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$SituationMessage</ns1:situationMessage>"
	$TheData += "<ns1:situationType xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">Risk</ns1:situationType>"
	$TheData += "<ns1:EventDetail xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$EventDetail</ns1:EventDetail>"
	$TheData += "</ns2:statusEvents>"
	$TheData += "</ns2:addEvents>"
	$TheData += "</soapenv:Body>"
	$TheData += "</soapenv:Envelope>"
	$ObjXML = New-Object -ComObject Microsoft.XMLHTTP
	$ObjXML.open("POST",$ThePath,$false)
	$ObjXML.SetRequestHeader("Content-Type","application/soap+xml; charset=utf-8; action=""urn:addEvents""")
	$ObjXML.SetRequestHeader("Content-Length",$TheData.Length.ToString())
	$ObjXML.Send($TheData)
	$Response = [xml]$ObjXML.ResponseText
	$ObjXML = $Null
	Return $Response.Envelope.body.addeventsresponse.return
}
 
 
Function Add-CAUnicenterCI($ServerAddress,$ClassName,$DeviceID)
{
	$ThePath = $ServerAddress
	$TheData = "<?xml version=""1.0"" encoding=""utf-8""?>"
	$TheData += "<soapenv:Envelope xmlns:soapenv=""http://www.w3.org/2003/05/soap-envelope"">"
	$TheData += "<soapenv:Body>"
	$TheData += "<ns2:addCIs xmlns:ns2=""http://webservice.generic.connector.ifw.sam.ca.com"">"
	$TheData += "<ns2:ciAdds>"
	$TheData += "<ns1:className xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$ClassName</ns1:className>"
	$TheData += "<ns1:deviceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$DeviceID</ns1:deviceID>"
	$TheData += "<ns1:instanceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">" + $ClassName + ":" + $DeviceID.ToString().Trim() + "</ns1:instanceID>"
	$TheData += "<ns1:situationMessage xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">Adding a new CI</ns1:situationMessage>"
	$TheData += "</ns2:ciAdds>"
	$TheData += "</ns2:addCIs>"
	$TheData += "</soapenv:Body>"
	$TheData += "</soapenv:Envelope>"
	$ObjXML = New-Object -ComObject Microsoft.XMLHTTP
	$ObjXML.open("POST",$ThePath,$false)
	$ObjXML.SetRequestHeader("Content-Type","application/soap+xml; charset=utf-8; action=""urn:addCIs""")
	$ObjXML.SetRequestHeader("Content-Length",$TheData.Length.ToString())
	$ObjXML.Send($TheData)
	$Response = [xml]$ObjXML.ResponseText
	$ObjXML = $Null
	Return $Response.Envelope.body.addeventsresponse.return
 
}
 
 
 
Function Delete-CAUnicenterCI($ServerAddress,$ClassName,$DeviceID)
{
	$ThePath = $ServerAddress
	$TheData = "<?xml version=""1.0"" encoding=""utf-8""?>"
	$TheData += "<soapenv:Envelope xmlns:soapenv=""http://www.w3.org/2003/05/soap-envelope"">"
	$TheData += "<soapenv:Body>"
	$TheData += "<ns2:deleteCIs xmlns:ns2=""http://webservice.generic.connector.ifw.sam.ca.com"">"
	$TheData += "<ns2:ciDeletes>"
	$TheData += "<ns1:className xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$ClassName</ns1:className>"
	$TheData += "<ns1:deviceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">$DeviceID</ns1:deviceID>"
	$TheData += "<ns1:instanceID xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">" + $ClassName + ":" + $DeviceID.ToString().Trim() + "</ns1:instanceID>"
	$TheData += "<ns1:situationMessage xmlns:ns1=""http://webservice.generic.connector.ifw.sam.ca.com/xsd"">Deleting CI</ns1:situationMessage>"
	$TheData += "</ns2:ciDeletes>"
	$TheData += "</ns2:deleteCIs>"
	$TheData += "</soapenv:Body>"
	$TheData += "</soapenv:Envelope>"
	$ObjXML = New-Object -ComObject Microsoft.XMLHTTP
	$ObjXML.open("POST",$ThePath,$false)
	$ObjXML.SetRequestHeader("Content-Type","application/soap+xml; charset=utf-8; action=""urn:deleteCIs""")
	$ObjXML.SetRequestHeader("Content-Length",$TheData.Length.ToString())
	$ObjXML.Send($TheData)
	$Response = [xml]$ObjXML.ResponseText
	$ObjXML = $Null
	Return $Response.Envelope.body.addeventsresponse.return
}

The $ServerAddress variable is the path to the GenericConnectorService on the Unicenter rig, this normally looks like: "http://myipaddress:7090/axis2/services/GenericConnectorService" I hope this helps someone as having to go as far as a packet trace was a right pain!