Skip to content
This repository has been archived by the owner on Mar 24, 2023. It is now read-only.

Commit

Permalink
Merge pull request #18 from ehrnst/dev
Browse files Browse the repository at this point in the history
Version 1.1 - adds support for performance data plus a few bug fixes
  • Loading branch information
ehrnst authored Feb 27, 2018
2 parents 235418e + 8bc7c43 commit e7ed7ad
Show file tree
Hide file tree
Showing 9 changed files with 476 additions and 33 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ Bringing SCOM in to the 21. century with a Restful Web API.
| [GET] API/MonitoringObject/{id} | Get a monitoring object and all child object |
| [GET] API/MonitoringObject/class/{classId} | Get all objects of a class. Limited properties returned. |

### Performance

### Installation
| Route | Description | Parameters |
| ------ | ------ | ------ |
| [GET] API/Perf/{managedEntityId} | Get RAW performance data from a specific managedEntity and metric | managedEntityId, counterName, startDate, endDate |
| [GET] API/Perf/hourly/{managedEntityId} | Get hourly aggregated performance data from a specific managedEntity and metric | managedEntityId, counterName, startDate, endDate |
| [GET] API/Perf/daily/{managedEntityId} | Get daily aggregated performance data from a specific managedEntity and metric | managedEntityId, counterName, startDate, endDate |

- Download the zip and extract to your SCOM management server running IIS or download the whole source to make your own customizations
- Create a new web site and application pool
- Set your application pool to use Network Service
- Enable windows authentication (basic if needed)
- Copy SCOM specific .dll's to the BIN folder where you extracted the .Zip
### Installation

### Remarks
- Please note that versioning isn't implemented and current version have breaking changes to Alert endpoints. Please review the changes to get an understanding on how this affects your application. For first time users this is not a problem.
Follow the (very limited) guide here https://github.com/ehrnst/System-Center-Operations-Manager-API/wiki/Installation-and-configuration
8 changes: 5 additions & 3 deletions SCOM API/Controllers/SCOMAlertController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,10 @@ public IList<MonitoringAlert> GetAlertByMonitoringObjectId(Guid MonitoringObject
/// For more information please see technet documentation "http://bit.ly/2zblZLh"</param>
/// <param name="Id">Specify alert guid you want to update</param>
[HttpPut]
[ResponseType(typeof(IEnumerable<MonitoringAlert>))]
[ResponseType(typeof(HttpResponseMessage))]
[Route("Alerts/{Id:Guid}")]
public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
//public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
public IHttpActionResult UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
{
if (Id == Guid.Empty)
{
Expand Down Expand Up @@ -246,7 +247,8 @@ public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] S
}

}
return alerts;
// creating OK response
return Ok(new { message = "Alert updated", alertId = Id.ToString() });

}

Expand Down
92 changes: 85 additions & 7 deletions SCOM API/Controllers/SCOMMaintenanceController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using System.Configuration;
using System.Web.Http.Description;
using Microsoft.EnterpriseManagement.Monitoring.MaintenanceSchedule;
using Swashbuckle.Swagger.Annotations;

namespace SCOM_API.Controllers
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public IHttpActionResult EnableComputerMaintenance(SCOMComputerMaintenanceModel

List<SCOMComputerMaintenanceModel> MaintenanceComputers = new List<SCOMComputerMaintenanceModel>();

///travers trough all classes to get monitoring objects
//travers trough all classes to get monitoring objects
foreach (ManagementPackClass monClass in monClasses)
{
monObjects.AddRange(mg.EntityObjects.GetObjectReader<MonitoringObject>(criteria, ObjectQueryOptions.Default));
Expand Down Expand Up @@ -111,8 +112,6 @@ public IHttpActionResult EnableComputerMaintenance(SCOMComputerMaintenanceModel





/// <summary>
/// Puts the specified monitoring object in maintenance mode.
/// </summary>
Expand Down Expand Up @@ -190,14 +189,92 @@ public IHttpActionResult EnableObjectMaintenance(SCOMObjectMaintenanceModel Data

}

/// <summary>
/// Updates or ends existing maintenance mode for object.
/// </summary>
/// <param name="Data">Json string with object id and new endTime</param>
/// <param name="EndNow">If true, maintenance will end</param>
/// <example>
/// {
/// "id": "Guid",
/// "EndTime": "2017-07-07T19:00:00.000Z"
/// }
/// </example>
/// <response code="200">Successfully updated maintenance mode</response>
/// <response code="400">Bad request. Check json input</response>
/// <response code="304">Object not in maintenance. Nothing to update</response>

[HttpPut]
[SwaggerResponse(HttpStatusCode.OK, "Object maintenance mode updated")]
[ResponseType(typeof(HttpResponseMessage))]
[Route("API/ObjectMaintenance")]
public IHttpActionResult UpdateObjectMaintenance(SCOMUpdateObjectMaintenanceModel Data, bool EndNow = false)
{
//Validate input
if (ModelState.IsValid)
{
//create a Guid from the json input
var ObjectId = new Guid(Data.id);
//get the monitoring object by Guid
var monObject = mg.EntityObjects.GetObject<MonitoringObject>(ObjectId, ObjectQueryOptions.Default);

//If object not in maintenance not modified
if (!monObject.InMaintenanceMode)
{
{
HttpResponseMessage res = new HttpResponseMessage(HttpStatusCode.NotModified);
res.Content = new StringContent("Specified object not in maintenance mode. Nothing to update...");
throw new HttpResponseException(res);
}
}

//If object in maintenanance update
else
{
//If endNow parameter validate true. End maintenance mode
if (EndNow.Equals(true))
{
monObject.StopMaintenanceMode(DateTime.UtcNow, TraversalDepth.Recursive);

}

// Get the maintenance window
MaintenanceWindow MaintenanceWindow = monObject.GetMaintenanceWindow();

//If user specifies an end date
if (Data.EndTime > DateTime.MinValue)
{

//Compare specified end time with current maintenance end time
int TimeCompare = DateTime.Compare(Data.EndTime, MaintenanceWindow.ScheduledEndTime);
//Update end time but use same reason and comment
monObject.UpdateMaintenanceMode(Data.EndTime, MaintenanceWindow.Reason, MaintenanceWindow.Comments);
}

}
// creating OK response
return Ok(new { message = "Updated maintenance mode", monitoringObjectId = Data.id });

}

// throw error message
else
{
HttpResponseMessage res = new HttpResponseMessage(HttpStatusCode.BadRequest);
res.Content = new StringContent("Please check request body");
throw new HttpResponseException(res);
}
}


/// <summary>
/// Creates a new maintenance schedule with the specified monitoring objects.
/// </summary>
/// <param name="Data">Json string scheduleName, object ids, StartTime, EndTime, comment</param>
/// <param name="Data">scheduleName, object ids, StartTime, EndTime, comment are mandatory</param>
/// <example>
/// {
/// "scheduleName": "string",
/// "id": "[monitoringObjectId]",
/// "id": "[monitoringObjectId's]",
/// "StartTime": "2017-05-22T07:01:00.374Z",
/// "EndTime": "2017-05-22T08:01:00.374Z",
/// "comment": "doing maintenance"
Expand Down Expand Up @@ -233,7 +310,6 @@ public IHttpActionResult ScheduleObjectMaintenance(SCOMObjectSchedMaintenanceMod

ObjectList.Add(item);
}
//

//create a recurrencePattern this is 'sourced' from OmCommands.10.dll ( new-scommaintenanceSchedule CMDLET )
//read more: https://docs.microsoft.com/en-us/powershell/systemcenter/systemcenter2016/operationsmanager/vlatest/new-scommaintenanceschedule
Expand Down Expand Up @@ -263,10 +339,11 @@ public IHttpActionResult ScheduleObjectMaintenance(SCOMObjectSchedMaintenanceMod
var shed = MaintenanceSchedule.GetMaintenanceScheduleById(guid, mg);
List<SCOMObjectSchedMaintenanceModel> MaintenanceScheduleList = new List<SCOMObjectSchedMaintenanceModel>();
SCOMObjectSchedMaintenanceModel mSched = new SCOMObjectSchedMaintenanceModel();
mSched.scheduleId = guid;
mSched.scheduleName = shed.ScheduleName;
mSched.id = array;
mSched.StartTime = shed.ActiveStartTime;
mSched.EndTime = shed.ScheduledEndTime;
mSched.scheduleName = shed.ScheduleName;
mSched.comment = shed.Comments;

MaintenanceScheduleList.Add(mSched);
Expand All @@ -276,5 +353,6 @@ public IHttpActionResult ScheduleObjectMaintenance(SCOMObjectSchedMaintenanceMod

}


}
}//END
Loading

0 comments on commit e7ed7ad

Please sign in to comment.