Raphael Burri's blog

Mostly about Systemcenter Operations Manager 2012

Windows Scheduled Tasks Management Pack for OpsMgr 2007

Posted by rburri on February, 14 2008

August 12, 2014 – link to latest update: https://rburri.wordpress.com/2014/08/12/scheduled-task…pack-1-2-0-500/

Post last updated on July,1st 2009

Summary

For Windows Server 2003 and 2008.

I created a management pack, which discovers scheduled tasks and monitors them for successful execution as well as if they have a working schedule configured. On Windows 2003, the output of the schtasks.exe command is parsed. On Windows 2008 however; the Task Scheduler 2.0 library is used.

The object type ‘Windows Scheduled Task’ can be used in Distibuted Applications or to further categorize scheduled tasks by writing other management packs.

Features
Discovery:
  • Scheduled Tasks and AT tasks on Windows 2003 and 2008 Server
  • Server 2008 supports any OS language. On Server 2003 the following:
English, Dutch, German, French, Italian, Portuguese and Spanish
Monitors:
  • Last exit code
  • Invalid status (anything not 'Running' or NUL)
  • Next run definition available
  • Long running task (requires configuration)
  • Next scheduled execution skipped (task ran too long)
  • No active triggers defined (Windows 2008 only)
Rule:
  • Collect Scheduled Task job duration (if task runs > 1 minute)
Tasks:
  • Disable Scheduled Task
  • Enable Scheduled Task
  • Run Scheduled Task
  • End Scheduled Task
  • List all Scheduled Tasks
View:
  • Scheduled Task state
Scheduled Task Screen Shot

Scheduled Task Screen Shot

 

Download
Upgrade Compatibility

Due to the significant changes required to get Windows 2008 tasks managed and to incorporate language support for Windows 2003, this version of the MP is not upgrade compatible with the previous ones. Should you have been using the Windows 2003 management pack (Version 1.1.0.20 and below), you need to remove the old one before importing the 1.1.1.0 ones. My apologies for that.

42 Responses to “Windows Scheduled Tasks Management Pack for OpsMgr 2007”

  1. rburri said

    Update
    I just learnt that Maarten Goet of Inovativ has published a very similar management pack a few days ago.

    http://www.inovativ.nl/pagina/downloads

    The main differences are that Maarten’s MP is introducing an additional object type ‘Scheduler’ (if I understand correctly those are essentially Windows computers with Scheduled Tasks configured) and that he’s decided to look at the ‘Last Run’ property instead of the ‘Next Run’. Also Maarten’s features cool icons for diagram views. It’ll be up to you to decide which one you find more helpful.

  2. StuR said

    Several of us have created similar MP’s. The problem with the approach that has to be taken (parsing the output of the little schedtask executable) is that the output isn’t consistent between desktop and server versions of the tool. Also, this approach only works for the new Scheduled Task interface, and not the original AT interface. This whole approach wouldn’t have even been necessary had MS included WMI support for the newer scheduled task method (as they promised about 5 years ago).

  3. rburri said

    You are absolutely right. It should not be required to write command output parsers when looking at core OS elements.
    Btw: I am pretty sure that international versions could lead to problems as well (luckily I do not have to look at anything other than US-English).

  4. Jon said

    Is it possible to override and not monitor a scheduled task by name; for example, discover all the scheduled tasks, but there may be a task with the same name across numerous monitored systems that you do not want to monitor or you want to say it is successful based on different return codes than the standard ‘0’; ie if 1 or 0 for just this 1 tasks across numerous server.

  5. rburri said

    Absolutely. You can either configure an override for every single task or keep it dynamic by first creating a group based on the tasks’ names and then configure the override with the different return code against that group.
    If you want to disable monitoring of these tasks completely, just make sure you override all the monitors to ‘disabled’ in context of the group.

  6. […] Il y a quelques années, un pack avait été développé pour Operations Manager 2005. La même initiative vient d’être prise pour Operations Manager 2007. C’est sans garantie, aucune, mais disponible depuis l’emplacement suivant : https://rburri.wordpress.com/2008/02/14/windows-scheduled-tasks-management-pack-for-opsmgr-2007/ […]

  7. John Bradshaw said

    Thank you!! Excellent work.

  8. […] Operations Manager agent’larındaki zamanlanmış görevleri inceleyebileceğiniz bir Management Pack, oldukça başarılı – Windows Scheduled Tasks Management Pack […]

  9. Lovro said

    first of all – great work !

    I have a little question, why is SCOM showing in the Scheduled task state view in columns Next Run and Last Run, only HasDate? Is there a way to show actually date of next run, or last run ?

    Tnx in advance!

    • rburri said

      Unfortunately not. The MP deliberatly doesn’t display the actual dates as this would lead to a property update every time a task ran. The load on SCOM due to these updates could potentally be rather high – especially in a configuration with many, frequently running tasks. This is why I decided to take the detailed datetime information out and go for a simple, static value which is sufficient to drive the monitors (next run defined).
      Not to discover dynamic properties should be considered a best practice when authoring management packs.

      Raphael

      • Lovro said

        Yes, now when you explained me it really makes sense.

        Thank you for your reply, and again, this MP saved me a lot of work🙂.

        Bye

  10. Mark said

    I’ve added the newest version of this management pack successfully, and shortly thereafter, I received the following alert from a number of 2003 servers:
    —————————–
    Alert: Script or Executable Failed to run Priority: 1 Severity: 1 Resolution state: New

    Alert description: The process started at 10:15:16 AM failed to create System.Discovery.Data. Errors found in output:

    C:\Program Files\System Center Operations Manager 2007\Health Service State\Monitoring Host Temporary Files 80\2007\Custom.Windows.ScheduledTask.ServiceDiscovery.vbs(254, 7) Microsoft VBScript runtime error: Subscript out of range: ‘-1’
    Command executed: “C:\WINDOWS\system32\cscript.exe” /nologo “Custom.Windows.ScheduledTask.ServiceDiscovery.vbs” {90CEFAC6-EC4C-2BDA-8423-71F1543577AB} {81D4E91C-46A3-7338-E026-8DCFEF346503} FQDN.SERVERNAME.DOMAIN ENGLISH
    Working Directory: C:\Program Files\System Center Operations Manager 2007\Health Service State\Monitoring Host Temporary Files 80\2007\

    One or more workflows were affected by this.

    Workflow name: Custom.Windows.ScheduledTask.DiscoverByScript

    Instance name: Microsoft(R) Windows(R) Server 2003, Enterprise Edition

    Instance ID: {81D4E91C-46A3-7338-E026-8DCFEF346503}

    ———————————-
    Any idea what this means?

  11. Steve said

    it appears that the MP is written to give a warning alert if the scheduled job fails? I was looking for a way to change that through an override to Critical. Every time I change the alert severity the changed value ends up being “Error”. What am I doing wrong?

    • rburri said

      Steve
      It isn’t possible to change the Health State for a monitor’s condition using overrides. In Health Explorer and on a State View, the scheduled task will go to warning (yellow) if it failed to run. In order to change that you’d have to unseal the MP, alter the logic and reseal it.
      You can however change the severity of the alert generated when the monitor state changes to warning. You’ll need to override the property ‘Alert Severity’ which is by default set to ‘Match the monitor’s health’. If you change that to ‘Critical’, your alert will be red.
      Note that this will only affect alerts being generated after the change. It doesn’t alter the ones already in the console.
      Hope this helps,
      Raphael

  12. Hendrik said

    Does the MP run on Windows Server 2008 R2?

    • rburri said

      Unfortunately I haven’t yet been able to test the MP on 2008 R2 but there is a good chance that it will run as I haven’t yet become aware of major changes regarding Task Scheduler. If you can run some test in a lab and experience issues: Contact me via email at raburri [at] bluewin [dot] ch

  13. John Bradsahw said

    Hi Raphael,
    Hope all is well.
    Just noticed when looking at Last Result Successful Monitor that it says in the Knowledge: “Anything other than ‘0’ is considered a warning condition for an enabled scheduled task.”
    I was wondering if “1” should also be considered a success?
    Thankyou,
    John Bradshaw

    • rburri said

      Hi John
      On Windows Server 2003 ‘Last Result’ reflects the return code of the application which was executed by the scheduled task. As most applications return zero if everything went fine I decided to implement it like that. Having said that, it is up to a programmer to implement exit codes when coding. Hence you’ll find here might be situations where a ‘1’ or indeed any other value is fine as well (imagine an application let you know how many files had been copied by its exit code).
      And while it is possible to override the behaviour of the monitor it isn’t an option to alter the knowledge entry dynamically.
      On Windows Server 2008 the ‘Last Result’ handling is slightly different by the way as Task Scheduler internals are mixed with the application exit code.

  14. Scott said

    Hi Raphael,
    I only have one or two machines that I’d like to monitor with this pack. Can I modify the discovery settings so that it doesn’t go out and discover every scheduled job on every server?

    Thanks,
    Scott…

    • rburri said

      Scott,

      Sure, that is absolutely possible. You’ll need to follow 3 steps:
      1. Disable the discovery for all servers, using an override
      2. Remove the already discovered objects from SCOM’s repository (this is required because the MP will start disocvering all Scheduled Tasks immediately after importing it).
      3. Re-enable the discovery for the servers you need to be monitored using overrides.

      Detailed instructions: Go to the Authoring pane, select discoveries. Then set the scope to Scheduled Tasks. You should then see the discoveries as they are described in the MP guide. One is for Windows 2003 and the other one for Windows 2008. Right click them and choose to override for all Windows Server 2003 respectively Server 2008 objects. Deselect the ‘enable’ box and save that override off to an MP of your choice (make sure it isn’t the ‘default MP’).

      Next you will want to remove the scheduled tasks that have already been discovered from SCOM’s repository. To do so start the SCOM Command Console and run the commandlet ‘Remove-DisabledMonitoringObject‘.

      No scheduled tasks should remain in SCOM’s repository now and you can repeat the override procedure to re-enable discovery for groups of computers or individual computers.

      Raphael

  15. Scott said

    Thanks for the quick response Raphael. I was hoping you wouldn’t mention the remove-disabledmonitoringobject script. This hasn’t run correctly for us in months. It keeps timing out and fails to cleanout any of the disabled objects. So we’ve resorted to altering the discovery rules for a given MP, then completely removing the agent and redploying it on applicable machines in order to flush discovered settings. Obviously, this doesn’t bode well when a core-OS component is potentially discovered.

    Any chance of delaying initial discovery to give us time for greater deployment control? Or possibly having discovery disabled by default, and then allowing us to override/enable it when we’re ready to target it?

    • rburri said

      Scott,

      When using the sealed MP you’ll not succeed in delaying the disocvery successfully. Even when you prepare the override MP on a lab machine and then import them all together, some unwanted instances might be discovered due to timing.

      May I suggest you convert the sealed MPs to XML and change the discovery rule from ‘enabled’ to ‘disabled’? Let me know if you’re having issues with that.

      Side note: If I started with the MP today, I’d ship it with the discovery rules ‘disabled’ and adding a ‘quick start override’ MP for folks who want it to run immediately. I’ve done so with the ‘PKI Certificate Validation’ MP and that seems to be an ideal compromise between configuration requirements for novice users and MP footprint.

      Raphael

  16. Scott said

    Yep, I agree with that methodology. I seem to recall reading somewhere that Microsoft is going to start taking this approach with more of their MP’s. i.e. disabling discovery by default so there’s not such a huge potential impact when a pack is first imported, and allowing for a more selective deployment.

    If I convert to xml, are there applicable discovery rules in all three MP’s, or only in the primary MP?

    • rburri said

      In order to completely stop discovering any objects, you’ll need to disable the following rules:
      – Custom.TaskScheduler2.Task.DiscoverByScript (in Windows2008.Monitoring)
      – Custom.Microsoft.Windows.ScheduledTask.Server.2003.OperatingSystem.DiscoverByScript (in Windows2003.Monitoring)
      – Custom.Windows.ScheduledTask.DiscoverByScript (in Windows2003.Monitoring)
      No need to alter (and unseal) the library MP.

  17. Scott said

    In case anyone else wants to try converting these packs to XML in order to control deployment, here’s some notes:

    – You only need to convert the os-specific packs, not the library pack.
    – When importing, you must select the two OS XML packs, and the “.mp” library pack since there’s a dependency on that pack.
    – Once imported, you can go to the authoring console/object discovery and search for “task” and you’ll see the discovery tasks in a disabled state. You can override each of these and enable them for a specific group, or a specific windows machine.
    – Note that if you are overriding for a specific machine, you must enable the “Windows OS Language Discovery (Windows 2003)” discovery first and allow it to discover the targeted machine before you can enable objects in the “Windows Scheduled Task Discovery (Windows 2003)” discovery rule. (The latter will be blank until the first objects are discovered).

    Many thanks to Raphael for building this pack.

  18. Scott said

    Ugh. Went through all the trouble to import and customize this pack in order to monitor scheduled jobs that are created by the NTbackup utility, only to find out that there’s a but with NTbackup relating to exit code processing.

    http://support.microsoft.com/kb/260327

    So this pack shows the jobs as successful with a 0 exit code, yet there are event log errors for these jobs indicating that the job had warnings and failed to complete successfully.

    Anyone encounter this situation or have a recommended work around? I guess I’ll have to create event ID monitors and look for the NTbackup failure event, but that’s exactly what I was trying to avoid by using this pack.

    • rburri said

      Sorry for all the trouble. Had you mentioned what kind of scheduled task you needed to monitor I could have told you that you needed a different approach. Here’s what I did in the past
      – Create an event log monitor which is looking for failure events “8019, Warning or Error” in the application log by ntbackup.exe
      – or: create a missing event rule looking for the success event “8019, Information” within a given timeframe
      The second is what I usually did. Works nicely because it will throw an alert even when the backup job didn’t run at all. It is a bit peculiar that ntbackup.exe writes the same event code (8019) at the end and one has to distinguish them only by their sevrity.

  19. Scott said

    Thanks for the suggestion Raphael. It’s not a total loss because we have a couple other jobs on this box we need to monitor.

    So I created the 8019 failure rule, however, can’t I still rely on your pack to notify me about the job not running at all instead of creating the missing event rule?

    • rburri said

      Scott
      It will if the scheduled job itself has an issue (e.g. expired user account, run out schedule or optionally if it ran too long). It won’t if an operator removes or disables the task. That’s exactly what we wanted to be able to detect and finally came up with the idea of the missing event rule.

  20. Scott said

    I apologize for tying up the thread with this discussion. Further challenge to the missing event rule approach is that we have multiple backup jobs that run each night on the same server. (They run at different times because the dependent applications they are trying to backup have timing dependencies). Because the event log entries don’t indicate the job name, there’s no way to identify which of the 5 nightly jobs failed to run. I suppose I could try to get a total count of missing events, but that gets pretty ugly.

    I’m starting to think I should just tell them to purchase backup exec.

  21. Ryan said

    Just curious why the intervals on a lot of these rules/monitors are set so low?

    • rburri said

      Good question: This was a compromise to assure that the monitors trigger within a reasonable time after a schooled task ended. With the detailed log that has been introduced with Windows 2008, most of this could be done with event monitors rather than on schedules.
      Raphael

  22. Raphael,

    I have some 2008 servers with the following error:

    The process started at 1:33:17 AM failed to create System.Discovery.Data. Errors found in output:

    C:\Program Files\System Center Operations Manager\Agent\Health Service State\Monitoring Host Temporary Files 102722\28934\Custom.Windows.ScheduledTask.ServiceDiscovery.vbs(143, 3) Microsoft VBScript runtime error: Subscript out of range: ‘[number: 0]’

    Command executed: “C:\Windows\system32\cscript.exe” /nologo “Custom.Windows.ScheduledTask.ServiceDiscovery.vbs” {xy} {xy} servername ENGLISH
    Working Directory: C:\Program Files\System Center Operations Manager\Agent\Health Service State\Monitoring Host Temporary Files 102722\28934\

    Can you help with this?

    Kind regards,
    Natascia

    • rburri said

      Hi Natascia
      Actually that script should not be running on Windows Server 2008 machines. It is part of the 2003 task scheduler MP. Could it be that you have upgraded the server (same hostname) and that SCOM still has references to Windows 2003 OS on those computers?
      If this is the case you could delete the affected agent from SCOM, let some time pass to allow grooming to clean it out of the DB and then re-adding the agent so that it gets discovered with Server 2008 objects only.
      Raphael

      • Hi Raphael,

        You are right. i checked the machine and saw that only the scheduled task objects had 2003 and 2008 entries, everything else only shows 2008. that is why I overlooked it. Thanks, I will fix that now.

        Regards,

        Natascia

  23. Lalit Gupta said

    Hi ,

    I have imported this MP and disabled discovery for all.And enabled discovery only for few servers,but its discovering all the servers and their jobs as well.
    I want to discover jobs only for few servers.

    Thanks!

    • rburri said

      Hi Lalit
      After disabling the discoveries using an override, additional steps are required to remove the already discovered instances from SCOM. Running Remove-SCOMDisabledClassInstance resp. Remove-DisabledMonitoringObject if you’re still on 2007 take care of this.

      To summarize:
      a) Disable root discovery. “Windows Task Scheduler Discovery (Windows 2008)” / “Windows Scheduled Task Discovery (Windows 2003)”. Make sure you’ve got an override that sets “Enabled” to “False” in place.
      b) run the SCOM PSCommand (might take some time to finish)
      c) the task instances should then have been removed
      d) enable the discoveries just for the computers you require task monitoring.

      By the way: I am in the process of rewriting this MP such that it will support PS Scheduled Jobs. If you’re interested in testing it, drop me an email. You can find the address in the MP guide.

      Cheers

      Raphael

  24. salvador said

    This MP works in Scom 2012 SP1?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: