{"id":96,"date":"2006-12-12T07:34:00","date_gmt":"2006-12-12T14:34:00","guid":{"rendered":"http:\/\/www.jasemccarty.com\/blog\/2006\/12\/vmware-read-virtualcenter-events-in-mom-2005.html"},"modified":"2006-12-12T07:34:00","modified_gmt":"2006-12-12T14:34:00","slug":"vmware-read-virtualcenter-events-in-mom-2005","status":"publish","type":"post","link":"https:\/\/www.jasemccarty.com\/blog\/vmware-read-virtualcenter-events-in-mom-2005\/","title":{"rendered":"VMware: Read VirtualCenter Events in MOM 2005"},"content":{"rendered":"<p>Challenged with a MOM 2005 project, I have been trying to figure out how to get VirtualCenter alerts into MOM.<\/p>\n<p>I didn&#8217;t want to address using forwarded SNMP traps, as not everyone seems to compile the VMware MIBs too well.<\/p>\n<p>VirtualCenter 1.x had the ability to run scripts, but it didn&#8217;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:<\/p>\n<blockquote><p>{eventDescription} full formatted message for alarm triggering event<\/p>\n<p>{entityName} name of the entity name where the alarm is triggered<\/p>\n<p>{alarmName} name of the alarm that is triggered<\/p>\n<p>{triggeringSummary} summary info of the alarm with triggering values<\/p>\n<p>{declaringSummary} summary info of the alarm declaration<\/p>\n<p>{oldStatus} alarm status before it is triggered<\/p>\n<p>{newStatus} alarm status after it is triggered<\/p>\n<p>{entityObject} inventory object as triggering alarm<\/p><\/blockquote>\n<p>Unfortunately, {entityName} and {entityObject} don&#8217;t seem to work right now, but you can parse the {eventDescription} to get the object&#8217;s name.<\/p>\n<p>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.<\/p>\n<p>First, well need to compile the application.  You can find a copy of it <a style=\"font-weight: bold;\" href=\"http:\/\/www.jasemccarty.com\/vmwareforum\/momapp.zip\">here<\/a>.  You&#8217;ll need WinZip, or some other zip application to unzip it.<\/p>\n<p>I&#8217;ve included the .exe in the zip, but feel free to delete it and recompile it.  (I don&#8217;t always trust everyone else&#8217;s code).<\/p>\n<p>Here&#8217;s the basic contents of the VB application, a file called MakeEventCall.vb, and it includes the following code:<\/p>\n<blockquote><p>Imports System.Diagnostics<\/p>\n<p>Module MakeEventCall<\/p>\n<p>&#8216;******************************************************<br \/>&#8216;* MomApp.exe &#8211; 12\/12\/06<br \/>&#8216;* Jase McCarty<br \/>&#8216;* My first VB.NET application for the purpose of<br \/>&#8216;* sending VMware VirtualCenter alerts to the<br \/>&#8216;* Application Event Log of a VirtualCenter system<br \/>&#8216;* that has a Microsoft Operations Manager Agent<br \/>&#8216;* installed on it.<br \/>&#8216;*<br \/>&#8216;* This code may be redistributed, but must have<br \/>&#8216;* this disclaimer included. Agreement to use<br \/>&#8216;* this code, absolves me from any liability.<br \/>&#8216;******************************************************<\/p>\n<p>Sub Main()<\/p>\n<p>&#8216;Variables for doing our work<br \/>Dim separators As String = &#8220;-&#8220;<br \/>Dim strIncoming As String = Microsoft.VisualBasic.Command()<br \/>Dim argCount As Integer<br \/>Dim args() As String = strIncoming.Split(separators.ToCharArray)<br \/>Dim MessageOutStart As Integer<br \/>Dim strMessageOut As String<br \/>Dim strFullMessage As String = strIncoming<br \/>Dim strApplicationName As String = &#8220;VMware VirtualCenter&#8221;<br \/>Dim objName As String<\/p>\n<p>&#8216;Variables for our potential input parameters<br \/>Dim eventDescription As String<br \/>Dim entityName As String<br \/>Dim alarmName As String<br \/>Dim triggeringSummary As String<br \/>Dim declaringSummary As String<br \/>Dim oldStatus As String<br \/>Dim newStatus As String<br \/>Dim entityObject As String<\/p>\n<p>&#8216;Don&#8217;t do anything, unless we get at least one argument<br \/>If UBound(args) > 0 Then<\/p>\n<p>    &#8216;Blank our Output Message<br \/>    strMessageOut = &#8220;&#8221;<\/p>\n<p>    &#8216;Loop through all our arguments, and process them<br \/>    &#8216;Each argument should read something like this in<br \/>    &#8216;the VirtualCenter Alert settings:<br \/>    &#8216;<br \/>    &#8216;momapp.exe -ed:{eventdescription} -ns:{newstatus} -an:{alarmname}<br \/>    &#8216;<br \/>    &#8216;Where the 2 letter argument prefix matches up with<br \/>    &#8216;the appropriate event item.<\/p>\n<p>    For argCount = 0 To UBound(args)<\/p>\n<p>        Select Case Left(args(argCount), 2)<br \/>            Case &#8220;ed&#8221;<br \/>                eventDescription = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;en&#8221;<br \/>                entityName = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;an&#8221;<br \/>                alarmName = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;ts&#8221;<br \/>                triggeringSummary = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;ds&#8221;<br \/>                declaringSummary = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;os&#8221;<br \/>                oldStatus = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;ns&#8221;<br \/>                newStatus = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>            Case &#8220;eo&#8221;<br \/>                entityObject = Right(args(argCount), Len(args(argCount)) &#8211; 3)<br \/>        End Select<br \/>    Next<\/p>\n<p>    Dim objEventLog As New EventLog<\/p>\n<p>    Try<br \/>        &#8216;Register the App as an Event Source<br \/>        If Not objEventLog.SourceExists(strApplicationName) Then<br \/>            objEventLog.CreateEventSource(strApplicationName, &#8220;Application&#8221;)<br \/>        End If<\/p>\n<p>        objEventLog.Source = strApplicationName<\/p>\n<p>        &#8216;This could be modified to include other information from above<br \/>        strMessageOut = &#8220;Alarm: &#8221; &#038; alarmName &amp;amp;amp;amp;amp;amp;amp;amp; vbCrLf &#038; _<br \/>                        &#8220;Event: &#8221; &amp; eventDescription &#038; vbCrLf<\/p>\n<p>        &#8216;Include the appropriate warning level.  If the -ns:{newstatus}<br \/>        &#8216;parameter is omitted, an Informational entry will be written to<br \/>        &#8216;the application log<br \/>        Select Case Trim(Trim(newStatus))<br \/>            Case &#8220;Green&#8221;<br \/>                objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Information)<br \/>            Case &#8220;Yellow&#8221;<br \/>                objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Warning)<br \/>            Case &#8220;Red&#8221;<br \/>                objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Error)<br \/>            Case Else<br \/>                objEventLog.WriteEntry(strMessageOut, EventLogEntryType.Information)<br \/>        End Select<\/p>\n<p>    Catch Ex As Exception<\/p>\n<p>    End Try<\/p>\n<p>End If<\/p>\n<p>End Sub<\/p>\n<p>End Module<\/p><\/blockquote>\n<p>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 &#8220;Run A Script&#8221; alert function in VC 2.0.x.<\/p>\n<table border=\"0\">\n<tbody>\n<tr>\n<td>When you set it up in VC, it should look something like this:<\/td>\n<\/tr>\n<p><\/p>\n<tr>\n<td><a onblur=\"try {parent.deselectBloggerImageGracefully();} catch(e) {}\" href=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappscreen-731596.JPG\"><img decoding=\"async\" style=\"margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;\" src=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappscreen-727514.JPG\" alt=\"\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>When an event happens, it will look something like this:<\/td>\n<\/tr>\n<tr>\n<td><a onblur=\"try {parent.deselectBloggerImageGracefully();} catch(e) {}\" href=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappevent-723410.JPG\"><img decoding=\"async\" style=\"margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;\" src=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappevent-717846.JPG\" alt=\"\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<tr>\n<td>And the individual item will look something like this:<\/td>\n<\/tr>\n<tr>\n<td><a onblur=\"try {parent.deselectBloggerImageGracefully();} catch(e) {}\" href=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappeventitem-748631.JPG\"><img decoding=\"async\" style=\"margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;\" src=\"http:\/\/www.jasemccarty.com\/blog\/uploaded_images\/momappeventitem-744525.JPG\" alt=\"\" border=\"0\" \/><\/a><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Keep in mind, this is not a complete solution, but more of a starting point to get VC events into MOM 2005.<\/p>\n<p>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.<\/p>\n<p>Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Challenged with a MOM 2005 project, I have been trying to figure out how to get VirtualCenter alerts into MOM. I didn&#8217;t want to address &hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-96","post","type-post","status-publish","format-standard","hentry","category-virtualization"],"_links":{"self":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":0,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasemccarty.com\/blog\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}