Page 1 of 1

Monitoring Windows 2008 Scheduled Tasks

Posted: Wed Jul 10, 2013 9:28 am
by WillemDH
Hello,

I've had a really hard time today trying to monitor WIndows 2008 scheduled tasks. Is there anyone here who got some experience with this?
I've been looking on http://www.nsclient.org/nscp/wiki/Check ... _tasksched for more information, but it seems like there is some infor missing.

nsclient.ini:

[/modules]
CheckTaskSched1 = 1
CheckTaskSched2 = 1

[root@srvnagios01 ~]# /usr/local/nagios/libexec/check_nrpe -H testserver -t 30 -c CheckTaskSched -p 5666 -a "filter=exit_code ne 0" "syntax=%title%: %exit_code%" warn=\>0
OK: All scheduled tasks are good.|'eventlog'=0;0;0

While there is at least one scheduled task that hasn't got a status code of 0.
i thought the problem could be that I use the checktasksched1 or so, but

/usr/local/nagios/libexec/check_nrpe -H testserver -t 30 -c CheckTaskSched2 -p 5666 -a "filter=exit_code ne 0" "syntax=%title%: %exit_code%" warn=\>0
No handler for command: checktasksched2

So he doesn't seem to know checktasksched2..

Any help is welcome..

Re: Monitoring Windows 2008 Scheduled Tasks

Posted: Wed Jul 10, 2013 9:51 am
by lmiltchev
Can you post the whole "nsclient.ini" file (hide the sensitive info)?

Re: Monitoring Windows 2008 Scheduled Tasks

Posted: Thu Jul 18, 2013 3:52 am
by WillemDH
Hello,

We solved this problem bij creating a powershell script that outputs it's result to Nagios. Works much better then the checktasksched2 in the nscp software.

For people who are interested, this is the powershell script:

Code: Select all

 

#Scheduled Task Result powershell script

$status = 0;

#First, the script will pull a list of all the scheduled tasks on your computer and push it into a CSV file.
schtasks /query /fo csv -v | ConvertFrom-Csv | ? {$_.HostName -match "^$($Env:Computername)$" -and $_.'Scheduled Task State' -eq "Enabled" -and $_.TaskName -notlike '\Microsoft*' } | % {
	if ($_."Last Result" -ne "0") {
		echo "Scheduled task $($_.TaskName) exited with result $($_.'Last Result')"
		$status = 2
	}
}

if ($status -eq 0) {
	echo "All OK"
}
exit $status


Re: Monitoring Windows 2008 Scheduled Tasks

Posted: Thu Jul 18, 2013 9:34 am
by yancy
WilliemDH,

Thanks for posting your Powershell script.

It would be a useful addition to exchange.nagios.org if you have a chance to post it there.

Thanks,

-Yancy

Re: Monitoring Windows 2008 Scheduled Tasks

Posted: Fri Jul 19, 2013 6:25 am
by WillemDH
Posted on Exchange. Waiting for approval.

Re: Monitoring Windows 2008 Scheduled Tasks

Posted: Fri Jul 19, 2013 9:10 am
by scottwilkerson
Thanks!