Mar
01
How to create simple alerts if a windows service fails
As we all know, it seems like everyone but the admin knows when your server is down. The reason this happens is because one service failed but it wasn’t an important enough event to set off any of your high level alerts. Using very simple VBS and a batch file, we can setup very simple low level alerts for individual services if they fail.
First we start with the VBS using notepad create a VBS file called: MyServiceAlert.VBS and save it to c:\Alerts, then paste in the below info modifying the highlighted text:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Set objMessage = CreateObject(“CDO.Message”)
objMessage.Subject = “Service Alert for <serverName>“
objMessage.From = “alerts@mydomain.com“
objMessage.To = “helpdesk@mydomain.com; level2support@mydomain.com“
objMessage.TextBody = “The XXXXXX service has failed after one attempt to restart. Server IP: xxx.xxx.xxx.xxx“
’2 = SMTP
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
‘Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “<addressOfYourSMTPserver>“
‘Server port (typically 25)
objMessage.Configuration.Fields.Item _
(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
objMessage.Configuration.Fields.Update
‘==End remote SMTP server configuration section==
objMessage.Send
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Next create a very simple batch file that will call the .VBS file
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@echo off
Start C:\Alerts\MyServiceAlert.VBS
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Now just find the service that you want to set up the alert for click on the Recovery tab and setup your Service Failure responses. Make sure that you select the “Enable actions for stops with errors.” Box.






























