By BoLOHUKE payday loans uk

Sep 122008
 

Edit: 09/13/2008 – On the advice of Pete Zerger, updated script to include a throttling mechanism to prevent an overload if an alert storm occurs. Also changed things around to make it a more generic ‘run remote executable’ instead of run remote sound.

A question was recently asked on the MOM Mailing List over at myITforum.com.

That question was, quite to the point:
How to create a audible alert? I like to create one for the critical alerts..

I’ve been working earlier with a script that would go out and disable the run time tracing, stop it, then delete the log files. So I already had knew what would work – a simple PowerShell script that uses WMI’s process create method on a remote machine.

A caveat lector before I continue; while this solution will technically work, I haven’t tested it formally. Additionally, you’ll need to contend with permission issues that arise as well. If you’re running the OpsMgr services under a named account, you’ll need to give that same account local administrator access on whichever machine you plan to run this call against. If you’re using ‘Local System’ you’ll have to either add the RMS\Local System account to the remote machine’s admin group or embed credentials inside the WMI call((Be careful when doing this. I haven’t included directions for that because it’s just a nightmare waiting to happen. I can give you a jumping off point though.))

First, the script. It’s small and basic. It wants to know the machine you want to run the command on, the command, and because this is a a sound player, the path to the WAV file. It then creates the process via WMI, and decodes the return code. If it’s 0, everything is fine. If it’s anything else, the process creation failed and it writes an event to the Operations Manager event log, which you can create an additional rule to look for.

Download SCOM-RunRemoteExecutable.ps1

To implement this, open the Operations Console and go to Administration > Settings > Notification
Click on the Command tab, then click on add. Fill it out as you normally would:

Then click on OK, and you’ll see it with the rest of your commands:

Now to finish it up you’ll need to create a new notification recipient. Right-click on Notifications and select new recipient.

Make the display something to designate that it runs a command, I used “Sound Audible Alert”. And because the NOC isn’t manned 24/7, I limited the notification time to weekdays from 8am to 6pm. You can also adjust this from the devices tab, but I’m not going to include an emailing or other devices, so I prefer to set it in the general tab, this way it’s obvious even with a casual glance what the settings are.

After that, click on the “Notification Devices” tab, then click “Add”.
In the resulting popup, select our new notification command and enter anything for the delivery address – I used NA, because for this particular command we don’t require any additional information – but OpsMgr still needs something in there. Hit next, keep the schedule at always unless you’re adding additional channels, next again, name the device – I used “Send Audible Alert”

Click OK, and your set. Treat it like any other notification recipient – either create a new rule just for this, or edit an existing subscription and add our new recipient to it.

As you can see, using PowerShell inside of Operations Manager makes it very flexible and powerful. We can run all manner of things in response to alerts; From running a simple sound file all the way up to initiating disaster recovery scenarios and intense system diagnostics – both things which I’ll be showing you later on as we explore the Notification Command Channel together.

Be Sociable, Share!

  12 Responses to “Creating an audible alert notification in SCOM”

  1. You forgot one very important thing.
    Your script opens a new instance of the media player every time it triggers and eventually you have numerous instances open.
    You command should be:
    “C:\Program Files\Real Alternative\Media Player Classic\mplayerc.exe /close”

  2. One other note:
    The command line parameter for the Command Channel doesn’t trigger properly for me when using “-Command….”.
    I got it to work using only X:\Path\to\file\.ps1

  3. OK, I lied. Another thing …actually two more:

    1) You have to right click on the script and select properties, then “unblock” beside Security, otherwise powershell returns errors about the script being un-signed.

    2) The OpsMan account must have sufficient privileges to the file/folder when the script is located.

  4. Can I take part of your post to my blog?really like this,mate

  5. I’m trying to use a powershell script as a notification command. but nothing appen.
    When launching a vbscript everything is fine.
    i’v the same set up as you on the notification channel windows.
    Full path to file :
    C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe
    Command Line parameters :
    -Command c:\temp\test.ps1
    Initial directory:
    c:\temp
    The script just write an ok sentence to a file for now. it’s working correctly when started from a command prompt.
    Do you have any idea on what could stop the notification so start ?
    Thank’s a lot.

  6. Sure, just put a link to point where ya got it from :)

  7. It’s probably something with your command line parameters. I’d try:
    -Command “& C:\Temp\test.ps1″
    or just
    “& C:\Temp\test.ps1″
    Also remember that if your path has spaces in it, PoSh breaks it up into individual arguments, so you’d have to use single quotes instead.

  8. Thank’s a lot. It’s working with the parameter you gave :
    -Command “& c:\temp\test.ps1″
    Thank you.

  9. Hi,
    I’ve SCOM 2007 R2 x64 installed on windows 2008 R2 x64.

    When I execute the powershell script (SCOM-RunRemoteExecutable.ps1) on the RMS server I receive the following error in powershell console:
    DecipherRetCode : Cannot process argument transformation on parameter ‘retCode’
    . Cannot convert the “System.Management.ManagementBaseObject” value of type “Sy
    stem.Management.ManagementBaseObject#\__PARAMETERS” to type “System.Int32″.
    At C:\scripts\test.ps1:105 char:16
    + DecipherRetCode <<<< $retCode
    + CategoryInfo : InvalidData: (:) [DecipherRetCode], ParameterBin
    din…mationException
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,DecipherRet
    Code
    The media player launches but it also displays an error saying Windows Media player encountered a problem while playing the file.

  10. I made it work on the following architecture with some modification
    SCOM 2007 R2
    Windows 2008 server x64
    VLC as the sound player

    c:\windows\system32\windowspowershell\v1.0\powershell.exe
    -command “& c:\Scripts\SCOM_remote_sound_playing.ps1″
    c:\windows\system32\windowspowershell\v1.0\

    I had trouble if the path was SysWOW64

    Do you mind if had your post to my blog, with my modification of the script and 2007 R2 images updates?

  11. Nope, be my guest – im actually working on a proper service for all this stuff

  12. Hello,

    When I run the .PS1 file it comes with an error:

    Connot convert value “\myserver\root\cimv2:win32_process” to type “sytem.management.managementcalss”. Error: “the RPC server is unavailable. ” at C:\scripts\soundalarm.ps1:100 char:23

    But the server is Up and I can ping it from the server.

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>