Monitoring Windows Scheduled Tasks

Started by mdreher, October 16, 2017, 11:13:48 PM

Previous topic - Next topic

mdreher

Hey,

Wondering what would be the easiest way to monitor the status of a windows scheduled task. 

Thoughts? 

mdreher

Any thoughts?  Possibly looking at the event logs was my first thought, but wanted to see if anyone had a different idea. 

Tursiops

Hi,

Use PowerShell to retrieve the status of scheduled tasks:
https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/12/use-powershell-to-show-results-of-scheduled-tasks/

You can then monitor specific (or all) tasks using ExternalParameters/ExternalLists/ExternalParametersProvider depending on your exact requirements.

Cheers

mdreher

Hmm, ok.  Completely forgot they added powershell for scheduled tasks.  I'm guessing I'd have to use netxms to call an external script then?  Or can the agent run native powershell?

Tursiops

Hi,

You can create an ExternalParameter (or ExternalParametersProvider) which can run a handful of commands or call a PowerShell script, which returns the data you are after. If you are after one very specific Scheduled Task, that may be enough. You can also implement an ExternalList, which can call PowerShell to generate a list of Scheduled Tasks you are interested in and which exist on that node, then use this with Instance Discovery to create DCIs for you (using the agent parameter created via ExternalParameter or ExternalParametersProvider).

For semi-native PowerShell, you can create an ExternalParameter that simply calls powershell -c "$1" (you can tweak that with -noninteractive, -noprofile, etc.), with $1 being the parameter passed from the DCI. We're using the above not as an ExternalParameter, but an Action, so we can run a single, arbitrary PowerShell command on Windows nodes at any time via NetXMS (and lock this object tool down to the users that we trust with that access).
This method is not suitable for running multi-line commands or scripts of course.

Cheers

mdreher

I ended up implementing the log parsing looking for event 203, scheduled task failed.  I definitely like the ideas posted here, if not for this case, then possibly for others.  I really appreciate the feedback.