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

Commit e7ed7ad

Browse files
authored
Merge pull request #18 from ehrnst/dev
Version 1.1 - adds support for performance data plus a few bug fixes
2 parents 235418e + 8bc7c43 commit e7ed7ad

9 files changed

+476
-33
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,14 @@ Bringing SCOM in to the 21. century with a Restful Web API.
5353
| [GET] API/MonitoringObject/{id} | Get a monitoring object and all child object |
5454
| [GET] API/MonitoringObject/class/{classId} | Get all objects of a class. Limited properties returned. |
5555

56+
### Performance
5657

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

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

65-
### Remarks
66-
- 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.
66+
Follow the (very limited) guide here https://github.com/ehrnst/System-Center-Operations-Manager-API/wiki/Installation-and-configuration

SCOM API/Controllers/SCOMAlertController.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ public IList<MonitoringAlert> GetAlertByMonitoringObjectId(Guid MonitoringObject
160160
/// For more information please see technet documentation "http://bit.ly/2zblZLh"</param>
161161
/// <param name="Id">Specify alert guid you want to update</param>
162162
[HttpPut]
163-
[ResponseType(typeof(IEnumerable<MonitoringAlert>))]
163+
[ResponseType(typeof(HttpResponseMessage))]
164164
[Route("Alerts/{Id:Guid}")]
165-
public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
165+
//public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
166+
public IHttpActionResult UpdateAlertById([FromUri()]Guid Id, [FromBody()] SCOMAlertUpdateModel Properties)
166167
{
167168
if (Id == Guid.Empty)
168169
{
@@ -246,7 +247,8 @@ public IList<MonitoringAlert> UpdateAlertById([FromUri()]Guid Id, [FromBody()] S
246247
}
247248

248249
}
249-
return alerts;
250+
// creating OK response
251+
return Ok(new { message = "Alert updated", alertId = Id.ToString() });
250252

251253
}
252254

SCOM API/Controllers/SCOMMaintenanceController.cs

Lines changed: 85 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
using System.Configuration;
1717
using System.Web.Http.Description;
1818
using Microsoft.EnterpriseManagement.Monitoring.MaintenanceSchedule;
19+
using Swashbuckle.Swagger.Annotations;
1920

2021
namespace SCOM_API.Controllers
2122
{
@@ -59,7 +60,7 @@ public IHttpActionResult EnableComputerMaintenance(SCOMComputerMaintenanceModel
5960

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

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

112113

113114

114-
115-
116115
/// <summary>
117116
/// Puts the specified monitoring object in maintenance mode.
118117
/// </summary>
@@ -190,14 +189,92 @@ public IHttpActionResult EnableObjectMaintenance(SCOMObjectMaintenanceModel Data
190189

191190
}
192191

192+
/// <summary>
193+
/// Updates or ends existing maintenance mode for object.
194+
/// </summary>
195+
/// <param name="Data">Json string with object id and new endTime</param>
196+
/// <param name="EndNow">If true, maintenance will end</param>
197+
/// <example>
198+
/// {
199+
/// "id": "Guid",
200+
/// "EndTime": "2017-07-07T19:00:00.000Z"
201+
/// }
202+
/// </example>
203+
/// <response code="200">Successfully updated maintenance mode</response>
204+
/// <response code="400">Bad request. Check json input</response>
205+
/// <response code="304">Object not in maintenance. Nothing to update</response>
206+
207+
[HttpPut]
208+
[SwaggerResponse(HttpStatusCode.OK, "Object maintenance mode updated")]
209+
[ResponseType(typeof(HttpResponseMessage))]
210+
[Route("API/ObjectMaintenance")]
211+
public IHttpActionResult UpdateObjectMaintenance(SCOMUpdateObjectMaintenanceModel Data, bool EndNow = false)
212+
{
213+
//Validate input
214+
if (ModelState.IsValid)
215+
{
216+
//create a Guid from the json input
217+
var ObjectId = new Guid(Data.id);
218+
//get the monitoring object by Guid
219+
var monObject = mg.EntityObjects.GetObject<MonitoringObject>(ObjectId, ObjectQueryOptions.Default);
220+
221+
//If object not in maintenance not modified
222+
if (!monObject.InMaintenanceMode)
223+
{
224+
{
225+
HttpResponseMessage res = new HttpResponseMessage(HttpStatusCode.NotModified);
226+
res.Content = new StringContent("Specified object not in maintenance mode. Nothing to update...");
227+
throw new HttpResponseException(res);
228+
}
229+
}
230+
231+
//If object in maintenanance update
232+
else
233+
{
234+
//If endNow parameter validate true. End maintenance mode
235+
if (EndNow.Equals(true))
236+
{
237+
monObject.StopMaintenanceMode(DateTime.UtcNow, TraversalDepth.Recursive);
238+
239+
}
240+
241+
// Get the maintenance window
242+
MaintenanceWindow MaintenanceWindow = monObject.GetMaintenanceWindow();
243+
244+
//If user specifies an end date
245+
if (Data.EndTime > DateTime.MinValue)
246+
{
247+
248+
//Compare specified end time with current maintenance end time
249+
int TimeCompare = DateTime.Compare(Data.EndTime, MaintenanceWindow.ScheduledEndTime);
250+
//Update end time but use same reason and comment
251+
monObject.UpdateMaintenanceMode(Data.EndTime, MaintenanceWindow.Reason, MaintenanceWindow.Comments);
252+
}
253+
254+
}
255+
// creating OK response
256+
return Ok(new { message = "Updated maintenance mode", monitoringObjectId = Data.id });
257+
258+
}
259+
260+
// throw error message
261+
else
262+
{
263+
HttpResponseMessage res = new HttpResponseMessage(HttpStatusCode.BadRequest);
264+
res.Content = new StringContent("Please check request body");
265+
throw new HttpResponseException(res);
266+
}
267+
}
268+
269+
193270
/// <summary>
194271
/// Creates a new maintenance schedule with the specified monitoring objects.
195272
/// </summary>
196-
/// <param name="Data">Json string scheduleName, object ids, StartTime, EndTime, comment</param>
273+
/// <param name="Data">scheduleName, object ids, StartTime, EndTime, comment are mandatory</param>
197274
/// <example>
198275
/// {
199276
/// "scheduleName": "string",
200-
/// "id": "[monitoringObjectId]",
277+
/// "id": "[monitoringObjectId's]",
201278
/// "StartTime": "2017-05-22T07:01:00.374Z",
202279
/// "EndTime": "2017-05-22T08:01:00.374Z",
203280
/// "comment": "doing maintenance"
@@ -233,7 +310,6 @@ public IHttpActionResult ScheduleObjectMaintenance(SCOMObjectSchedMaintenanceMod
233310

234311
ObjectList.Add(item);
235312
}
236-
//
237313

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

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

277354
}
278355

356+
279357
}
280358
}//END

0 commit comments

Comments
 (0)