Written by David Postlethwaite
I’m sure there are many out there using System Centre Operations Manager (or SCOM for short) it’s a great tool for monitoring the Windows estate.
One area where it is lacking is updating the subscribers list for a Notification Group – in other words changing the on call person for a department.
Ideally this should be done by each department but the only person who can do this a SCOM Administrator . You don’t really want to be giving everyone full admin access to the SCOM console just for this purpose.
One way round this is to create a stand alone app or web site that updates the subscribers. It is possible to do this using the .NET Microsoft.EnterpriseManagement class.
In my case I created two tables one with a list of the Notification Groups that have been defined in SCOM and another with a list of staff and their cell phones. On the web site these are held in dropdownLists. You select the Notification Group, the staff member, click OK. and it updates SCOM. Simple.
The web page also interrogates SCOM to show who is currently on call.
In these examples there is only one subscriber for each Notification Group and we simply overwrite that subscriber. It wouldn’t be too difficult to loop through a list of names.
Here’s code to retrieve a subscriber from a Notification Group called DeptName.
public static string FindSCOM_Subscriber(string DeptName)
{
string SCOMServer = "ServerName";
string returnString = "";
try
{
// make connection to SCOM Server
ManagementGroup mg = new ManagementGroup(SCOMServer);
// connect to the Notification Group
Microsoft.EnterpriseManagement.Administration.NotificationRecipient connector = new
Microsoft.EnterpriseManagement.Administration.NotificationRecipient(DeptName);
connector.Reconnect(mg);
//retrieve the subscribers
Microsoft.EnterpriseManagement.Administration.NotificationRecipient name =
connector.ManagementGroup.GetNotificationRecipient(DeptName);
//return the Name and Address (i.e. the cell phone number)
returnString = name.Devices[0].Address.ToString() + "; " + name.Devices[0].Name.ToString();
}
catch (Exception objException)
{
// if no values are found then an error is reported so we'll just return a suitable text string
returnString = " No Value";
}
return returnString;
}
Here is code to update a notification group called DeptName with the subscriber called OnCallName and a phone number of PagerNo for
In this case it overwrites the only subscriber.
public static string UpdateSCOM_Subscriber(string DeptName, string PagerNo, string OnCallName)
{
string SCOMServer = "ServerName";
string returnString = "";
try
{
// make connection to SCOM Server
ManagementGroup mg = new ManagementGroup(SCOMServer);
// connect to the Notification Group
Microsoft.EnterpriseManagement.Administration.NotificationRecipient connector = new
Microsoft.EnterpriseManagement.Administration.NotificationRecipient(DeptName);
connector.Reconnect(mg);
//retrieve the the subscribers
Microsoft.EnterpriseManagement.Administration.NotificationRecipient name = connector.ManagementGroup.GetNotificationRecipient(DeptName);
//Get the current recipient pager no
string RecipientAddress = name.Devices[0].Address.ToString();
string RecipientName = name.Devices[0].Name.ToString();
name.Devices[0].Name = OnCallName;
name.Devices[0].Address = PagerNo;
name.Update();
returnString = DeptName + " successfully changed from " + RecipientName + " to " + OnCallName;
}
catch (Exception objException)
{
returnString = "An Error occurred: " + objException.Message.ToString();
}
return returnString;
}
In conclusion this code looks quit straight forward now but at the time it was quite hard work to work out how to use the class and get the syntax correct. There were few examples around for .NET and in the end I had to translate a powershell example.
I hope it helps someone else