public IHttpActionResult GetComputerPartialMonitoringObject() { ManagementPackClassCriteria classCriteria = new ManagementPackClassCriteria("Name = 'Microsoft.Windows.Computer'"); IList <ManagementPackClass> monitoringClasses = mg.EntityTypes.GetClasses(classCriteria); List <PartialMonitoringObject> windowsComputerObjects = new List <PartialMonitoringObject>(); IObjectReader <PartialMonitoringObject> reader = mg.EntityObjects.GetObjectReader <PartialMonitoringObject>(monitoringClasses[0], ObjectQueryOptions.Default); windowsComputerObjects.AddRange(reader); List <SCOMComputerModel> SCOMComputers = new List <SCOMComputerModel>(); foreach (PartialMonitoringObject windowsComputerObject in windowsComputerObjects) { SCOMComputerModel SCOMComputer = new SCOMComputerModel(); SCOMComputer.id = windowsComputerObject.Id; SCOMComputer.displayName = windowsComputerObject.DisplayName; SCOMComputer.healthState = windowsComputerObject.HealthState.ToString(); SCOMComputer.inMaintenance = windowsComputerObject.InMaintenanceMode; SCOMComputer.isAvailable = windowsComputerObject.IsAvailable; SCOMComputers.Add(SCOMComputer); } return(Json(SCOMComputers)); }
public IHttpActionResult GetLinuxComputersByName(string ComputerName) { ManagementPackClassCriteria classCriteria = new ManagementPackClassCriteria("Name = 'Microsoft.Linux.Computer'"); IList <ManagementPackClass> monitoringClasses = mg.EntityTypes.GetClasses(classCriteria); if (string.IsNullOrEmpty(ComputerName)) { throw new HttpResponseException(Request .CreateResponse(HttpStatusCode.BadRequest)); } else { MonitoringObjectCriteria criteria = new MonitoringObjectCriteria(string.Format("Name = '{0}'", ComputerName), monitoringClasses[0]); List <PartialMonitoringObject> linuxComputerObjects = new List <PartialMonitoringObject>(); IObjectReader <PartialMonitoringObject> reader = mg.EntityObjects.GetObjectReader <PartialMonitoringObject>(criteria, ObjectQueryOptions.Default); linuxComputerObjects.AddRange(reader); //Check if computers are in list if (linuxComputerObjects.Count > 0) { List <SCOMComputerModel> SCOMLinuxComputers = new List <SCOMComputerModel>(); foreach (PartialMonitoringObject linuxComputerObject in linuxComputerObjects) { SCOMComputerModel SCOMComputer = new SCOMComputerModel(); SCOMComputer.id = linuxComputerObject.Id; SCOMComputer.displayName = linuxComputerObject.DisplayName; SCOMComputer.healthState = linuxComputerObject.HealthState.ToString(); SCOMComputer.inMaintenance = linuxComputerObject.InMaintenanceMode; SCOMComputer.isAvailable = linuxComputerObject.IsAvailable; SCOMLinuxComputers.Add(SCOMComputer); } //Successful return return(Json(SCOMLinuxComputers)); } //If computer cannot be found else { HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.NotFound); message.Content = new StringContent("Cannot find Computer. Please see input"); throw new HttpResponseException(message); } } }