02. 07. 2024 Juergen Vigna NetEye

Monitor the Tasks in the Windows Task Scheduler

A lot of people run regular tasks on their Windows Servers using the Windows Task Scheduler. Now it’s time to find out if these tasks run on time, within a limit, and complete successfully.

This monitoring task is done over nscp.exe, so you should have NSClient++ installed along with your Icinga2 Agent. Take a look at the NSClient++ CheckTaskSched documentation for all the details which you can find here.

Using this you can monitor various aspects of a task – for this blog post I’ll assume that I have to monitor a task which should run regularly at some predefined interval, I have to check that the task runs successfully, and that it has run within the defined interval at least once. To do so we check that the exit_status of the task is 0 (No Error) and that the last_run_time is not farther back in time then the running interval. Let’s assume that the interval is 1 minute and the name of the task is “alyvix_check_service” (as running on Alyvix Server Nodes). The command we would have to execute from a CMD is the following (you can test this directly on a CMD):

"C:\Program Files\NSClient++\nscp.exe" client --log critical --module CheckTaskSched --show-all -a "filter=title like 'alyvix_check_service'" -a "critical=(most_recent_run_time < -90s) or (exit_code < 0)" -a empty-state=critical -a "empty-syntax=CRITICAL: Task 'alyvix_check_service' NOT found" -a "detail-syntax=%(title) (%(most_recent_run_time) UTC) [exit_code:%(exit_code)] [statuts:%(task_status)]" -b -q check_tasksched

Now that we know what command we have to launch to check our task, we can make the Icinga Director part and create a Service Template and a Service on our Host. The Service Template should be an Agent Check, including the variables defined by the nscp-local command already present, as an imported command (should be at least NSCP Module and NSCP query).

I then define another string variable “win_task_name” so that you don’t have to change every instance of the check every time (you have to create all the NSCP Arguments somehow if you want to use the same logic), just the name of the task. Note that I use “like” in the filter for the Task-Name so it searches for the task as “Substring” (like a RegEx with .* before and after the string). When you’re done it should look like this:

The last step is to add a Service Instance of this Template to the Host to check for the running task.

And then you’ll get something like this as result:

And with this you are able to add monitoring for all the Windows Task Scheduler(s) you want. To get you running quickly with this, you can download a Director Basket File for the Service Template to use from here.

Juergen Vigna

Juergen Vigna

NetEye Solution Architect at Würth Phoenix
I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

Author

Juergen Vigna

I have over 20 years of experience in the IT branch. After first experiences in the field of software development for public transport companies, I finally decided to join the young and growing team of Würth Phoenix. Initially, I was responsible for the internal Linux/Unix infrastructure and the management of CVS software. Afterwards, my main challenge was to establish the meanwhile well-known IT System Management Solution WÜRTHPHOENIX NetEye. As a Product Manager I started building NetEye from scratch, analyzing existing open source models, extending and finally joining them into one single powerful solution. After that, my job turned into a passion: Constant developments, customer installations and support became a matter of personal. Today I use my knowledge as a NetEye Senior Consultant as well as NetEye Solution Architect at Würth Phoenix.

Leave a Reply

Your email address will not be published. Required fields are marked *

Archive