Module: check_mk
Branch: master
Commit: 076840cfe3cd949483d99e93bc43c386cf988092
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=076840cfe3cd94…
Author: Bastian Kuhn <bk(a)mathias-kettner.de>
Date: Fri Oct 18 11:53:30 2013 +0200
windows_tasks: New Check to monitor the Windows Task Scheduler
---
ChangeLog | 1 +
agents/windows/plugins/windows_tasks.ps1 | 2 +
checkman/windows_tasks | 13 ++++++
checks/windows_tasks | 74 ++++++++++++++++++++++++++++++
4 files changed, 90 insertions(+)
diff --git a/ChangeLog b/ChangeLog
index e01e70b..274725a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2297,6 +2297,7 @@
mount points). No external plugin is needed.
* Windows agent: new section <<<fileinfo>>> for monitoring file
sizes
(and later possible ages)
+ * windows_tasks: New Check to monitor the Windows Task Scheduler
* logwatch: allow to classify messages based on their count (see
man page of logwatch for details)
* fileinfo: new check for monitoring age and size of files
diff --git a/agents/windows/plugins/windows_tasks.ps1
b/agents/windows/plugins/windows_tasks.ps1
new file mode 100644
index 0000000..4c6420b
--- /dev/null
+++ b/agents/windows/plugins/windows_tasks.ps1
@@ -0,0 +1,2 @@
+echo "<<<windows_tasks:sep(58)>>>"
+schtasks /query /fo csv -v | ConvertFrom-Csv | ? {$_.HostName -match
"^$($Env:Computername)$" -and $_.TaskName -notlike '\Microsoft*' -and
$_.TaskName -notlike '*zachteHRM*'} | fl taskname,"last run
time","next run time","last result","scheduled task
state"
\ No newline at end of file
diff --git a/checkman/windows_tasks b/checkman/windows_tasks
new file mode 100644
index 0000000..74a8b35
--- /dev/null
+++ b/checkman/windows_tasks
@@ -0,0 +1,13 @@
+title: Check Windows Task Scheduler
+agents: windows
+catalog: os/misc
+license: GPL
+distribution: check_mk
+description:
+ The Windows Task Scheduler Checks controlls the last return state of windows task
scripts.
+ The check goes to {WARNING} state, if the task is disabled. If the Script from the Task
returns
+ another return code as 0, the Check goes {CRITICAL}.
+ In order to run, its needed to copy the windows_tasks.ps1 script to the plugin folder of
the agent.
+
+inventory:
+ One service will be created for each enabled task
diff --git a/checks/windows_tasks b/checks/windows_tasks
new file mode 100644
index 0000000..a7cd6a9
--- /dev/null
+++ b/checks/windows_tasks
@@ -0,0 +1,74 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2013 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# ails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+# Example output from agent:
+
+def windows_tasks_convert(info):
+ data = {}
+ last_task = False
+ for line in info:
+ name = line[0].strip()
+ value = "".join(line[1:]).strip()
+ if last_task and name != "TaskName":
+ data[last_task][name] = value
+
+ if name == 'TaskName':
+ last_task = value
+ data[last_task] = {}
+ return data
+
+def inventory_windows_tasks(info):
+ info = windows_tasks_convert(info)
+ return [ (n, None) for n, v in info.items() if v['Scheduled Task State'] ==
"Enabled"]
+
+def check_windows_tasks(item, _no_params, info):
+ info = windows_tasks_convert(info)
+ for name, values in info.items():
+ if name == item:
+ last_result = saveint(values['Last Result'])
+ state = 0
+ label = ""
+ msg = []
+ if last_result != 0:
+ state = 2
+ label = "(!!)"
+ msg.append("Service in state: %s%s" % ( last_result, label ) )
+
+ if values['Scheduled Task State'] != 'Enabled':
+ msg.append("Task not Enabled(!)")
+ state = max(state,1)
+
+ return state, ", ".join(msg)
+
+ return 3, "Task not found on server"
+
+check_info["windows_tasks"] = {
+ "check_function" : check_windows_tasks,
+ "inventory_function" : inventory_windows_tasks,
+ "service_description" : "Task %s",
+ "has_perfdata" : False,
+}
+