Answered by:
SCOM SDK Distributed Application

Question
-
THis is the current code i have and it works good at showing the distributed applications and there health states. But i want to go one step further and see the health states of the monitors that make up the distributed applications.
public string GetITServiceStatusWarning() { //Set Number of Monitors per row int numberOfMonitors = 2; //Set to zero index by minusing 1 int maxRowLength = numberOfMonitors - 1; //read RMS name from param ManagementGroupConnectionSettings mgSettings = new ManagementGroupConnectionSettings("grropsrm01"); SecureString password = this.ConvertToSecureString("tfosorciM9002"); //UserName Properties mgSettings.UserName = "scom-msa"; mgSettings.Domain = "NA"; mgSettings.Password = password; ManagementGroup mg = new ManagementGroup(mgSettings); // enumerate all non-abstract classes that have as the base GenericService from ServiceDesigner. MonitoringClassCriteria baseclassCriteria = new MonitoringClassCriteria("Name = 'System.Service'"); ReadOnlyCollection<MonitoringClass> basemonitoringClasses = mg.GetMonitoringClasses(baseclassCriteria); //Console.WriteLine("BaseMonitoringClassName = " + basemonitoringClasses[0].Name.ToString()); MonitoringClassCriteria classCriteria = new MonitoringClassCriteria("BaseMonitoringClassId = '" + basemonitoringClasses[0].Id.ToString() + "' AND Abstract = 'false' "); // There should only be one item in the monitoringClasses collection. ReadOnlyCollection<MonitoringClass> monitoringClasses = mg.GetMonitoringClasses(classCriteria); //Int for counts error int i = 0; //Int for dataset rows error int j = 0; //Int for row count 0 to j int z = 0; //String builder for table StringBuilder firstRow = new StringBuilder(); StringBuilder secondRow = new StringBuilder(); //String to combine both first and second row StringBuilder oneRow = new StringBuilder(); StringBuilder bothRows = new StringBuilder(); //If more than one row combines then in to this string StringBuilder multiRows = new StringBuilder(); StringBuilder multiRowAll = new StringBuilder(); //DataTable Errors DataTable dt = new DataTable(); DataRow newRow = dt.NewRow(); //DataTable Warnings DataTable dt2 = new DataTable(); DataRow newRow2 = dt2.NewRow(); DataColumn newColumn = new DataColumn(); dt.Columns.Add(newColumn); DataColumn newColumn2 = new DataColumn(); dt2.Columns.Add(newColumn2); string data; foreach (MonitoringClass mc in monitoringClasses) { // The criteria specifies that you want to collect // all the monitoring objects (computers running Windows Server 2003) in an error state. //Response.Write("MonitoringClassName = " + mc.Name.ToString() + " Name: = " + mc.DisplayName.ToString() + "<br>"); ReadOnlyCollection<MonitoringObject> objects = mg.GetMonitoringObjects(mc); // Display information about each object. foreach (MonitoringObject monitoringObject in objects) { //Display Name String string displayName = monitoringObject.DisplayName.ToString(); string healthState = monitoringObject.HealthState.ToString(); if (healthState != "Uninitialized") { if (monitoringObject.HealthState.ToString() == "Warning") { //Start new row if (i == 0) { firstRow.AppendFormat("<td class='signal2' background='Images/yellow_question.png'></td><td class='name'><div class='name'>" + displayName + "</div></td>"); i++; } else if (i > 0 && i < maxRowLength) { firstRow.AppendFormat("<td class='signal2' background='Images/yellow_question.png'></td><td class='name'><div class='name'>" + displayName + "</div></td>"); i++; } else if (i == maxRowLength) { firstRow.AppendFormat("<td class='signal2' background='Images/yellow_question.png'></td><td class='name'><div class='name'>" + displayName + "</div></td>"); data = firstRow.ToString(); dt.Rows.Add(data); if (firstRow.Length > 0) { firstRow.Remove(0, firstRow.Length); } i = 0; j++; } } } } } bothRows.AppendFormat("<tr>" + firstRow.ToString() + "</tr>"); if (dt.Rows.Count < maxRowLength) { oneRow.AppendFormat("<table class='outer'>"); oneRow.AppendFormat(bothRows.ToString()); oneRow.AppendFormat("</table>"); return (oneRow.ToString()); } else if (firstRow.Length > 0) { multiRowAll.AppendFormat("<table class='outer'>"); //Error table parse while (j != 0) { j--; while (z <= j) { multiRowAll.AppendFormat("<tr>" + dt.Rows[z][0].ToString() + "</tr>"); z++; } j = 0; } z = 0; multiRowAll.AppendFormat(bothRows.ToString()); multiRowAll.AppendFormat("</table>"); return (multiRowAll.ToString()); } else if (firstRow.Length < 1 && secondRow.Length < 1) { multiRowAll.AppendFormat("<table class='outer'>"); //Error table parse while (j != 0) { j--; while (z <= j) { multiRowAll.AppendFormat("<tr>" + dt.Rows[z][0].ToString() + "</tr>"); z++; } j = 0; } z = 0; multiRowAll.AppendFormat("</table>"); return (multiRowAll.ToString()); } else { return ("Error"); } } private SecureString ConvertToSecureString(string value) { SecureString ret = new SecureString(); foreach (char c in value) { ret.AppendChar(c); } ret.MakeReadOnly(); return ret; } } } }
What would i do to show the monitors that make up the distributed applications.
Thanks!
Ben
Tuesday, August 3, 2010 3:26 PM
Answers
-
Hi Ben,
I just got the following which is used to display the information for monitoring object and hope this can be a reference which can fit your needs:
How to Display Information about a Monitoring Object
http://msdn.microsoft.com/en-us/library/bb960484.aspx
Thanks.
Nicholas Li - MSFT
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.- Marked as answer by Nicholas Li Friday, August 13, 2010 9:33 AM
Wednesday, August 4, 2010 8:54 AM