Automation

Web API for System Center Operations Manager

The SCOM web API is updated, see this post

You will always find the latest SCOM Web API release on GitHub

 

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 privileges 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.

18 COMMENTS
  • Harish
    Reply

    Hi Martin

    We are trying to automate the SCOM alters by writing the script to resolve the alerts and closing them. But the thing is when i fetch the alerts from the SCOM, data is huge and it will take more time. Is there a way to restrict the no of alerts to fetch in API. Please help me it would be helpful.

    1. Martin Ehrnst
      Reply

      Hi Harish. I haven’t implemented any function to limit the # returned. I may look in to that. Just by curiosity, how many alerts are we talking, and how long does it take?

  • Hung Le
    Reply

    SCOM 2016 UR3 on WIndows 2012 R2

    1. Hung Le
      Reply

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

      1. Martin Ehrnst
        Reply

        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. Hung Le
          Reply

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

          Thanks you
          Hung

          1. Martin Ehrnst

            Perfect. Glad you sorted it out

  • Hung Le
    Reply

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

    1. Martin Ehrnst
      Reply

      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. Hung Le
        Reply

        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.

        1. Hung Le
          Reply

          Something wrong with IIS on Windows 2012 R2?

          1. Martin Ehrnst

            Strange. I don’t manage to replicate this my self. Scom 2012 and server 2012?

          2. Martin Ehrnst

            Do you have webDav enabled?
            https://forums.asp.net/t/1949993.aspx?PUT+and+DELETE+methods+not+working+on+IIS

          3. Hung Le

            SCOM 2016 and Windows 2012 R2

  • Hung Le
    Reply

    Thank you for bringing SCOM in to the 21st century

    1. Martin Ehrnst
      Reply

      Of course 😉 if you are attending Experts Live in Berlin next week, I will have a short demo of it as well.

  • Tommy Vadman
    Reply

    Useful and fun stuff 🙂 Great job!

    1. Martin Ehrnst
      Reply

      Thank you Tommy. Let me know if you experience any issues. Glad you find it useful.

Engage by commenting