I know this is a silly question, but I'm just having trouble wrapping my head around creating a custom script.
I have created a script that monitors scheduled tasks on a box, and can return it's last run status. (0, 1, 2, 3 depending). It can also output some text showing info about it.
I don't quite get how to setup the script on the uptime server side. I want to pass in the scheduled task name to check for, and get back a simple status code. (Later I'll worry about adding in info like next run time, last run time, etc) How do I actually call my script?
Both the monitoring and the monitored servers are windows
':: * CheckSched.vbs
':: * Monitor all “scheduled tasks” from a single machine
':: * Returns success status and last run time.
':: * by Jonathan Best
':: * INPUTS: the name of the scheduled task. In 7/2008 the name is the foldername+task name.
':: * for example, MicrosoftWindowsAutochkProxy
':: * OUTPUTS: 0 for OK, 1 for WARNING, 2 for CRITICAL, 3 for UNKNOWN
'Make sure we're passing through some command line arguemnts
If WScript.Arguments.Count = 0 Then
WScript.echo(“No command lines passed”)
ArrayCounter = 0
Set Dict = CreateObject(“Scripting.Dictionary”)
'Build the command.
TSKcmd = “Schtasks /query /V /FO CSV “
'Create the shell
set objShell = createobject(“WScript.shell”)
'Run the command.
set TASKlines = objShell.exec(“%ComSpec% /c ” & TSKcmd )
'Break into an array
arrayTasks = Split(TASKlines.StdOut.readall, vbNewLine)
Arraysize = UBOUND(arrayTasks)
for each TASKline in arrayTasks
'If the line starts with “HOSTNAME” than do nothing. This removes the column headers
IF LCase(mid(TASKline,2,8)) = “hostname” THEN
ELSE ' Column headers are gone. Now we have to play with the data.
'WScript.echo “ArrayCounter “& ArrayCounter
'Strip out the double quotes
TASKline = Replace(TASKline,””””,””)
'WScript.echo “TASKline = ” & TASKline
IF TASKline = “” THEN
'add to the dictionary
temparray = Split(TASKline,”,”)
If Dict.Exists(temparray(1)) then
'do nothing, this is a repeat key. This happens due to each schedule or trigger for a task causes
'it to show up in the list again.
Dict.Add temparray(1), Split(TASKline,”,”)
'ok, we have all the info we need to do the lookup.
ArrayCounter = Arraycounter + 1
'Take the command line arguments and do stuff with it.
'There should only be one argument
'Lets return the selected scheduled task
WScript.echo (“Selected Task Name: “) & Dict.Item(WScript.Arguments(0))(1)
WScript.echo (“Selected Task Status: “) & Dict.Item(WScript.Arguments(0))(3)
WScript.echo (“Selected Task Last Run Time: “) & Dict.Item(WScript.Arguments(0))(5)
WScript.echo (“Selected Task Last Result: “) & Dict.Item(WScript.Arguments(0))(6)
'lets close out what we used
'Lets send our reply back to uptime
'If Selected Task Last Result is a 1, send back a critical status.
'If Selected Task Last Result is a 0, send back a OK status.
'If Selected Task Last Result is a N/A, send back a OK status (We can add in other checks like if
'next run is in the next 15 minutes or so, do something, else send back an unknown. For now, this.
'If Selected Task Last Result is anything else, send back a UNKNOWN status.
IF Dict.Item(WScript.Arguments(0))(6) = “1” THEN
ELSEIF Dict.Item(WScript.Arguments(0))(6) = “0” THEN
ELSEIF Dict.Item(WScript.Arguments(0))(6) = “N/A” THEN