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
NextDim objEventLog As New EventLog
Try
‘Register the App as an Event Source
If Not objEventLog.SourceExists(strApplicationName) Then
objEventLog.CreateEventSource(strApplicationName, “Application”)
End IfobjEventLog.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 SelectCatch 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.
Jase,
Would you like to include a real word sidebar about your mom integration in a Sybex book about VMware Infrastructure 3?
Chris
That would be great!
Just send me an e-mail at my first name at mydomain dot com.
Thanks!
Jase
Did you hear about VMware FT? I just read a bit about it on http://www.virtualizationteam.com/virtualization-vmware/vmware-esx-40-ft-fault-tolerant-sneak-peek.html Would u think that would replace VMware HA? I had seen a video even of FT on that link. Is it available yet?
VMware FT, will provide the ability to run “mirrored” VMs in a sense.
Looks pretty interesting.