Wednesday, 16 May 2012

SCOM Operations Manager Alarm Export Report

This simple powershell script will export SCOM / Operations Manager 2007 alarms to csv file using the command shell.

The second script is particularly useful for answering one of the long unanswerable questions of Operations Manager... how to tell if alarms are generated by a monitor or a rule because from this report we can tell if it is or not by the column 'IsMonitorAert'. Generally speaking

  • IsMonitorAlert=true means the alarms come from monitors and will resolve themselves when the situation is fixed
  • IsMonitorAlert=fase means the alarms come from rules and won't resolve themselves when the situation is fixed.
Rule monitors can create problems when not resolved by operations as repeat alarms are suppressed as duplicates.

One common example is the service terminated unexpectedly rule in the windows server management pack.

We can also categorize the alarms and tell which management pack they came from from the column MonitoringObjectFullName 

# this script will make some csv reports of System Center Operations Manager Alarms
#**********setup root ms connection assume local ***************

$cs = get-wmiobject win32_computersystem
$rootMS = $cs.Name + "." + $cs.Domain
$rootMS = $rootMS.ToUpper() 

#*****************************************************************
#Connect to the Mgmt Group (SDK)

if (Get-PSSnapin | select-string -pattern "OperationsManager")
{echo "OPs mgr snap in is installed already";}
else
{Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;}

Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
set-location $rootMS -ErrorVariable errSnapin;

############ ALL including resolved Alerts ########################
$title="ALLAlertsByMonitoringObjectFullName"
$Body =get-alert | select Id,Name,Priority,Severity,TimeRaised,ResolutionState,TimeResolved,ResolvedBy,RepeatCount,LastModified,MonitoringObjectDisplayName,MonitoringObjectPath,Category,Description,MonitoringObjectId,MonitoringClassId,MonitoringObjectFullName,IsMonitorAlert | sort-object MonitoringObjectFullName 
$body | Export-Csv c:temp\$Title.csv

############ OPEN Alerts ########################
$title="OpenAlertsByUTCDateModDesc"
$Body =get-alert -criteria 'ResolutionState = "0"' | select Id,Name,Priority,Severity,TimeRaised,RepeatCount,LastModified,MonitoringObjectDisplayName,MonitoringObjectPath,Category,Description,MonitoringObjectId,MonitoringClassId,IsMonitorAlert | sort-object LastModified -descending
$body | Export-Csv c:temp\$Title.csv