NetXMS Support Forum

English Support => General Support => Topic started by: mdreher on October 16, 2017, 11:13:48 PM

Title: Monitoring Windows Scheduled Tasks
Post by: mdreher on October 16, 2017, 11:13:48 PM
Hey,

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

Thoughts? 
Title: Re: Monitoring Windows Scheduled Tasks
Post by: mdreher on October 20, 2017, 12:08:53 AM
Any thoughts?  Possibly looking at the event logs was my first thought, but wanted to see if anyone had a different idea. 
Title: Re: Monitoring Windows Scheduled Tasks
Post by: Tursiops on October 29, 2017, 11:48:54 PM
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
Title: Re: Monitoring Windows Scheduled Tasks
Post by: mdreher on October 30, 2017, 02:59:52 PM
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?
Title: Re: Monitoring Windows Scheduled Tasks
Post by: Tursiops on October 30, 2017, 11:43:41 PM
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
Title: Re: Monitoring Windows Scheduled Tasks
Post by: mdreher on November 01, 2017, 02:22:03 PM
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.