1: '*** This script checks for the existence of a totalizer dump file on each Kronos WTK server, and if
2: '*** any exist, sends out an email alert.
3: '***
4: '*** M.Kizer (08/27/2008) - Created.
5:
6: Option Explicit
7:
8: '* Define Constants / Variables
9: Const BinPath = "c:\utilities\" 'Full path to this VBS script
10: Const LogsPath = "c$\kronos\wfc\logs\" 'Full path to the Kronso WTK logs directory
11: Const Dump1FileName = "wtktotal1dump.log" 'Dump file name
12: Const Dump2FileName = "wtktotal2dump.log" 'Dump file name
13: Const EmailFrom = "FromEmail@domain.com" 'Emails will be sent "from" this account
14: Const EmailTo = "ToEmail@domain.com" 'Emails will be sent "to" this account
15: Dim Item 'Used in Servername array
16: Dim Msg 'Message
17:
18: Dim CurrentDate 'Current date/time
19: CurrentDate = Now
20:
21: Dim ServerName(18)
22: ServerName(0) = "cosda256p"
23: ServerName(1) = "cosda257p"
24: ServerName(2) = "cosda259p"
25: ServerName(3) = "cosda260p"
26: ServerName(4) = "cosda261p"
27: ServerName(5) = "cosda262p"
28: ServerName(6) = "cosda263p"
29: ServerName(7) = "cosda264p"
30: ServerName(8) = "cosda265p"
31: ServerName(9) = "cosda266p"
32: ServerName(10) = "cosda267p"
33: ServerName(11) = "cosda268p"
34: ServerName(12) = "cosda270p"
35: ServerName(13) = "cosda271p"
36: ServerName(14) = "cosda272p"
37: ServerName(15) = "cosda253p"
38: ServerName(16) = "cosda254p"
39: ServerName(17) = "cosda255p"
40: ServerName(18) = "cosda269p"
41:
42: '* Create objects
43: Dim WshShell
44: Set WshShell = CreateObject("WScript.Shell")
45:
46: Dim fso
47: Set fso = CreateObject("Scripting.FileSystemObject")
48:
49: Dim objEmail
50: Set objEmail = CreateObject("CDO.Message")
51:
52: '* Create log file
53: Dim LogFile
54: Set LogFile = fso.CreateTextFile(BinPath & "TotalizerDumpCheck.log", true)
55: LogFile.WriteLine("================================================================================")
56: LogFile.WriteLine(Now & " - Kronos WTK Totalizer Dump Check - Starting...")
57: LogFile.WriteLine("================================================================================")
58:
59: '* Loop through all servers
60: For Each Item in ServerName
61: '* Check if dump file 1 exists
62: If fso.FileExists("\\" & Item & "\" & LogsPath & Dump1FileName) Then
63: Msg = Msg & "Server: " & Item & " has a crashed totalizer - see " & Dump1FileName & vbCrLf
64: End If
65: '* Check if dump file 2 exists
66: If fso.FileExists("\\" & Item & "\" & LogsPath & Dump2FileName) Then
67: Msg = Msg & "Server: " & Item & " has a crashed totalizer - see " & Dump2FileName & vbCrLf
68: End If
69: Next
70:
71: '* If dump files were found...
72: If Msg = "" Then
73: LogFile.WriteLine("No Totalizers crashed!")
74: Else
75: LogFile.WriteLine(Msg)
76: LogFile.WriteLine("*** Sending out email alert! ***")
77: '* Send out email
78: objEmail.From = EmailFrom
79: objEmail.To = EmailTo
80: objEmail.Subject = "Kronos WTK Production - Totalizer Crash Alert"
81: objEmail.Textbody = Msg
82: objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
83: objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "your SMTP mail server here"
84: objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
85: objEmail.Configuration.Fields.Update
86: objEmail.Send
87: End If
88:
89: LogFile.WriteLine("================================================================================")
90: LogFile.WriteLine(Now & " - Kronos WTK Totalizer Dump Check - Completed.")
91: LogFile.WriteLine("================================================================================")
92: LogFile.WriteBlankLines 1
93:
94: '* Close log file
95: LogFile.Close
96:
97: '* Destroy objects
98: Set WshShell = Nothing
99: Set fso = Nothing
100: Set LogFile = Nothing
101: Set objEmail = Nothing
102:
103: '***** End of main script *****
Once I had this program up and running successfully, I staged it on one of the 19 servers for this system and scheduled it to run every 15 minutes during most of the day using Windows Task Scheduler. For the ToEmail address I used a mailing list address so that anyone that wishes to be informed about these alerts can simply subscribe to mailing list. You can even subscribe multiple email addresses to the mailing list, like your cell phone's text message email address for example. By using a mailing list instead of hard coded email addresses, I will never have to update this program to add or remove people from the distribution. If you don't have in-house mailing lists available, a great option is Google Groups (which is what I used). Their response time on populating emails out to the group members is usually very quick. Plus their features and web interface for the mailing list makes it very easy to set one up and maintain it.
Hopefully this article spurs some ideas for automation that will make your life a bit easier. If you come up with any creative ways of using this example, tell me about it in the comments.