Friday, August 22, 2008

My First VB Script

As I am typing this blog, I am working on a monitoring script to ensure the Oracle services are up and running. I think I need to pick up a book to understand more about scripting in Windows environment.

Option Explicit
Dim objWMIService
Dim allServices
Dim s
Dim objProcess
dim objShell
Dim Mesg
Dim Command
Dim objEnv
Dim Subject


Set objShell = Wscript.CreateObject ("Wscript.shell")
Set ObjEnv =objShell.Environment("Process")
Set allServices = GetObject("winmgmts:").ExecQuery _
("SELECT * FROM Win32_Service")


For Each s in allServices
If s.Name = "OracleMTSRecoveryService" and s.State = "Stopped" Then
        Mesg = s.Name + " is down, "
End If
If s.Name = "OracleORACLEAgent" and s.State = "Stopped" Then
        Mesg = s.Name + " is down, "
End If
If s.Name = "OracleORACLEHTTPServer" and s.State = "Stopped" Then
        Mesg = s.Name + " is down, "
End If
If s.Name = "OracleORACLETNSListener" and s.State = "Stopped" Then
        Mesg = s.Name + " is down, "
End If
If s.Name = "OracleServiceLIVE" and s.State = "Stopped" Then
        Mesg = s.Name + " is down, "
End If
Next


Subject = "Oracle is down"
If Mesg = "" Then
        'Wscript.echo "Do nothing"
Else
        Command =  "C"\Scripts\postie -host:smtphost -to:someone@somewhere.com "
        Command = Command + "-from:" + ObjEnv("COMPUTERNAME") + " "
        Command = Command + "-s:" + chr(34) + Subject + chr(34) + " "
        Command = Command + "-msg:" + chr(34) + Mesg + chr(34)
        objShell.run Command
End If

Plenty of room for improvement to the above script. I hope to be able to drive the service monitoring via a input file so that the VB script does not have to be modified.

Labels:

0 Comments:

Post a Comment

<< Home