Alert raised time (local)


Recently we added a global customer to our owns. It spans 6 time zones with several sites and branch offices. This moved our monitoring scenarios one step further and sadly rised what I see as a major lack in OpsMgr. The first thing our support people asked me was: I need to know when this has happened in local time, it’s ok to have alerts in my local time but I need to know when this happened in agent local time. Easy I though, I could remember from MOM 2005 times the alert table had a local time raised field… alas this is no more the case with OpsMgr.

We needed a solution so I started drilling into the alert exposed fields. First there’s no help in the extended alert properties as they’re visible in console, they all just report the alert time in console local time.

I took a closer look at the database table and I confirmed there’s no direct or indirect reference at the alert local agent time, but things were not so bad at least the alert context had all the data I needed.

image

From my research *almost* every alert has a context (there are exception for rollup generated alerts) and in the alert context there’s always the time property referring to the agent local time.

So it was time to bring this piece of information in console and the natural way to do so is via an alert targeted task. The logic is very simple in powershell:

# Get the named parameters
param($alertGUID)

#let’s register the opsmgr snapin

#required error checking is missing
$Setup =Get-Item -Path “HKLM:\Software\Microsoft\Microsoft Operations Manager\3.0\Setup”
$dir = $setup.GetValue(“InstallDirectory”)
cd $dir
add-pssnapin Microsoft.EnterpriseManagement.OperationsManager.Client
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Functions.ps1;
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.NonInteractiveStartup.ps1

    $alert = Get-Alert -id:$alertGUID
    if($alert -ne $null)
    {
        if ($alert.context -ne $null -and $alert.context -ne “”)
        {
            $c = [xml] $alert.context
            $localtime = [datetime] $c.DataItem.Time.Substring(0,19)
        }
        else
        {
            $localtime = “unknown”
        }
        $message = ($alert.Name) + “`nLocal Agent Time Raised: ” + $localtime + “`nUTC Time Raised: ” + ($alert.TimeRaised) `
            + “`nUTC Time Last Modified: ” + ($alert.LastModified)
    }
    else
    {
        $message = “alert not found”
    }

#finally return the raw message
    $message

The net result is not elegant but it works:

image

This is an internal tool so it lacks error checking and a proper installation procedure. To have a better interface I could have written a small managed code utility with a few lines of OpsMgr SDK and some UI, but it was out of scope at this time. Maybe in the future if more data is needed.

To make the while thing work you have to:

  1. Copy the powershell script in the OpsMgr installation directory on every console computer
  2. Import the attached management pack

Hope this help.

You can find the attachments here: Get Alert local time

– Daniele

This posting is provided “AS IS” with no warranties, and confers no rights.

Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: