Monday, May 21, 2012

Using a CDMA Modem to Send Alerts from System Center Operations Manager 2007 R2



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.SmsChannelTest10
Turns 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 PM
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
We 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.
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.


  1. #########################################################################   
  2. # Name:   
  3. #         customsms.ps1   
  4. #         Powershell SMS Texting via COM port and SCOM 2007 R2   
  5. # Rev:   
  6. #         1.0   
  7. #         1.1 fix clearing pending serial messages 2012/06/12   
  8. #         1.2 change logging from transcript to out-file 2012/06/27   
  9. #   
  10. # Date:   
  11. #         11:07 AM 2012/05/21   
  12. #   
  13. # Author:   
  14. #         Justin Bennett   
  15. #         jbennett at msjc d0t edu           
  16. #         http://justin-bennett-msjc.blogspot.com/   
  17. #   
  18. # Description:   
  19. #         This script is setup to be used by SCOM's Command Notification    
  20. #         Channel to send Alerts via SMS text messages directly using a COM   
  21. #         port. The inherent SMS function in SCOM doesn't work with our   
  22. #         CDMA modem, but this script does.   
  23. #   
  24. #         Tested on a MultiTech Modem - MTCBA-C1X-N3 using SCOM 2007 R2   
  25. #         and running Windows Server 2008 R2.   
  26. #   
  27. # References:   
  28. #         http://www.multitech.com/en_US/DOCUMENTS/Collateral/manuals/S000478D.pdf   
  29. #         http://scug.be/blogs/dieter/archive/2011/05/11/scom-setup-command-notification-channel-subscriber.aspx   
  30. #         http://social.technet.microsoft.com/Forums/en-ZA/operationsmanagerdeployment/thread/0ebfa1bc-e973-41eb-b2e5-5a847d647d49   
  31. #   
  32. # Example SCOM Command Notification Channel   
  33. #         Full patch of the command file: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe   
  34. #         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$' "   
  35. #         Startup folder for the command line: c:\windows\system32\windowspowershell\v1.0   
  36. #   
  37. # Note:   
  38. #         Execution-Policy had to be modified on our SCOM server for this to function.   
  39. #   
  40.   
  41. #Input Variables   
  42. # example .\customsms.ps1 -AlertSource "Src" -AlertName "Name" -AlertSeverity "Rainbow" -AlertResolution "1080p"   
  43. Param( [string] $AlertSource, [string] $AlertName, [string] $AlertSeverity, [string] $AlertResolution )    
  44.   
  45. #List of Addresses to send SMS text to   
  46. #                           Person1     Person2   
  47. #   [array] $toaddress = "0987654321", "7654321"   
  48.     [array] $toaddress = "0987654321""7654321"  
  49.   
  50. #Logfile   
  51. $logfile = "C:\paging\log\Customsms_"+"_"+(get-date -format yyyy-MM-dd_hh-mm-ss)+".log"  
  52.   
  53. #Special Character for CTRL-Z   
  54. $z= new-Object String(26,1)   
  55.   
  56. #Composed SMS Body   
  57. $msg = $AlertSource+"; Name: "+$AlertName+"; Severity: "+$AlertSeverity+"; Resolution: "+$AlertResolution+";`r"  
  58.   
  59.  function logprocess {   
  60.   #start-transcript -path ($logfile)   
  61.   Out-File $logfile -input ("Starting log") -append   
  62.   Out-File $logfile -input (get-date -format yyyy-MM-dd_hh:mm:ss) -append   
  63.       
  64.   Out-File $logfile -input ("Input AlertSource: "+$AlertSource)  -append   
  65.   Out-File $logfile -input ("Input AlertName: "+$AlertName)  -append   
  66.   Out-File $logfile -input ("Input AlertSeverity: "+$AlertSeverity)  -append   
  67.   Out-File $logfile -input ("Input AlertResolution: "+$AlertResolution)  -append   
  68.   Out-File $logfile -input ("toaddress: "+$toaddress)  -append   
  69.   Out-File $logfile -input ("Arg: "+$msg)  -append   
  70.      
  71. }   
  72. logprocess   
  73.   
  74. try   
  75. {   
  76.     $port = new-Object System.IO.Ports.SerialPort    
  77.     $port.PortName = "COM1"  
  78.     $port.BaudRate = 115200   
  79.     $port.Parity = "None"  
  80.     $port.DataBits = 8   
  81.     $port.StopBits = 1   
  82.     $port.Handshake = "RequestToSendXOnXOff"  
  83.     $port.ReadTimeout = 1000   
  84.            
  85.     #Wait 5 Seconds   
  86.     #Start-Sleep 5   
  87.     $port.open()   
  88.        
  89.     #clear pending messages   
  90.     $port.ReadExisting()   
  91.      
  92.     #Modem - Check for OK response to AT   
  93.     $port.Write("AT`r")   
  94.     $a = 0   
  95.     do {   
  96.         $b = $port.ReadLine()   
  97.         switch ($a){   
  98.             0 { if ($b -ne "AT`r`r") { throw "Modem Check AT - Response["+$a+"]:"+$b }; }   
  99.             1 { if ($b -ne "OK`r") { throw "Modem Check AT - Response["+$a+"]:"+$b }; }    
  100.         }   
  101.         Out-File $logfile -input ("Modem Output: "+$b)  -append   
  102.         $a++   
  103.     } until ($a -eq 2)   
  104.        
  105.     #Modem - Check for +CREG: 0,1 response to AT+CREG?   
  106.     #           0 not registered; MS is not currently searching for a new operator   
  107.     #           1 registered; home network   
  108.     #           2 not registered; MS currently searching for a base station   
  109.     #           4 unknown   
  110.     #           5 registered; roaming   
  111.     $port.Write("AT+CREG?`r")   
  112.     $a = 0   
  113.     do {   
  114.         $b = $port.ReadLine()   
  115.         switch ($a) {   
  116.             0 { if ($b -ne "AT+CREG?`r`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }    
  117.             1 { if ($b -ne "+CREG: 0,1`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }    
  118.             2 { if ($b -ne "`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }    
  119.             3 { if ($b -ne "OK`r") { throw "Modem Check AT+CREG? - Response["+$a+"]:"+$b }; }    
  120.         }   
  121.         Out-File $logfile -input ("Modem Output: "+$b) -append   
  122.         $a++   
  123.     } until ($a -eq 4)    
  124.        
  125.     #Modem - Check for OK response to AT+WSCL=1,2   
  126.     #           Assignes English and Unicode to SMS Encoding, needed to leave Verizon Network   
  127.     $port.Write("AT+WSCL=1,2`r")   
  128.     $a = 0   
  129.     do {   
  130.         $b = $port.ReadLine()   
  131.         switch ($a){   
  132.             0 { if ($b -ne "AT+WSCL=1,2`r`r") { throw "Modem Check AT+WSCL=1,2 - Response["+$a+"]:"+$b }; }   
  133.             1 { if ($b -ne "OK`r") { throw "Modem Check AT+WSCL=1,2 - Response["+$a+"]:"+$b }; }    
  134.         }   
  135.         Out-File $logfile -input ("Modem Output: "+$b) -append   
  136.         $a++   
  137.     } until ($a -eq 2)   
  138.   
  139.     Start-Sleep -Milliseconds 1500         
  140.     #Modem - Start Spreading the News...   
  141.     #           ...I'm texting today...   
  142.     $a = 0   
  143.     do {   
  144.         $port.Write("AT+CMGS=`""+$toaddress[$a]+"`"`r")   
  145.         Start-Sleep -Milliseconds 100          
  146.         Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append   
  147.         $port.Write($msg)   
  148.         Start-Sleep -Milliseconds 100   
  149.         Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append   
  150.         $port.Write($z)   
  151.         Start-Sleep -Milliseconds 3000   
  152.         Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append   
  153.         $a++   
  154.     } until ($a -eq $toaddress.count)   
  155.        
  156.     Start-Sleep -Milliseconds 5000    
  157.     Out-File $logfile -input ("Modem Output: "+($port.ReadExisting())) -append   
  158.        
  159.     #Close the COM port   
  160.     $port.Close()   
  161.     $port = 0   
  162. }   
  163.   
  164. catch   
  165. {   
  166.   
  167.     Out-File $logfile -input ("Error interacting with the serial device: $($_.Exception.GetType().Name) - $($_.Exception.Message)") -append   
  168.   
  169. }   
  170.   
  171. #Stop Logging   
  172. #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.

Let me know how this works out for you. Logging only seems to function if you manually kick off the .ps1 file. There's some more articles related to that, but I didn't bother with them.

Monday, May 14, 2012

Backup Linux using Microsoft DPM 2010

Update (2012-07-18)
Today we transitioned from Microsoft DPM 2010 to Microsoft DPM 2012. It was no problem as the structure remained the same - backing up the copied files off our linux clients from the windows host NFS volume.
-Justin

We had a conundrum on a project over winter in my department. We’d been moving toward Microsoft’s Data Protection Manager 2010 to take over all our backups for our systems, but a new system that was coming online was a Red Hat server. Data Protection Manager doesn’t have a native client that supports Red Hat to add it to a protection group, unless you buy an expensive Data Protection Manager appliance that run’s a proprietary client.http://www.evault.com/products/data-backup-software/microsoft-backup-recovery/index.html

We put our heads together and came up with a cheaper alternative that required some initial labor and ongoing overhead to verify backups. We ended up with some overelaborate scripts to suite our taste, but I’ve oversimplified it for easy reading.

First, we carved out some backup storage space on both the Red Hat server for the initial local backups and on the Data Protection Manager’s server for an NFS mirror.


Second, we added an NFS root on the Data Protection Manager’s server with the NFS mapping to a mount on the Red Hat server.
http://support.microsoft.com/?kbid=324089
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/3/html/System_Administration_Guide/s1-nfs-mount.html


Third, a bash script creates tar files on the Red Hat server that is activated via a daily cron. Once the tar files are created, we use the RSYNC to mirror the local storage backups from the Red Hat server to the Data Protection Manager’s storage via the NFS mount folder.
http://docs.redhat.com/docs/en-US/Red_Hat_Enterprise_Linux/4/html/Step_by_Step_Guide/s1-managing-compressing-archiving.html#S2-MANAGING-ARCHIVING
http://rsync.samba.org/


Forth, the Data Protection Manager Server NFS Root is added to a D.P.M. Protection Group.
http://technet.microsoft.com/en-us/library/cc161486.aspx


Lastly, we added scripts on both systems that pruned files based on our retention requirements and added log file outputs for verification and diagnostics.



It was a bit of an exercise to get this configured and learn the technologies, but I think it was well worth the learning experience to challenge ourselves, fight limitations, and save some hard costs of equipment with soft costs of labor.