mirror of
https://github.com/librenms/librenms.git
synced 2024-09-21 02:18:39 +00:00
Add a validation for checking if the scheduler is running (#14987)
This commit is contained in:
parent
e1b6fd0165
commit
f271019f6c
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,4 +44,5 @@ librenms_theme
|
||||
|
||||
bin/
|
||||
lib/
|
||||
lib64
|
||||
pyvenv.cfg
|
||||
|
43
LibreNMS/Validations/Scheduler.php
Normal file
43
LibreNMS/Validations/Scheduler.php
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
@ -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
11
dist/librenms-scheduler.service
vendored
Normal 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
9
dist/librenms-scheduler.timer
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
[Unit]
|
||||
Description=LibreNMS Scheduler
|
||||
|
||||
[Timer]
|
||||
OnCalendar=minutely
|
||||
AccuracySec=1second
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
5
librenms.nonroot.cron → dist/librenms.cron
vendored
5
librenms.nonroot.cron → dist/librenms.cron
vendored
@ -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:
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user