Home » Scripts » Configure Command Notification in R2

Contoso.se

Welcome to contoso.se! My name is Anders Bengtsson and this is my blog about Azure infrastructure and system management. I am a senior engineer in the FastTrack for Azure team, part of Azure Engineering, at Microsoft.  Contoso.se has two main purposes, first as a platform to share information with the community and the second as a notebook for myself.

Everything you read here is my own personal opinion and any code is provided "AS-IS" with no warranties.

Anders Bengtsson

MVP
MVP awarded 2007,2008,2009,2010

My Books
Service Manager Unleashed
Service Manager Unleashed
Orchestrator Unleashed
Orchestrator 2012 Unleashed
OMS
Inside the Microsoft Operations Management Suite

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.


26 Comments

  1. Hi Anders,

    does SCOM have capability to write the alerts in logfile? if so can you please let me know the instruction.

    Thanks,
    Hamendra

  2. Hi Anders,
    We have installed trial version of SCOM 2007 monitoring tool for Biztalk. Whenever orchestration suspended, we are getting alert in Ops manager console. But alerts have not been automatically forward to E-mail. Every time we have to manually forward the alert to “E-mail by using Forward to–> operations manager Internal Connector”. Could you please advise how to configure alert being automatically forward to E-mail.
    Please let me know, if you need more clarification.

    Thanks and regards,
    -Gopal

  3. Hi,

    I tried your example and it work. But, I would like to get the recipient of the notification.
    I use “$Data/Recipients/To/Address/Address$” and it always content the string “address”.
    Do you know a way to get the recipient or subscriber name?
    or the TO in your vbs comment:
    ‘ LOG TO FILE (DATE,TIME,TO,ALERT NAME,STATE

    any ideas?

  4. Yes it does work : I run the following from the command line

    c:\windows\system32\cmd.exe /c c:\smsapp\sendsms.bat ” Test”

    If I create a BAT which starts command shell and from there if I execute the c:\smsapp\sendsms.bat ” Test” , It works too.

  5. I do have a batch file which send sms via Gateway. As mentioned in the post I have done the config as below but notification doesnt happen. An ideas?

    Full path of the command line : c:\windows\system32\cmd.exe

    Command line param : /c c:\smsapp\sendsms.cmd “$Data/Context/DataItem/AlertName$”

    Start up folder : C:\smsapp

  6. I exactly implemented the same config, it doesnot work.even when I change the command line parameters to something simple as /c ipconfig>c:\test.txt it write a text file,it doesnot work
    However when I manually enter

    C:\windows\system32\cscript.exe /c C:\sms.vbs test

    It works.

    What could be wrong.I am pretty new to SCOM

    Thanks

  7. Have some a Idea how yan I open the internet explorer and give the Alert Content to defined places in the URL. I need somthin easy for our Helpdesk to open Tickets for 2nd Level manually but without Mail and any past an copy.

  8. Meanwhile I found the problem (but no solution :d). I added some logging into my vbs code. I am using AT commands to send an SMS, more specific the sendkey method. When I ask the vbs to create a txt file after each line of code (example: cmd.txt, telnet.txt, sms.txt), the script creates this txt files.

    However, when you execute manually the VBS file, the focus is within the cmd / telnet session and writes the sended keys. But what happens in SCOM ? Where are the keys send to ? I guess not to the activated cmd/telnet. That’s my problem, now finding the solution …

    Hereby the script I used:

    Set oShell = CreateObject(“WScript.Shell”)
    set WshShell = WScript.CreateObject(“WScript.Shell”)
    oShell.run”cmd.exe”
    WScript.Sleep 500
    oShell.SendKeys”telnet 10.1.1.208 5000″
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”admin”
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”admin”
    oShell.SendKeys(“{Enter}”)
    WScript.Sleep 1000
    oShell.SendKeys”AT”
    oShell.Sendkeys (“{ENTER}”)
    WScript.Sleep 5000
    oshell.SendKeys “AT” & Chr(13)
    WScript.Sleep 10000
    oShell.SendKeys “AT” & (“{+}”) & “CMGS” & (“{=}”) & “+xxxxxxxx”
    WScript.Sleep 10000
    oShell.SendKeys “{Enter}”
    WScript.Sleep 10000
    oShell.SendKeys “test scom”
    WScript.Sleep 10000
    oShell.SendKeys “^(Z)”
    WScript.Sleep 15000
    oShell.run”taskkill /F /IM telnet.exe”
    WScript.Sleep 5000
    Wscript.Quit

  9. 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 ?

  10. 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)

  11. 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.

  12. 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?

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.