December 22, 2024

VMware: Read VirtualCenter Events in MOM 2005

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

Unfortunately, {entityName} and {entityObject} don’t seem to work right now, but you can parse the {eventDescription} to get the object’s name.

So with a little help from a .NET guy here at work, I was off, on my first VB.NET application. To be honest, it looks more like .vbs to me, but put it in VB.NET, and I guess it is VB.NET.

First, well need to compile the application. You can find a copy of it here. You’ll need WinZip, or some other zip application to unzip it.

I’ve included the .exe in the zip, but feel free to delete it and recompile it. (I don’t always trust everyone else’s code).

Here’s the basic contents of the VB application, a file called MakeEventCall.vb, and it includes the following code:

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

Once you have compiled the app, drop it off somewhere on your VirtualCenter server that is in the path. This will make it easier to run it, and will help with an issue with the “Run A Script” alert function in VC 2.0.x.

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:

Keep in mind, this is not a complete solution, but more of a starting point to get VC events into MOM 2005.

Additionally, because this application simply writes to the event log, any monitoring software that reads the Application Event Log, will be able to pick up this information.

Enjoy.

4 thoughts on “VMware: Read VirtualCenter Events in MOM 2005

  1. Jase,

    Would you like to include a real word sidebar about your mom integration in a Sybex book about VMware Infrastructure 3?

    Chris

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.