# Using Nagios

![](/files/-M8HPrKFX6Jvy2XUGzHd)

#### Get informed in case the last run had problems (exitcode > 0)

Our example job's md5 is `0f517c9d32a032b84615c82461e1c864`&#x20;

In your host config:

```
define service {
        use                             generic-service;
        host_name                       my.server.com
        service_description             Last Run Failed
        check_command                   check_nrpe!check_last_run_job1
        notifications_enabled           1
}
```

In your nrpe.cfg:

```bash
command[check_last_run_job1]=cd /your/project && php artisan scheduler-watcher:checklastevent 0f517c9d32a032b84615c82461e1c864 --no-ansi
```

#### Get informed in case the job did not run in the last 15 minutes

Write a SQL that shows you how many minutes have passed since last run:

```sql
SELECT	CEILING(TIME_TO_SEC(TIMEDIFF(NOW(),je.jobe_db_created))/60) AS c 
FROM job_events je
	INNER JOIN jobs j
		ON je.jobe_job_id = j.job_id
WHERE j.job_md5 = '0f517c9d32a032b84615c82461e1c864'
ORDER BY je.jobe_id DESC LIMIT 0, 1;
```

Write a bash script, PHP or whatever you prefer:&#x20;

In case the result of the SQL shows more than 15, [exit your script](https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/pluginapi.html) with exitcode 2, if lower, exit with 0.

Read [this](https://unixmen.com/write-nagios-plugin-using-bash-script/) for further informations and example scripts.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://michabbb.gitbook.io/laravel-scheduler-watcher/nagios.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
