in

code4ward

code4ward.net

information technologies | consulting | development

September 2007 - Posts

  • Royal TS 1.4

     So I did it...

    I just released Version 1.4 and I'm totally excited what my user base or any new user will think of this release. I hope I will get a lot of feedback.

     Have fun...
     

  • Set-NotificationForAlert

    In MOM 2005 it was easy to notify someone on specific alerts. SCOM 2007 - with it's subscription based system - cannot handle these kind of notifications. But the limitation is the user interface. Jakub from the SCOM 2007 product team released some very useful code which helped to implement a notification based on the alert name. One problem of Jakubs code is, that it's a C# program which is not very handy and that he creates most of the stuff in code which can be created with the UI.

    I translated the script to power shell, which should be much friendlier to use, deploy and let's you quickly tweak some settings. The code below works for me (at least working with email notifications), but I have to admit, I didn't test it that much. The script usage is pretty simple, but you have to do some stuff first:

    • Setup email notification
    • Create at least one recipient
    • The alert has to be raised at least once
    • Change the $RMS variable in the script to your root management server

    Then, just execute it in Power Shell: ".C:\Set-NotificationForAlert.ps1 "This is a test alert" "This is a test notification recipient"

    Parameter 1: The name of the alert

    Parameter 2: The name of the recipient

    ## check for parameters
    param(
    [string]$AlertName = $(throw write-host "You did not specify the -AlertName parameter."),
    [string]$NotificationRecipientName = $(throw write-host "You did not specify the -NotificationRecipientName parameter. Use the Get-NotificationRecipient command to get a list of all registered notification recipients")
    )
     
    $RMS = "RootManagementServerName"
     

    write-Host
    write-Host "Executing Set-NotificationForAlert.ps1 ..."
    write-Host

    ## prepare OpsMgr shell

    if ((Get-PSSnapin | Where-Object {$_.Name -eq 'Microsoft.EnterpriseManagement.OperationsManager.Client'}) -eq $null) {
    Write-Host
    Write-Host "File OpsMgrV3.ps1 loaded."
    Write-Host "Initializing shell for operations manager..."
    Write-Host "Add Microsoft.EnterpriseManagement.OperationsManager.Client snap in."
    Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction SilentlyContinue -ErrorVariable Err
    if ($Err) { $(throw write-Host $Err) }
    }

    if ((Get-ManagementGroupConnection | Where-Object {$_.ManagementServerName -eq $RMS}) -eq $null) {
    Write-Host "Connect to Management Server: $RMS"
    New-ManagementGroupConnection $RMS -ErrorAction SilentlyContinue -ErrorVariable Err
    if ($Err) { $(throw write-Host $Err) }
    }

    if ((Get-PSDrive | Where-Object {$_.Name -eq 'Monitoring'}) -eq $null) {
    Write-Host "Create Monitoring drive from Provider."
    New-PSDrive -Name: Monitoring -PSProvider: OperationsManagerMonitoring -Root: \ -ErrorAction SilentlyContinue -ErrorVariable Err
    if ($Err) { $(throw write-Host $Err) }
    Write-Host "Operations manager shell initialized."
    Write-Host
    }

    Set-Location Monitoring:\$RMS

    $Alerts = Get-Alert | where {$_.Name -eq $AlertName}
    if ($Alerts.ProblemId -eq $null)
    {
    if ($Alerts.Count -gt 0)
    {
    $ProblemID = $Alerts[0].ProblemId.ToString()
    }
    else
    {
    throw write-host "No alert was found with the specified name"
    }
    }
    else
    {
    $ProblemId = $Alerts.ProblemId.ToString()
    }


    ## load SDK assemblies
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.Configuration")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.ConnectorFramework")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.EnterpriseManagement.Monitoring")

    ## connect to management group
    $ManagementGroup = New-Object Microsoft.EnterpriseManagement.ManagementGroup($RMS)
    $ManagementGroup.Reconnect()

    $smtpAction = $ManagementGroup.GetNotificationAction("DefaultSmtpAction")
    $recipient = $ManagementGroup.GetNotificationRecipient($NotificationRecipientName)
    $config          = New-Object Microsoft.EnterpriseManagement.Administration.AlertChangedSubscriptionConfiguration([Microsoft.EnterpriseManagement.Administration.AlertSubscriptionConfigurationType]::Any)

    $config.Criteria = "<SimpleExpression><ValueExpression><Property>ProblemId</Property></ValueExpression><Operator>Equal</Operator><ValueExpression><Value>$ProblemId</Value></ValueExpression></SimpleExpression>"

    $config.ExpirationStartTime = Get-Date
    $config.PollingIntervalMinutes = 1

    $NewGuid = [System.Guid]::NewGuid()
    $NewGuid = $NewGuid.ToString().Replace('-', '_')

    $Subscription = New-Object Microsoft.EnterpriseManagement.Administration.AlertNotificationSubscription("STACustomSubscription$NewGuid", $config)

    $Subscription.DisplayName = $NotificationRecipientName + " - " + $AlertName
    $Subscription.ToRecipients.Add($recipient)
    $Subscription.Actions.Add($smtpAction)
    $ManagementGroup.InsertNotificationSubscription($Subscription)

     

    So, hopefully I can ease some pain with this...

  • Royal TS 1.4 Coming Soon...

    RTS14

    I got a lot of feedback recently about Royal TS, mostly about the .NET Framework 1.1 requirement. Because of my poor involvement in the Royal TS 2.0 project, I decided to dig out the "old" code base and do some dirty hacks to get some of your requested features out in the wild. So what changed?

    • Requires .NET Framework 2.0
    • User Interface Upgrade
      I got rid of all 3rd Party controls and used only built-in controls (except for the Remote Desktop Control of course)
    • No more duplicate connection names or folder names possible
    • Connection list when a folder or the document is selected
    • The connection list also features a search function
    • Bulk-Edit (includes the ability to re-apply credentials to multiple connections - which is handy when you changed the password)
    • Ability to send a message to a remote session and log off a remote session
    • Some basic logging (double-click on the status bar)
    • and more...

    So stay tuned, this beast will be released soon...

Copyright © by Stefan Koell | code4ward | All rights reserved
Disclaimer   Terms of Use   Privacy Statement  Imprint
Powered by Community Server (Non-Commercial Edition), by Telligent Systems