Automating the Infrastructure

Focusing on scripts, MOM, SMS, WMI, and any other technologies design to assist operations staff in performing their entire job function from the comfort of their own desk.

"Generic Failure" problem with MOM WMI provider

Just ran across this one.  If you try to update a MOM object through the WMI provider, you may get the not so descriptive error message "Generic failure".  For example, the following script should work just fine to automatically resolve all open alerts.

Set objWMI = GetObject("winmgmts://./root/MOM")
strQuery = "select * from MSFT_Alert where ResolutionState <> 255"
Set colAlerts = objWMI.ExecQuery(strQuery)
 
For Each objAlert In colAlerts
   objAlert.ResolutionState = 255
   objAlert.Put_
Next

Chances are very good though that you're going to get that "Generic failure" error on the objAlert.Put_ command.  That's when you attempt to actually commit your changes to the database.

It turns out there is a bit of a quirk in the MOM WMI provider - okay, let's call it a bug.  In any event, the workaround isn't too bad.  The problem is that the provider doesn't properly handle empty fields.  It can handle a Null, just not a field with an empty string.  A single empty field on an object - even one that has nothing to do with your script - will cause the error. 

You can correct the problem by setting any empty fields to Null before issuing the Put_.  I went through the alert object and identified all fields that might be empty.  This results in the following code:

If Len(Trim(objAlert.AlertHistoryComment)) = 0 Then objAlert.AlertHistoryComment = Null
If Len(Trim(objAlert.CustomField1)) = 0 Then objAlert.CustomField1 = Null
If Len(Trim(objAlert.CustomField2)) = 0 Then objAlert.CustomField2 = Null
If Len(Trim(objAlert.CustomField3)) = 0 Then objAlert.CustomField3 = Null
If Len(Trim(objAlert.CustomField4)) = 0 Then objAlert.CustomField4 = Null
If Len(Trim(objAlert.CustomField5)) = 0 Then objAlert.CustomField5 = Null
If Len(Trim(objAlert.Description)) = 0 Then objAlert.Description = Null
If Len(Trim(objAlert.OwnerName)) = 0 Then objAlert.OwnerName = Null
If Len(Trim(objAlert.ResolvedBy)) = 0 Then objAlert.ResolvedBy = Null
If Len(Trim(objAlert.TimeResolved)) = 0 Then objAlert.TimeResolved = Null

Put this into the Resolve All Alerts script above, and you get the following:

Set objWMI = GetObject("winmgmts://./root/MOM")
strQuery = "select * from MSFT_Alert where ResolutionState <> 255"
Set colAlerts = objWMI.ExecQuery(strQuery)
 
For Each objAlert In colAlerts
   
If Len(Trim(objAlert.AlertHistoryComment)) = 0 Then objAlert.AlertHistoryComment = Null
   
If Len(Trim(objAlert.CustomField1)) = 0 Then objAlert.CustomField1 = Null
   If Len(Trim(objAlert.CustomField2)) = 0 Then objAlert.CustomField2 = Null
   If Len(Trim(objAlert.CustomField3)) = 0 Then objAlert.CustomField3 = Null
   If Len(Trim(objAlert.CustomField4)) = 0 Then objAlert.CustomField4 = Null
   If Len(Trim(objAlert.CustomField5)) = 0 Then objAlert.CustomField5 = Null
   If Len(Trim(objAlert.Description)) = 0 Then objAlert.Description = Null
   If Len(Trim(objAlert.OwnerName)) = 0 Then objAlert.OwnerName = Null
   If Len(Trim(objAlert.ResolvedBy)) = 0 Then objAlert.ResolvedBy = Null
   If Len(Trim(objAlert.TimeResolved)) = 0 Then objAlert.TimeResolved = Null

   objAlert.ResolutionState = 255
   objAlert.Put_
Next

Certainly increases the size of the script, but it could be a lot worse.  You can just paste that little block of code into any script working with MOM alerts.  I'm not going to guarantee that I got all the fields that might be empty, but this worked for my environment.  Shouldn't be rocket science to figure out how to add another field.  Should also not be too tough to figure out how to set the fields for other MOM objects.

Oh, if you're not sure how to look at your objects through WMI in order to find the empty fields, just use WBEMTEST.  If you have no idea what that is, have a look at my paper on WMI Notifications in MOM.

 

Published Tuesday, March 28, 2006 7:54 AM by Brian Wren

Comments

 

jmontessi said:

Thanks Brian. That was exactly my problem, and it fixed it right up. Appreciate your efforts!

-james

January 8, 2007 1:42 PM
Anonymous comments are disabled

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker