UPDATED: Added a fix to the script to clear pending serial messages and fixed the logging. -Justin
We recently purchased a MultiTech Modem to use with our System Center Operations Manager server to send us alerts when critical system events occur, like Internet Outages or E-mail Outages, where email-to-text would no longer function. We've been using TAP on our old paging system to serve in this fashion, Telephone Alphanumeric Protocol - used to dial-up to paging providers and send alphanumeric pages, but it is very difficult to get it configured on most cellular providers support have limited if any knowledge of it and it is awfully slow waiting on 33.6K baud to connect for every message. So, after reading up on Scott's blog on how to set it up, we we're all salivating for direct SMS texting via cellular service - http://svintinner.blogspot.com/2008/02/how-to-configure-scom-2007-to-send-sms.html
We ordered a compatible to Verizon CDMA Wireless Modem, "w00t!"
The modem arrived, "Hurray!"
We got the modem activated and tested sending out SMS messages from Verizon to other cellular providers, "Bigger Hurray!!"
Connected the modem to our SCOM server and sent test alerts with "Alert: Failed to send notification using server/device" responses back from SCOM, :(
Last modified time: 5/18/2012 8:53:31 AM Alert description: Notification subsystem failed to send notification using device/server 'MultiTech - CDMA Modem' over 'SMS' protocol to '+15555551234'. Microsoft.EnterpriseManagement.HealthService.Modules.Notification.SmsNotificationException: Sms error 'PDU not supported' (16014). Rule id: Microsoft.SystemCenter.Notifications.Testing.ChannelTesting.SmsChannelTest10Turns out, CDMA modems are not supported by SCOM, currently.
http://social.technet.microsoft.com/Forums/en-ZA/operationsmanagerdeployment/thread/0ebfa1bc-e973-41eb-b2e5-5a847d647d49
Monday, July 27, 2009 10:04 PMWe could send test messages from putty using AT commands to the modem no problem. I also stumbled upon PowerShell scripting to Andrino via Serial Ports and a SCOM ticket creation PowerShell script via Command Notification Channels and boom, the light bulb popped.
We only offically support using GSM modems. We have not testing using other devices. Nothing else is supported at this time.
--------------------------------------------------------------------------------
Rob Kuehfus | System Center Operations Manager | Setup and Deployment Program Manager
Marked As Answer byRob KuehfusMicrosoft Employee, OwnerMonday, July 27, 2009 10:04 PM
Here's a reasonable alternative to the canned SMS messaging mechanism. It involved a few hours of tinkering, but I think it was well worth it. Only thing that couldn't be replicated is assigning addresses via subscribers. You'll have to either have multiple entries in the PowerShell script, multiple PowerShell scripts, or a create a input parameter to pass on launch. This could also be easy to adapt for triggering other things such as IM's, playing music files, sending faxes, operating cat food dispensers, ordering pizza, potent potables, or whatever suits your fancy.
Saved the following customsms.ps1 onto the SCOM's local C:\paging folder and then configured SCOM to trigger the PowerShell.
Note: You'll need to make sure the service account being used for the Operations Managers service is a Local Administrator on the server and to set your Powershell execution policy, http://technet.microsoft.com/en-us/library/hh849812.aspx.
Download the customsms.ps1 file as a zip, click here.
- #########################################################################
- # Name:
- # customsms.ps1
- # Powershell SMS Texting via COM port and SCOM 2007 R2
- # Rev:
- # 1.0
- # 1.1 fix clearing pending serial messages 2012/06/12
- # 1.2 change logging from transcript to out-file 2012/06/27
- #
- # Date:
- # 11:07 AM 2012/05/21
- #
- # Author:
- # Justin Bennett
- # jbennett at msjc d0t edu
- # http://justin-bennett-msjc.blogspot.com/
- #
- # Description:
- # This script is setup to be used by SCOM's Command Notification
- # Channel to send Alerts via SMS text messages directly using a COM
- # port. The inherent SMS function in SCOM doesn't work with our
- # CDMA modem, but this script does.
- #
- # Tested on a MultiTech Modem - MTCBA-C1X-N3 using SCOM 2007 R2
- # and running Windows Server 2008 R2.
- #
- # References:
- # http://www.multitech.com/en_US/DOCUMENTS/Collateral/manuals/S000478D.pdf
- # http://scug.be/blogs/dieter/archive/2011/05/11/scom-setup-command-notification-channel-subscriber.aspx
- # http://social.technet.microsoft.com/Forums/en-ZA/operationsmanagerdeployment/thread/0ebfa1bc-e973-41eb-b2e5-5a847d647d49
- #
- # Example SCOM Command Notification Channel
- # Full patch of the command file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- # Command line parameters: -command "& c:\paging\bin\customsms.ps1 -AlertSource '$Data/Context/DataItem/ManagedEntityPath$\$Data/Context/DataItem/ManagedEntityDisplayName$' -AlertName '$Data/Context/DataItem/AlertName$' -AlertSeverity '$Data/Context/DataItem/Severity$l' -AlertResolution '$Data/Context/DataItem/ResolutionStateName$' -UserAddress '$Data/Recipients/To/Address/Address$' "
- # Startup folder for the command line: c:\windows\system32\windowspowershell\v1.0
- #
- # Note:
- # Execution-Policy had to be modified on our SCOM server for this to function.
- #
- #Input Variables
- # example .\customsms.ps1 -AlertSource "Src" -AlertName "Name" -AlertSeverity "Rainbow" -AlertResolution "1080p"
- Param( [string] $AlertSource, [string] $AlertName, [string] $AlertSeverity, [string] $AlertResolution )
- #List of Addresses to send SMS text to
- # Person1 Person2
- # [array] $toaddress = "0987654321", "7654321"
- [array] $toaddress = "0987654321", "7654321"
- #Logfile
- $logfile = "C:\paging\log\Customsms_"+"_"+(get-date -format yyyy-MM-dd_hh-mm-ss)+".log"
- #Special Character for CTRL-Z
- $z= new-Object String(26,1)
- #Composed SMS Body
- $msg = $AlertSource+"; Name: "+$AlertName+"; Severity: "+$AlertSeverity+"; Resolution: "+$AlertResolution+";`r"
- function logprocess {
- #start-transcript -path ($logfile)
- Out-File $logfile -input ("Starting log") -append
- Out-File $logfile -input (get-date -format yyyy-MM-dd_hh:mm:ss) -append
- Out-File $logfile -input ("Input AlertSource: "+$AlertSource) -append
- Out-File $logfile -input ("Input AlertName: "+$AlertName) -append
- Out-File $logfile -input ("Input AlertSeverity: "+$AlertSeverity) -append
- Out-File $logfile -input ("Input AlertResolution: "+$AlertResolution) -append
- Out-File $logfile -input ("toaddress: "+$toaddress) -append
- Out-File $logfile -input ("Arg: "+$msg) -append
- }
- logprocess
- try
- {
- $port = new-Object System.IO.Ports.SerialPort
- $port.PortName = "COM1"
- $port.BaudRate = 115200
- $port.Parity = "None"
- $port.DataBits = 8
- $port.StopBits = 1
- $port.Handshake = "RequestToSendXOnXOff"
- $port.ReadTimeout = 1000
- #Wait 5 Seconds
- #Start-Sleep 5
- $port.open()
- #clear pending messages
- $port.ReadExisting()
- #Modem - Check for OK response to AT
- $port.Write("AT`r")
- $a = 0
- do {
- $b = $port.ReadLine()
- switch ($a){
- 0 { if ($b -ne "AT`r`r") { throw "Modem Check AT - Response["+$a+"]:"+$b }; }
- 1 { if ($b -ne "OK`r") { throw "Modem Check AT - Response["+$a+"]:"+$b }; }
- }
- Out-File $logfile -input ("Modem Output: "+$b) -append
- $a++
- } until ($a -eq 2)
- #Modem - Check for +CREG: 0,1 response to AT+CREG?
- # 0 not registered; MS is not currently searching for a new operator
- # 1 registered; home network
- # 2 not registered; MS currently searching for a base station
- # 4 unknown
- # 5 registered; roaming
- $port.Write("AT+CREG?`r")
- $a = 0
- do {
- $b = $port.ReadLine()
- switch ($a) {
- 0 { if ($b -ne "AT+CREG?`r`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }
- 1 { if ($b -ne "+CREG: 0,1`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }
- 2 { if ($b -ne "`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }
- 3 { if ($b -ne "OK`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }
- }
- Out-File $logfile -input ("Modem Output: "+$b) -append
- $a++
- } until ($a -eq 4)
- #Modem - Check for OK response to AT+WSCL=1,2
- # Assignes English and Unicode to SMS Encoding, needed to leave Verizon Network
- $port.Write("AT+WSCL=1,2`r")
- $a = 0
- do {
- $b = $port.ReadLine()
- switch ($a){
- 0 { if ($b -ne "AT+WSCL=1,2`r`r") { throw "Modem Check AT+WSCL=1,2 - Response["+$a+"]:"+$b }; }
- 1 { if ($b -ne "OK`r") { throw "Modem Check AT+WSCL=1,2 - Response["+$a+"]:"+$b }; }
- }
- Out-File $logfile -input ("Modem Output: "+$b) -append
- $a++
- } until ($a -eq 2)
- Start-Sleep -Milliseconds 1500
- #Modem - Start Spreading the News...
- # ...I'm texting today...
- $a = 0
- do {
- $port.Write("AT+CMGS=`""+$toaddress[$a]+"`"`r")
- Start-Sleep -Milliseconds 100
- Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append
- $port.Write($msg)
- Start-Sleep -Milliseconds 100
- Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append
- $port.Write($z)
- Start-Sleep -Milliseconds 3000
- Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append
- $a++
- } until ($a -eq $toaddress.count)
- Start-Sleep -Milliseconds 5000
- Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append
- #Close the COM port
- $port.Close()
- $port = 0
- }
- catch
- {
- Out-File $logfile -input ("Error interacting with the serial device: $($_.Exception.GetType().Name) - $($_.Exception.Message)") -append
- }
- #Stop Logging
- #stop-transcript
Configuring System Center Operations Manager
- Open your SCOM Operations Console
- Under Administration, Open Notifications - Channels
- Create a new Command channel and enter your name
- Enter the location for your powershell.exe, parameters for the .ps1 script, and start-up directory.
- C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- -command "& c:\paging\bin\customsms.ps1 -AlertSource '$Data/Context/DataItem/ManagedEntityPath$\$Data/Context/DataItem/ManagedEntityDisplayName$' -AlertName '$Data/Context/DataItem/AlertName$' -AlertSeverity '$Data/Context/DataItem/Severity$l' -AlertResolution '$Data/Context/DataItem/ResolutionStateName$' -UserAddress '$Data/Recipients/To/Address/Address$' "
- c:\windows\system32\windowspowershell\v1.0
- Under Administration, Open Notifications - Subscribtions
- Create a new Subscription and assign the name you want
- Select the criteria to create the notification
- Add a new Subscriber for the powershell trigger (only one needs to be created.)
Note: There was no easy way assign an address for ever subscriber, so only one subscriber is needed to trigger the script. You can then have multiple recipents listed in the PowerShell. - Add your Command Notification Channel you created earlier
- And you're done.