Web API for System Center Operations Manager

This is updated, see this post

 

System Center Operations Manager (SCOM) is a widely used monitoring platform and one of its advatages is the ability to custom author monitoring through management pack development.
With a ‘cloud first’ approach most systems is able to do information exchange or integration through a web-based API, often reffered to as a REST API. SCOM have many ways to exchange information and the System Center Suite also have an integration platform call System Center Service Provide Foundation (SPF) which you can read more about here

To support a more light weight integration platform i decided to start my first C# project and develop a web-based API for SCOM that supported the daily used “functions”. Thanks to my colleague @RudiMartinsen i managed to create a working solution.

API Endpoints

  • [GET] Agents (Admin previlgies required)
    • Get all agents
    • single based on Guid
  • [GET] Alerts
    • Gets all alerts
    • single based on Guid
    • Single based on ComputerName
      • Include ‘closed’ with IncClosed=true
  • [PUT] Alerts
    • Update a single alert with resolution state and/or ticket id
    • Monitor generated alerts will be resett if 255 (closed) is sent as resolution state
  • [GET] WindowComputers
    • Get all partial monitoring object from the Windows Computer class
    • Single based on ComputerName
  • [POST] ComputerMaintenance*
    • Maintenance mode a Windows Computer for a specific # minutes
  • [GET] MonintoringObject/{id}
    • Get a single monitoring object based on ID (Guid)

I have uploaded the source project on GitHub and hopefully our community can continue to develop and introduce new features missing in this release.

 

Installation

There are two versions of the API. One without user impersonation and one where this is available. To install the version with user impersonation enabled. Do the following on a SCOM Management server

  • Download the project or .zip file from GitHub
  • Copy the required .dll from your management server (\Operations Manager\Server\SDK Binaries) to the web api Bin folder
    • Microsoft.EnterpriseManagement.Core.dll
    • Microsoft.EnterpriseManagement.OperationsManager.dll
    • Microsoft.EnterpriseManagement.Runtime.dll
  • Create a new web site and set physical path to where you extracted the files

  • Enable windows authentication (and basic if you want)
  • Set your Application pool to use network service identity

 

Examples

Using powershell here are a few examples on how you can use the API

Get Alerts
#Get all alerts
Invoke-RestMethod -Uri 'http://localhost:64049/Api/alerts' -UseDefaultCredentials

#Get a single alert
Invoke-RestMethod -Uri 'http://localhost:64049/Api/alerts?id=4a6f29e3-f4b5-4883-a3f2-97eb3be50c12' -UseDefaultCredentials

#Get alerts specified with computername
Invoke-RestMethod -Uri 'http://localhost:64049/Api/alerts?ComputerName=COMPUTERNAME.fqdn' -UseDefaultCredentials
Put a computer in to maintenance
PS C:\Users\...> $json = @"
{
    "DisplayName": "COMPUTERNAME.fqdn",
    "Minutes": 10,
    "comment": "I believe this is working"
}
"@

Invoke-RestMethod -Method POST -Uri 'http://localhost:64049/API/ComputerMaintenance' -Body $json -UseDefaultCredentials -ContentType 'Application/json'

Returns

DisplayName           Minutes EndTime                      comment                  
-----------           ------- -------                      -------                  
COMPUTER NAME.fqdn      10 2017-05-05T08:42:56.5938294Z I believe this is working
Get a monitoring object
#Get a monitoring object
Invoke-restmethod -uri 'http://localhost:64049/API/MonitoringObject/cb191c1a-47dc-3c51-3686-9f66dd59f187' -UseDefaultCredentials


displayName : D:
healthState : Success
inMaintenance : False
stateLastModified : 23.03.2017 15.39.23
classes :
path : MyComputerHostingThisDisk.fqdn

 

Limitations*

  • SCOM .dll files will need to copied manually in to the web api application folder as I assume im not allowed to redestribute these.
Martin Ehrnst
Systems Engineer working with SCOM, OMS and Azure
IT Pro with a passion for monitoring. Working with System Center, OMS, Azure and related software and cloud services.

Direct customer experience from previously being a Technical Account Manager.

Community supporter where I try to contribute via blogging and social media.

Posted by Martin Ehrnst

Working as a systems engineer in one of Norway's leading enterprise cloud providers. Mainly working with System Center, Azure and Windows server products

*All post are personal

16 Comments

    1. Webdav is enable. Have you ever tested with SCOM 2016 on Windows 2012 R SErver and IIS 8.5?

      1. That might be your problem. check the link if it makes sense. No sorry, only 2012 R2 os and scom and 2016 scom/os, but your combination should work, as it is the put command that seems to be the issue

        1. Finally it works.
          After make some configuration change in IIS and use -Credential instead -UseDefaultCredentials.

          Thanks you
          Hung

  1. Put server in Mainteance works but put/update an Alert doesn’t work. Do you have an example for updating an alert?

    1. Hi Hung Le,

      What languange are you calling the API with, is it working through swagger?
      Using PowerShell: Invoke-RestMethod -Uri 'https://ApiServer/API/Alerts?Id=2d35ff56-687f-48d0-b03c-0b9cb5354a37&ResolutionState=255' -UseDefaultCredentials -Method Put
      will update the alert (in this case close it)

      1. Hi Martin,
        when i run follow command with powershell:

        Invoke-RestMethod -Uri ‘http://localhost:8888/API/Alerts?Id=128d68a5-fcf5-4358-bced-a43dc5e3a124&ResolutionState=255’ -UseDefaultCredentials -Method Put
        i got follow error:
        Invoke-RestMethod :
        IIS 8.5 Detailed Error – 405.0 – Method Not Allowed
        HTTP Error 405.0 – Method Not Allowed
        The page you are looking for cannot be displayed because an invalid method (HTTP verb) is being used.

Engage by commenting