Challenged with a MOM 2005 project, I have been trying to figure out how to get VirtualCenter alerts into MOM.
I didn't want to address using forwarded SNMP traps, as not everyone seems to compile the VMware MIBs too well.
VirtualCenter 1.x had the ability to run scripts, but it didn't pass any information. VirtualCenter 2.0.x still runs scripts, but also includes additional information. According to the VirtualCenter help, the following variables can be passed to a script:
{eventDescription} full formatted message for alarm triggering event
{entityName} name of the entity name where the alarm is triggered
{alarmName} name of the alarm that is triggered
{triggeringSummary} summary info of the alarm with triggering values
{declaringSummary} summary info of the alarm declaration
{oldStatus} alarm status before it is triggered
{newStatus} alarm status after it is triggered
{entityObject} inventory object as triggering alarm
Imports System.Diagnostics
Module MakeEventCall
'******************************************************
'* MomApp.exe - 12/12/06
'* Jase McCarty
'* My first VB.NET application for the purpose of
'* sending VMware VirtualCenter alerts to the
'* Application Event Log of a VirtualCenter system
'* that has a Microsoft Operations Manager Agent
'* installed on it.
'*
'* This code may be redistributed, but must have
'* this disclaimer included. Agreement to use
'* this code, absolves me from any liability.
'******************************************************
Sub Main()
'Variables for doing our work
Dim separators As String = "-"
Dim strIncoming As String = Microsoft.VisualBasic.Command()
Dim argCount As Integer
Dim args() As String = strIncoming.Split(separators.ToCharArray)
Dim MessageOutStart As Integer
Dim strMessageOut As String
Dim strFullMessage As String = strIncoming
Dim strApplicationName As String = "VMware VirtualCenter"
Dim objName As String
'Variables for our potential input parameters
Dim eventDescription As String
Dim entityName As String
Dim alarmName As String
Dim triggeringSummary As String
Dim declaringSummary As String
Dim oldStatus As String
Dim newStatus As String
Dim entityObject As String
'Don't do anything, unless we get at least one argument
If UBound(args) > 0 Then
'Blank our Output Message
strMessageOut = ""
'Loop through all our arguments, and process them
'Each argument should read something like this in
'the VirtualCenter Alert settings:
'
'momapp.exe -ed:{eventdescription} -ns:{newstatus} -an:{alarmname}
'
'Where the 2 letter argument prefix matches up with
'the appropriate event item.
For argCount = 0 To UBound(args)
Select Case Left(args(argCount), 2)
Case "ed"
eventDescription = Right(args(argCount), Len(args(argCount)) - 3)
Case "en"
entityName = Right(args(argCount), Len(args(argCount)) - 3)
Case "an"
alarmName = Right(args(argCount), Len(args(argCount)) - 3)
Case "ts"
triggeringSummary = Right(args(argCount), Len(args(argCount)) - 3)
Case "ds"
declaringSummary = Right(args(argCount), Len(args(argCount)) - 3)
Case "os"
oldStatus = Right(args(argCount), Len(args(argCount)) - 3)
Case "ns"
newStatus = Right(args(argCount), Len(args(argCount)) - 3)
Case "eo"
entityObject = Right(args(argCount), Len(args(argCount)) - 3)
End Select
Next
Dim objEventLog As New EventLog
Try
'Register the App as an Event Source
If Not objEventLog.SourceExists(strApplicationName) Then
objEventLog.CreateEventSource(strApplicationName, "Application")
End If
objEventLog.Source = strApplicationName
'This could be modified to include other information from above
strMessageOut = "Alarm: " & alarmName & vbCrLf & _
"Event: " & eventDescription & vbCrLf
'Include the appropriate warning level. If the -ns:{newstatus}
'parameter is omitted, an Informational entry will be written to
'the application log
Select Case Trim(Trim(newStatus))
Case "Green"
objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Information)
Case "Yellow"
objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Warning)
Case "Red"
objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Error)
Case Else
objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Information)
End Select
Catch Ex As Exception
End Try
End If
End Sub
End Module
| When you set it up in VC, it should look something like this: |
| When an event happens, it will look something like this: |
| And the individual item will look something like this: |
Labels: VMware