Add a validation for checking if the scheduler is running (#14987)

This commit is contained in:
Jellyfrog 2023-04-24 10:04:50 +02:00 committed by GitHub
parent e1b6fd0165
commit f271019f6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 97 additions and 23 deletions

1
.gitignore vendored
View File

@ -44,4 +44,5 @@ librenms_theme
bin/
lib/
lib64
pyvenv.cfg

View File

@ -0,0 +1,43 @@
<?php
/**
* Scheduler.php
*
* -Description-
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* @link https://www.librenms.org
*/
namespace LibreNMS\Validations;
use Illuminate\Support\Facades\Cache;
use LibreNMS\Validator;
class Scheduler extends BaseValidation
{
/**
* Validate this module.
* To return ValidationResults, call ok, warn, fail, or result methods on the $validator
*
* @param Validator $validator
*/
public function validate(Validator $validator): void
{
if (! Cache::has('scheduler_working')) {
$validator->fail('Scheduler is not running',
"cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/\nsystemctl enable librenms-scheduler.timer\nsystemctl start librenms-scheduler.timer");
}
}
}

View File

@ -4,6 +4,7 @@ namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Cache;
use LibreNMS\Util\Debug;
use LibreNMS\Util\Version;
@ -17,8 +18,7 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
// ->hourly();
$this->scheduleMarkWorking($schedule);
}
/**
@ -62,4 +62,15 @@ class Kernel extends ConsoleKernel
return parent::handle($input, $output);
}
/**
* Store in the cache that the schedule is triggered.
* Used for Validation.
*/
private function scheduleMarkWorking(Schedule $schedule): void
{
$schedule->call(function () {
Cache::put('scheduler_working', now(), now()->addMinutes(6));
})->everyFiveMinutes();
}
}

11
dist/librenms-scheduler.service vendored Normal file
View File

@ -0,0 +1,11 @@
[Unit]
Description=LibreNMS Scheduler
[Service]
Type=oneshot
StandardOutput=null
StandardError=null
WorkingDirectory=/opt/librenms/
ExecStart=/usr/bin/env php artisan schedule:run
User=librenms
Group=librenms

9
dist/librenms-scheduler.timer vendored Normal file
View File

@ -0,0 +1,9 @@
[Unit]
Description=LibreNMS Scheduler
[Timer]
OnCalendar=minutely
AccuracySec=1second
[Install]
WantedBy=timers.target

View File

@ -1,13 +1,12 @@
# Using this cron file requires an additional user on your system, please see install docs.
33 */6 * * * librenms /opt/librenms/cronic /opt/librenms/discovery-wrapper.py 1
*/5 * * * * librenms /opt/librenms/discovery.php -h new >> /dev/null 2>&1
*/5 * * * * librenms /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
* * * * * librenms /opt/librenms/alerts.php >> /dev/null 2>&1
*/5 * * * * librenms /opt/librenms/poll-billing.php >> /dev/null 2>&1
01 * * * * librenms /opt/librenms/billing-calculate.php >> /dev/null 2>&1
*/5 * * * * librenms /opt/librenms/check-services.php >> /dev/null 2>&1
* * * * * librenms cd /opt/librenms/ && php artisan schedule:run >> /dev/null 2>&1
# Daily maintenance script. DO NOT DISABLE!
# If you want to modify updates:

View File

@ -592,7 +592,7 @@ systemctl restart snmpd
## Cron job
```
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited
@ -603,6 +603,15 @@ cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
> finished librenms install steps:
> <@= config.site_url =@/Support/Configuration/#proxy-support>
## Enable the scheduler
```
cp /opt/librenms/dist/librenms-scheduler.service /opt/librenms/dist/librenms-scheduler.timer /etc/systemd/system/
systemctl enable librenms-scheduler.timer
systemctl start librenms-scheduler.timer
```
## Copy logrotate config
LibreNMS keeps logs in `/opt/librenms/logs`. Over time these can

View File

@ -426,7 +426,7 @@ If the thread count needs to be changed, you can do so by editing the cron file
Create the cronjob
```
cp librenms.nonroot.cron /etc/cron.d/librenms
cp dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -277,7 +277,7 @@ systemctl restart snmpd
# Cron job
```
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -263,7 +263,7 @@ systemctl restart snmpd
# Cron job
```
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -133,7 +133,7 @@ systemctl restart snmpd
## Cron job
```bash
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -144,7 +144,7 @@ systemctl restart snmpd
# Cron job
```bash
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -150,7 +150,7 @@ systemctl restart snmpd
# Cron job
```bash
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -169,7 +169,7 @@ systemctl restart snmpd
# Cron job
```bash
cp /opt/librenms/librenms.nonroot.cron /etc/cron.d/librenms
cp /opt/librenms/dist/librenms.cron /etc/cron.d/librenms
```
> NOTE: Keep in mind that cron, by default, only uses a very limited

View File

@ -1,9 +0,0 @@
# It's recommended not to run this cron anymore - please see librenms.nonroot.cron
# PLEASE DO NOT USE THIS FILE
33 */6 * * * root /opt/librenms/discovery.php -h all >> /dev/null 2>&1
*/5 * * * * root /opt/librenms/discovery.php -h new >> /dev/null 2>&1
*/5 * * * * root /opt/librenms/cronic /opt/librenms/poller-wrapper.py 16
19 0 * * * root /opt/librenms/daily.sh >> /dev/null 2>&1
* * * * * root /opt/librenms/alerts.php >> /dev/null 2>&1
* * * * * root cd /opt/librenms/ && php artisan schedule:run >> /dev/null 2>&1

View File

@ -40,7 +40,7 @@
<div x-bind:id="'body-' + group.group" class="panel-collapse collapse" x-bind:class="{'in': group.status !== 2}">
<div class="panel-body">
<template x-for="result in group.results">
<div class="panel" x-bind:class="{'panel-success': result.status === 2, 'panel-warning': result.status === 1, 'panel-danger': result.status === 0}">
<div class="panel" x-bind:class="{'panel-info': result.status === 3, 'panel-success': result.status === 2, 'panel-warning': result.status === 1, 'panel-danger': result.status === 0}">
<div class="panel-heading"
x-text="result.statusText + ': ' + result.message"
></div>