Parameters Available in an Alert Based Task


I was using the really cool "Forward alert to Email Address" management pack from OpsMgr 2007 Unleashed and  See How to forward an Alert to an email address within the OpsMgr console on Cameron’s blog  The purpose of the task is to allow you to hilite an alert in the OpsMgr console, then send that alert to an email address.

The problem was this:  whenever I made changes to the task in the OpsMgr console, the task would stop working.  After i made any change to the task, even renaming it, the task would break and only send the first word of the alert as the subject, and then the second word of the alert text as the body of the email.

The way the original "Send Alert via Email" task worked, was that it called the script named email_alert.vbs, and passed it two OpsMgr parameters as arguments, "$NAME$", and "$DESCRIPTION$".  Then the VBscript took over from there and created an email using argument 1 ($NAME$) as the subject, and argument 2 ($DESCRIPTION$) as the body of the email. 

By default, VBscirpt recognizes aguments passed to it using SPACE as a delimeter between seperate aruguments.  The problem arises becasue $NAME$ and $DESCRIPTION$ both usually have spaces in them, so the VBSCRIPT sees each word in the alert as a seperate argument, unless the arguments are enclosed in quotes. 

The issue is addressed in the RTM version of OpsMgr by placing quotations around the parameters in the GUI when you create a task, but in SP1, for some reason, the GUI will REMOVE any quotes you put directly around a parameter name.  That is why when i would make a change to the task on my SP1 console, it would save it in the management pack WITHOUT the quotes, thereby breaking the script.

The only way i found to solve the problem, was to edit the management pack xml file directly, and put the quotes around the parameters manually.

While i was doing that, I also mapped out the name of the available alert parameters that you can pass to a script in an alert based custom task as show below.






















Also, I wanted to include more information in the email, so I decided to add more parameters to the management pack. 

These are the parameters I used in the mp:







Then i had to make some changes in the VBscript to get it to email the additional information. Originally I changed the subject to $MonitoringObjectName$ which usually logically translates to the “Source” in the opsmgr console.  Unfortunately, that parameter is sometimes blank on certain alerts (like the exchange queue alerts), so I added an if statement to the script to set the subject to $Name$ if $MonitoringObjectName$ is blank.


These are thy changes I made in the script:

if oArgs.Item(0)= "" then

    sSubjectText = oArgs.Item(1)

else sSubjectText = oArgs.Item(0)

end if


sBodyText = _

    oArgs.Item(1) & vbNewLine & vbNewLine & _

    oArgs.Item(2) & vbNewLine & vbNewLine & _

    "The alert occurred: " & oArgs.Item(3) & vbNewLine & vbNewLine & _

    "The severity was: " & oArgs.Item(4)



4 responses to “Parameters Available in an Alert Based Task

  1. When you forward an alert, I noticed that there\’s no field to enter additional comments, which I think would be a nice touch if you wanted to forward the alert to someone and at the beginning of the e-mail, include an optional message. So I dimmed a new variable, oOptionalMessage, and added an additional InputBox. I then added this variable to the sBodyText portion, so that it looks like this:
    sBodyText = _    oOptionalMessage & vbNewLine & vbNewLine & vbNewLine & vbNewLine & _    oArgs.Item(1) & vbNewLine & vbNewLine & _    oArgs.Item(2) & vbNewLine & vbNewLine & _    "The alert occurred: " & oArgs.Item(3) & vbNewLine & vbNewLine & _    "The severity was: " & oArgs.Item(4)
    Only "bad" thing with such a simple modification to the script is that if I don\’t enter any message, it alert is sent with a few blank lines.

  2. Thank you! I\’ve been looking for something like this for quite awhile. So those are the only parameters available? It would be nice to be able to include PATH and EVENT ORIGINATOR…

  3. Hey great Script, any way to get the “logging Computer” in there instead of just the “source” i have found that sometimes the source is “MSSQLSERVER” instead of the computer name. Thanks.

    • Usually, if the source is MSSQLSERVER that means that the source isn’t actually the computer, it is the object named “MSSQLSERVER” Unfortunately, that object often exists on many SQL servers.

Leave a Reply

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

You are commenting using your 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