次の方法で共有


Creating a System Center 2012 Operations Manager Alert RSS feed

In OpsMgr 2007 we had the option to create a RSS Feed for Alerts using the Operations Web Console.

image

 

Selecting the RSS button would return the following RSS Feed info.

image

 

In System Center 2012 Operations Manager (OM2012) we don’t have that option anymore. But this is not really an issue, because with a little bit of PowerShell magic,
we can create our own OM2012 Alert RSS feed with all the Alert information we want. And that is exactly what I did when I saw an internal question about this feature
missing in OM2012.

Environment information:

    • System Center 2012 Operations Manager with RU1 installed
    • Two Management Servers (OM12MS01 and OM12MS02)
    • OM12MS01 has the web console installed.
    • Server features installed on OM12MS01:
  • Application-Server
  • AS-NET-Framework
  • Web-Server
  • Web-WebServer
  • Web-Common-Http
  • Web-Static-Content
  • Web-Default-Doc
  • Web-Dir-Browsing
  • Web-Http-Errors
  • Web-App-Dev
  • Web-Asp-Net
  • Web-Net-Ext
  • Web-ISAPI-Ext
  • Web-ISAPI-Filter
  • Web-Health
  • Web-Http-Logging
  • Web-Request-Monitor
  • Web-Security
  • Web-Windows-Auth
  • Web-Filtering
  • Web-Performance
  • Web-Stat-Compression
  • Web-Mgmt-Tools
  • Web-Mgmt-Console
  • Web-Mgmt-Compat
  • Web-Metabase
  • NET-Framework
  • NET-Framework-Core
  • RSAT
  • RSAT-Role-Tools
  • RSAT-Web-Server
  • PowerShell-ISE
  • WAS
  • WAS-Process-Model
  • WAS-NET-Environment
  • WAS-Config-APIs

Pre-requisites:

What is PowerShel PipeWorks?

PowerShell Pipeworks is a Framework for making Sites and Services with Windows PowerShell. Read more about Pipeworks here.

 

Installation steps for creating an OM2012 Alert RSS feed

1. Download PowerShell PipeWorks Module.
2. Copy Module to Management Server where you have installed:

  • OM2012 Management Server with Console
  • PowerShell v2.0 or higher
  • ASP.NET

3. Unblock PipeWorks.1.0.2.6.zip file before extracting (you can also use the PowerShell v3 unblock-file Cmdlet if you have PowerShell v3 installed)
image

4. Extract the PipeWorks Module to your default PowerShell Module folder.
    You can check the default folders where PowerShell is looking for PowerShell modules using the following PowerShell command:
  

$env:psmodulepath   

        image
   
    I personally have created a D:\PowerShell\Modules folder to store the PipeWorks Module and added that path to my psmodulepath variable.
    You can add a new Module Path using the following Command in PowerShell:
  

$env:PSModulePath = $env:PSModulePath + ";D:\PowerShell\Modules"

    image

5. Create an IIS Application Pool for PipeWorks
    image
    
    image
   
    Change the Identity of the Application Pool to use the OM2012 SDK Account (Microsoft System Center Data Access Service account).
    image    image

6. Add PipeWorks Application
    image

    Enter Alias and Select previously created Application Pool. Enter Physical Path where to store the later to be created OM2012 RSS Alert files.
    Create Folder PipeWorks (C:\inetpub\wwwroot\PipeWorks)  if that folder does not exist.
    image

And configure the OM12_SDK Account to connect as configuration.

image

And finally Test Connection.
image

 

7. Use PipeWorks Module to create an OM2012 Alert Web Service, which we can use as an RSS Feed.
    a. Open PowerShell ISE
    b. Load PowerShell PipeWorks Module in PowerShell ISE.
       

import-module PipeWorks -verbose

   c. Create the following Function in the PowerShell ISE:

function Get-MySCOMAlert {         <#         .Synopsis             Shows SCOM Alerts         .Description             Shows SCOM Alerts for OM2012         .Example             Get-MySCOMAlert         .Example             Get-MySCOMAlert -ResolutionState New         .Example             Get-MySCOMAlert -ResolutionState Closed         #>         [CmdletBinding()]         param         (         [Parameter(Mandatory=$True,         ValueFromPipeline=$True,         ValueFromPipelineByPropertyName=$True,           HelpMessage='What is the ResolutionState of the Alerts you want to filter on?')]         [string[]]$ResolutionState,         [int]$First=50         )         process         {             if(!(Get-Module OperationsManager))             {                 Import-Module OperationsManager             }             #To convert string ResolutionStates to integers             switch ($ResolutionState) {                 New {[int]$ResolutionState = 0}                 Closed {[int]$ResolutionState = 255}                 default {return "$($ResolutionState) is unknow ResolutionState"}             } #end Switch             Get-scomalert -ResolutionState $ResolutionState | sort -Property TimeRaised -Descending | select Severity, Priority, Name, TimeRaised -First $First         } #end Process }

image

We can test the Function by selecting the function and hitting F8
Running the following command: Get-MySCOMAlert -ResolutionState "New" -First 2 returns the latest 2 OM2012 Alerts with ResolutionState New.
image

d. Convert Function to PipeWorks Web Service by running the following PipeWorks Command:
   

ConvertTo-CommandService -Command (Get-Command Get-MySCOMAlert) -RunOnline -OutputDirectory C:\inetpub\wwwroot\PipeWorks\Get-MySCOMAlert -Force

e. Check the Web Service in your Web browser by running the following command from the PowerShell ISE

Start-Process https://localhost/PipeWorks/Get-MySCOMAlert

You should see something like this:
image

You can now test the Get-MySCOMAlert Web Service by entering a ResolutionState and First (number of Alerts you want to return)
image

Result:
image

8. Retrieve RSS feed URL.
    Now we have created the Get-MySCOMAlert Web Service we can add some parameters to retrieve the RSS Feed for the OM12 Alerts.
   

https://localhost/PipeWorks/Get-MySCOMAlert/?Get-MySCOMAlert_ResolutionState=New&Get-MySCOMAlert_First=2&-AsRSS=true

This will return the RSS Feed for all OM2012 Alerts with a ResolutionState of new and only shows the last 2 new Alerts.

image

 

Have fun and let me know some other cool things you have created using PowerShell PipeWorks!!

DISCLAIMER: THIS PROGRAM SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY REPRESENTATION OR CONDITION OF ANY KIND EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO CONDITIONS OR OTHER TERMS OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. THE USER ASSUMES THE ENTIRE RISK AS TO THE ACCURACY AND THE USE OF THIS PROGRAM CODE OR RESULTING EXECUTABLE CODE

Comments

  • Anonymous
    January 01, 2003
    Hi IceTea,

    You are right there is no ConvertTo-CommandService anymore in the latest versions of Pipeworks.

    Here is an example you can start as a basis for creating a webservice with rss feed options. Keep in mind this was just a simple example as starting point. If I've some more time I'll write a blogpost.

    # In Pipeworks, you need 3 files to make a module.
    # The Script Module ( ModuleName.PSM1),
    # The Module Manifest ( ModuleName.PSD1)
    # The Pipeworks Manifest (ModuleName.Pipeworks.psd1)

    # This will check for the module directory and create it if it doesn't exist.
    $modulePath = "$homeDocumentsWindowsPowerShellModulesGetService"

    if (-not (Test-Path $modulePath)) {
    New-Item -ItemType Directory -Path $ModulePath |
    Out-Null
    }

    # Our module will be simple. It will have one command, Get-Service.
    # We'll include it inside of the .PSM1

    @'
    function Show-Service
    {
    Get-Service
    }
    '@ |
    Set-Content "$modulePathGetService.psm1"


    # The Module Manifest File is pretty simple.
    # It includes a version, a description, and it refers to the .PSM1
    @'
    @{
    ModuleVersion = '1.0'
    ModuleToProcess = 'GetService.psm1'
    Description = 'Get Services'
    }
    '@ |
    Set-Content "$modulePathGetService.psd1"

    # The Pipeworks Manifest describes how the module will turn into a web service, and what it can do.
    # You can create a Pipeworks Manifest by hand, or you can use the New-PipeworksManifest command

    New-PipeworksManifest -Name GetService -WebCommand @{
    "Get-Service" = @{
    FriendlyName = 'Get Services'
    Runwithoutinput = $true
    Outputproperty = "Name", "DisplayName", "Status"
    }

    } |
    Set-Content "$modulePathGetService.Pipeworks.psd1"

    # To create your web service, run the following command:
    Import-Module GetService -Force -PassThru | ConvertTo-ModuleService -Force -IISReset -asintranetsite -Port 8080

    # Go to IISManager. Open the GetProcess Site. Go to Authentication and enable anonymous authentication.

    # Open rss feed
    start http://localhost:8080/Get-Service/?asrss=true # this is not a good rss example to be honest. There is no date time property.
    start http://localhost:8080/Get-Service/ #This will show you a webpage with the Services.

    Run above script as Administrator.

    Hope this helps.
  • Anonymous
    January 01, 2003
    Hi Arnaud,

    Glad you like it. Make sure you check out the latest and greatest of Pipeworks.

    /Stefan
  • Anonymous
    October 13, 2014
    The comment has been removed
  • Anonymous
    February 09, 2015
    Thank you very much Stephan for this blog post. It's very well explained with plenty of details !
    Pipeworks is awesome ! Writing web services is a very tedious task from my IT Pro perspective ;-)