Configure Command Notification in R2

There has been a number of questions about the command notification channel in Technet forums. Here is a example how to configure a command notification channel, a subscriber for the channel and a subscription. This example configure a command notification channel to run a vbscript. The vbscript echo a time stamp and the alertname to a local file.

1. Go to Administration/Notification/Channels and create a new command notification channel. For example
Channel name: Contoso Command Notification Channel
Full path of the command file: C:\windows\system32\cmd.exe
Command line paramters: /c C:\logfile.vbs $Data/Context/DataItem/AlertName$
Startup folder for the command line: C:\

2. Go to Subscribers and create a new subscriber
Subscriber name: Contoso Command Line Subscriber (note that you do not need to select a AD user)
Schedule: Always send notification
Addresses: Added a new address
-Address name: Contoso Command Address
-Channel type: Command
-Command Channel: Contoso Command Notification Channel
-Delivery address for the selected channel: I just left this with default, something about sip: but it resultet in a blank field, so just leave it
-Schedule: Always send notification

3. Goto Subscriptions and add a new subscription, for example
Name: Contoso Command Line Subscription
Criteria: with a specific resolution state: new(0) and closed (255)
Subscribers: Contoso Command Line Subscriber
Channel: Contoso Command Notification Channel
Summary: Make sure the channel is enabled

Thats it, and the logfile.vbs looks like:

' ******************************************
' GET PARAMETERS INTO SCRIPT
' ******************************************
strAlert = Wscript.Arguments.Item(0)

' ******************************************
' LOG TO FILE (DATE,TIME,TO,ALERT NAME,STATE
' ******************************************
Dim Stuff, myFSO, WriteStuff, dateStamp
strdateStamp = Date()
strTimeStamp = Time()
'Write information to Text File
Stuff = strDateStamp & "," & strTimeStamp & "," & strAlert
Set myFSO = CreateObject("Scripting.FileSystemObject")
Set WriteStuff = myFSO.OpenTextFile("opsmgr_notification_logfile.txt", 8, True)
WriteStuff.WriteLine(Stuff)
WriteStuff.Close

More info about command notification channel here.

9 Comments

System Center SpartanJuly 30th, 2009 at 18:19

If anyone is interested, I have a blog enter on how to ‘Forward Ops Mgr Alerts via an SNMP Trap’ via the Command Notification in SP1 & R2.

http://systemcenterspartan.wordpress.com/2009/06/30/forwarding-opsmgr-alerts-snmp/

Cheers,
System Center Spartan

PaulSeptember 4th, 2009 at 15:48

Hi Anders,

How can i get this to run a powershell script? I can get your VBscript to run but not powershell.

i’ve got

C:\Windows\sytem32\windowspowershell\v1.0\powershell.exe in the full path of command

then

C:\PutNodeInPatchMaint.ps1 in the Paramters

and

C:\in startup folder but the powershell script never get executed.

if i run

C:\Windows\sytem32\windowspowershell\v1.0\powershell.exe c:\PutNodeInPatchMaint.ps1

the script works so i know the script is ok.

any ideas?

AndersSeptember 6th, 2009 at 8:37

You could try C:\windows\system32\cmd.exe as command and then C:\windows\system32\windowspowershell\v1.0\powershell.exe C:\PutScriptMode.ps1 as parameter.

JustinDecember 12th, 2009 at 22:38

This script works great…except when I run it, it only takes the first word from the Alert?

It appears as though the following detects a space in the variable…which causes it to only log the single word to the log file…has anybody else seen this behaviour?

Wscript.Arguments.Item(0)

Anders BengtssonDecember 12th, 2009 at 23:18

I think you need to use “” around the paramter, for example “$Data/Context/DataItem/AlertDescription$”

EdFebruary 4th, 2010 at 18:25

Where does the executable or script reside? In the RMS or MS or Gateway?

Anders BengtssonFebruary 5th, 2010 at 0:24

the RMS, and outside of Ops Mgr.

KennyFebruary 8th, 2010 at 17:10

I exactly implemented the same config, when I change the command line parameters to /c ipconfig>c:\test.txt it write a text file, but when I change the command line paramaters to /c C:\sms.vbs it doesn’t do anything at all, however when I manually enter

C:\windows\system32\cmd.exe /c C:\sms.vbs

it works … any idea ?

Anders BengtssonFebruary 8th, 2010 at 17:14

try add the cscript.exe as the command starting sms.vbs. You can see in my example how I did with a vbs file from a notification channel.

Leave a comment

Your comment