ehrnst / System-Center-Operations-Manager-API

Microsoft System Center Operations Manager (SCOM) Web API
http://adatum.no/operationsmanager/web-api-for-scom
MIT License
41 stars 7 forks source link

Feature Request: Maint.Mode for MonitoringObject (Class) #1

Closed s2patrick closed 7 years ago

s2patrick commented 7 years ago

Hi, great API, thanks for that.

It would be great to see the method to set a Maint. Mode not just for Windows Computers, but for any class. For instance, we need to set MM for a class to which service monitors are targeted, not the whole machine.

Thanks again and best, Patrick

ehrnst commented 7 years ago

Hi Partick, thank you for your feedback.

Just to be clear, you want to maintenance a monitoring object regardless of class, right? If that is the case I think I can manage that, i just have to find the time to implement it.

s2patrick commented 7 years ago

Hi, yes... that is correct. /patrick

ehrnst commented 7 years ago

Patrick. I will find some time to review this, but if you add this to the maintenance controller i believe it should work. ` ///

/// Puts the specified monitoring object in maintenance mode. /// /// Json string with Id, # of minutes and a comment /// /// { /// "id": "Guid", /// "Minutes": 10, /// "comment": "doing maintenance" /// } /// /// Successfully added maintenance mode for the object /// Bad request. Check json input /// Conflict: object already in maintenance [HttpPost] [Route("API/ObjectMaintenance")] public IHttpActionResult EnableObjectMaintenance(SCOMObjectMaintenanceModel Data) { //create a Guid from the json input var ObjectId = new Guid(Data.id); //get the monitoring object by Guid var monObject = mg.EntityObjects.GetObject(ObjectId, ObjectQueryOptions.Default);

        List<SCOMMonitoringObjectModel> MonitoringObjects = new List<SCOMMonitoringObjectModel>();

        List<SCOMObjectMaintenanceModel> MaintenanceObjects = new List<SCOMObjectMaintenanceModel>();

            if (!monObject.InMaintenanceMode)
            {
                {
                    //set maintenance properties
                    DateTime startTime = DateTime.UtcNow;
                    DateTime schedEndTime = DateTime.UtcNow.AddMinutes(Data.Minutes);
                    MaintenanceModeReason reason = MaintenanceModeReason.PlannedOther;
                    string comment = Data.comment;

                    monObject.ScheduleMaintenanceMode(startTime, schedEndTime, reason, comment);

                    //Add properties to list
                    SCOMObjectMaintenanceModel maintenanceObject = new SCOMObjectMaintenanceModel();
                    maintenanceObject.displayName = monObject.DisplayName;
                    maintenanceObject.id = monObject.Id.ToString();
                    maintenanceObject.EndTime = schedEndTime;
                    maintenanceObject.Minutes = Data.Minutes;
                    maintenanceObject.comment = comment;

                    //add computers to list
                    MaintenanceObjects.Add(maintenanceObject);

                }
            }

            //If computer already in maintenance. Do nothing and list info
            else
            {
                MaintenanceWindow MaintenanceWindow = monObject.GetMaintenanceWindow();

                HttpResponseMessage message = new HttpResponseMessage(HttpStatusCode.Conflict);
                message.Content = new StringContent("Object already in maintenance until" + MaintenanceWindow.ScheduledEndTime);
                throw new HttpResponseException(message);

            }

        //Return list of computers as Json
        return Json(MaintenanceObjects);

    }`
ehrnst commented 7 years ago

Patrick. Try the api from the dev branch. A lot of updates including the one you requested

s2patrick commented 7 years ago

Ehrnst, hi. Awesome, thank you for your time. Will try next week once I am back at my lab. I owe you a beer! :-)