Examples of JobMonitor Monitoring

Last updated on 11 November, 2024

To better understand the job monitoring process, use the following JobMonitor examples: Monitoring a Linux Cron Job and Monitoring a Windows Scheduler Task.

Warning: Do not provide sensitive information in the command line, such as usernames or passwords. This information should be handled inside the script, using any secrets management tool or environment variables (Environment variables are preferred over plain text credentials in code).

Recommendation: You can leverage a dedicated secrets management tool over using environmental variables.

Monitor Linux Cron Job Example

You can assume the monitored device in LogicMonitor is app1, and the collector monitoring app1 runs on the device agenthost. There is a cron job cleanlogs running at 8:30, 12:30, and 16:30 everyday on app1. LogicMonitor should monitor if:

  • The task cleanlogs starts on time at 8:30, 12:30, and 16:30 everyday
  • The task was finished successfully

Monitoring Linux Cron Job

  1. In LogicMonitor, navigate to Settings LogicModules.
  2. In the My Module ToolBox page, select add icon and then JobMonitor.
  3. Enter the JobMonitor definition.
  4. Select Save.
    Add linux cron job page
  5. On the Linux system where the cron job is executing, go to your command prompt and run the following script for cron jobs cleanlogs at 8:30, 12:30, and 16:30 everyday:
currently executes a script /usr/local/cleanlog.pl
Cron job script image
  1. Copy lmbatchjobwrapper.sh to app1. 
    The lmbatchjobwrapper.sh is located at /usr/local/logicmonitor/agent/lib of collectorhost.
  2. Run crontab -e (or equivalent) and update the command line as follows:
    30 8,12,16 * * * /usr/local/lmcollector lmbatchjobwrapper.sh agenthost:7214 app1 "Clean log monitoring" /usr/local/cleanlog.pl
    Review the elements in the code sample:
    • agenthost:7214 is the name of the device on which the collector is running and the port on which the collector listens to accept batch job execution notifications sent from lmJobMonitorwrapper.js
    • app1 is the name of the monitored device on which the batch job is running
    • Clean log monitoring is the name given to this scheduled task in LogicMonitor
    • /usr/local/cleanlog.pl tells the wrapper how to start the program to clean the logs
  3. Set the variables in etc/environment and do the following:
    1. Open the terminal and enter the following command: 
      $ sudo -H vi /etc/environment
    2. Enter the password. 
    3. Add the variables in the file that is opened. (For example, PASSWORD=pass1234)
      Note: Password can be used in the script with $PASSWORD. For more information, see Environment Variables with Linux/Unix.
    4. Save and close the file.
    5. Log out, and then log back in.

Note:

  • These variables can be accessed by any user and persist through power-offs.
  • Variable expansion is not supported in the /etc/environment.
  1. Check the job of the scheduled task on the Resources page.
    Jobs that did not start on time or finished abnormally are shown with an error.
    Jobmonitor execution page

Monitor Windows Scheduler Task Example

You can assume the monitored device is app1, and the collector monitoring app1 runs on the device agenthost. There is a Windows scheduler task cleanlogs running at 8:30, 12:30, and 16:30 everyday on app1. LogicMonitor should monitor if:

  • The task cleanlogs is started on time at 8:30, 12:30, and 16:30 everyday
  • The task was finished successfully

Monitoring Windows Scheduler Task

  1. In LogicMonitor, navigate to Settings LogicModules.
  2. In the My Module ToolBox page, select add icon and then JobMonitor.
  3. Enter the JobMonitor definition.
  4. Select Save.
    Add linux cron job page
  5. On your Windows device, enter Windows + R to open the Run dialog.
  6. Type taskschd.msc and select OK to open the Task Scheduler. 
  7. In the Action panel, select Create Basic Task.
    Windows task scheduler modal
  8. In the Create Basic Task Wizard, enter the name and description of the task in the Name and Description fields respectively. 
  9. Select Next.
  10. In the Task Trigger step, select the desired trigger interval. For example, Daily, Weekly, Monthly, and so on.
  11. Select Next.
  12. Set the trigger timing based on your requirements. For example, the start date, time, and recurrence.
  13. Select Next.
  14. In the Action step, select Start a program as the action.
  15. Select Next.
  16. In the Program/script field, enter cscript.exe or select Browse to navigate to the location of the cscript.exe file.
  17. In the Add arguments field, add in the following format:
    <path to file>/lmbatchjobwrapper.js <agentaddr> <hostname> <jobname> <cmdline> <Optional Arguments>

    <path to file>—Path to the lmbatchjobwrapper.js script file
    <agentaddr>—The agent address, For example, 10.1.1.1:7214
    <hostname>—The hostname where the task is running
    <jobname>—The name of the job being monitored is given on the LogicMonitor portal
    <cmdline>—The command to be executed
    • Example without optional arguments:
      cscript.exe lmbatchjobwrapper.js 10.1.1.1:7214 host myJob "cmd.exe /C dir"
    • Example with optional arguments:
      cscript.exe C:\lmbatchjobwrapper.js 10.1.1.1:7214 host myJob "cmd.exe /C $arg1" "arg1=C:\Program Files\Test Space Folder\Hello World.bat"
      Create basic task wizard modal
  18. Select Next.
  19. In the Summary step, review all the details and select Finish to create the task.
    Create task wizard summary modal
  20. Check the job of the scheduled task on the Resources page.
    Jobs that did not start on time or finished abnormally are shown with an error.
    Jobmonitor execution page
In This Article