none
Service failure automation script

    General discussion

  • Hi All,

    I have configured the below mentioned code on our prod servers services to send email notifications when ever a service fails. 

    On Error Resume Next

    strComputer = "USDFW16AS61"

    Const cdoSendUsingPickup = 1
    Const cdoSendUsingPort = 2

    'Function block to dynamically retrieve the file size of the report file.
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    'Authentication type used for SMTP server.
    'We are currently using 0, cdoAnonymous
    Const cdoAnonymous = 0 'Do not authenticate
    Const cdoBasic = 1 'basic (clear-text) authentication
    Const cdoNTLM = 2 'NTLM

    'Creates message subject, we are using variables declared earlier in the script
    Set objMessage = CreateObject("CDO.Message")
    objMessage.Subject = "CMS Production service iwutild is stopped"
    'Sets the From address
    objMessage.From = """Support DL"SupportDL@example.com
    'Sets the destination, or TO address
    objMessage.To = adminDL@example.com
    'Sets the CC address. Only used for testing purpose at the moment. Should be commented out when in use.
    'objMessage.CC = ""
    'Sets the message body, the actual email message. Variables are used in the message which was declared earlier.
    objMessage.TextBody = "Dear Administrators, the xyz service is now in STOPPED state." & vbCRLF & vbCRLF & "Please do not reply to this message as it was sent to you by an automated Script."& vbCRLF & vbCRLF & "Thanks and regards"
    'objMessage.TextBody = "Dear Application Administrators,"  & vbCRLF & ""& vbCRLF & ""& vbCRLF &

    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") = "servername"

    'Type of authentication, NONE, Basic (Base64 encoded), NTLM
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoAnonymous

    'Your UserID on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendusername") = ""

    'Your password on the SMTP server
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = ""

    'Server port (typically 25)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

    'Use SSL for the connection (False or True)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False

    'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
    objMessage.Configuration.Fields.Item _
    ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

    objMessage.Configuration.Fields.Update

    '==End remote SMTP server configuration section==
    'Sends the message using code.
    objMessage.Send

    This script is able to send notification only for the respective service that I have configured it to Run upon failure.

    My requirement now is that the script should be able to detect out of the 6 app services that are down & should append the email body with the name of that service & send an email.

    I understand Wscript.argument(0) can be of use but not able to use it. Could you kindly help?

    Thanks,

    Pankaj

    P.S: I am not a developer, so kindly bear with me :)


    Pankaj Dhoot

    Tuesday, April 15, 2014 5:25 AM

All replies