Examples of JobMonitor Monitoring
Last updated on 15 November, 2024To 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 every day on app1. LogicMonitor should monitor if:
- The task
cleanlogs
starts on time at 8:30, 12:30, and 16:30 every day - The task was finished successfully
Monitoring Linux Cron Job
- In LogicMonitor, navigate to Settings > LogicModules.
- In the My Module ToolBox page, select and then JobMonitor.
- Enter the JobMonitor definition.
- Select Save.
- 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 every day:
currently executes a script /usr/local/cleanlog.pl
- Copy
lmbatchjobwrapper.sh
to app1.
Thelmbatchjobwrapper.sh
is located at/usr/local/logicmonitor/agent/lib
of collectorhost. - 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
- 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
- Set the variables in etc/environment and do the following:
- Open the terminal and enter the following command:
$ sudo -H vi /etc/environment
- Enter the password.
- 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. - Save and close the file.
- Log out, and then log back in.
- Open the terminal and enter the following command:
Note:
- These variables can be accessed by any user and persist through power-offs.
- Variable expansion is not supported in the /etc/environment.
- 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.
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 every day on app1
. LogicMonitor should monitor if:
- The task
cleanlogs
is started on time at 8:30, 12:30, and 16:30 every day - The task was finished successfully
Monitoring Windows Scheduler Task
- In LogicMonitor, navigate to Settings > LogicModules.
- In the My Module ToolBox page, select and then JobMonitor.
- Enter the JobMonitor definition.
- Select Save.
- On your Windows device, enter Windows + R to open the Run dialog.
- Type taskschd.msc and select OK to open the Task Scheduler.
- In the Action panel, select Create Basic Task.
- In the Create Basic Task Wizard, enter the name and description of the task in the Name and Description fields respectively.
- Select Next.
- In the Task Trigger step, select the desired trigger interval. For example, Daily, Weekly, Monthly, and so on.
- Select Next.
- Set the trigger timing based on your requirements. For example, the start date, time, and recurrence.
- Select Next.
- In the Action step, select Start a program as the action.
- Select Next.
- In the Program/script field, enter cscript.exe or select Browse to navigate to the location of the cscript.exe file.
- 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"
- Example without optional arguments:
- Select Next.
- In the Summary step, review all the details and select Finish to create the task.
- 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.