Apps - backupninja (#11010)

* GUI - graphs

* GUI - Apps

* Polling

* GUI - apps

* Add backupninja to documentation

* Apps - backupninja : add link to librenmsagent script

* Add backupninja snmprec file

* Delete backupninja.snmprec

No Regression tests on apps (yet), only on devices.

* Remove old debug

* Update language : FR -> EN

* Add debug informations

* File path moved to /etc/snmp/

* Python script now use json

* Update following example on puppet script

* Update installation instructions following puppet example

* Update apps.inc.php

Co-authored-by: PipoCanaja <38363551+PipoCanaja@users.noreply.github.com>
Co-authored-by: SourceDoctor <sourcehhdoctor@gmail.com>
This commit is contained in:
Anael Mobilia
2020-06-16 01:04:30 +02:00
committed by GitHub
parent 7dc1e0236f
commit 22916afb9e
5 changed files with 136 additions and 0 deletions

View File

@@ -87,6 +87,7 @@ by following the steps under the `SNMP Extend` heading.
1. [Apache](#apache) - SNMP extend, Agent
1. [Asterisk](#asterisk) - SNMP extend
1. [backupninja](#backupninja) - SNMP extend
1. [BIND9/named](#bind9-aka-named) - SNMP extend, Agent
1. [Certificate](#certificate) - Certificate extend
1. [C.H.I.P.](#chip) - SNMP extend
@@ -233,6 +234,28 @@ The application should be auto-discovered as described at the top of
the page. If it is not, please follow the steps set out under `SNMP
Extend` heading top of page.
# backupninja
A small shell script that reports status of last backupninja backup.
## SNMP Extend
1: Download the [backupninja
script](https://github.com/librenms/librenms-agent/blob/master/snmp/backupninja.py)
to `/etc/snmp/backupninja.py` on your backuped server.
```
wget https://raw.githubusercontent.com/librenms/librenms-agent/master/snmp/backupninja.py -O /etc/snmp/backupninja.py`
```
2: Make the script executable: `chmod +x /etc/snmp/backupninja.py`
3: Edit your snmpd.conf file (usually `/etc/snmp/snmpd.conf`) and add:
```
extend backupninja /etc/snmp/backupninja.py
```
4: Restart snmpd on your host
# BIND9 aka named
1: Create stats file with appropriate permissions:

View File

@@ -0,0 +1,43 @@
<?php
require 'includes/html/graphs/common.inc.php';
$rrd_filename = rrd_name($device['hostname'], array('app', 'backupninja', $app['app_id']));
$array = array(
'last_actions' => array(
'descr' => 'last_actions',
'colour' => '22FF22',
),
'last_fatal' => array(
'descr' => 'last_fatal',
'colour' => '0022FF',
),
'last_error' => array(
'descr' => 'last_error',
'colour' => 'FF0000',
),
'last_warning' => array(
'descr' => 'last_warning',
'colour' => '0080C0',
),
);
$i = 0;
if (rrdtool_check_rrd_exists($rrd_filename)) {
foreach ($array as $ds => $var) {
$rrd_list[$i]['filename'] = $rrd_filename;
$rrd_list[$i]['descr'] = $var['descr'];
$rrd_list[$i]['ds'] = $ds;
// $rrd_list[$i]['colour'] = $var['colour'];
$i++;
}
} else {
echo "file missing: $file";
}
$colours = 'mixed';
$nototal = 1;
$unit_text = 'backups';
require 'includes/html/graphs/generic_multi_line.inc.php';

View File

@@ -332,6 +332,10 @@ $graphs['mailcow-postfix'] = array(
'traffic',
'domains',
);
$graphs['backupninja'] = array(
'backupninja',
);
echo '<div class="panel panel-default">';
echo '<div class="panel-heading">';
echo "<span style='font-weight: bold;'>Apps</span> &#187; ";

View File

@@ -0,0 +1,22 @@
<?php
$graphs = array(
'backupninja_backupninja' => 'backupninja backups',
);
foreach ($graphs as $key => $text) {
$graph_type = $key;
$graph_array['height'] = '100';
$graph_array['width'] = '215';
$graph_array['to'] = \LibreNMS\Config::get('time.now');
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;
echo '<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">'.$text.'</h3>
</div>
<div class="panel-body">
<div class="row">';
include 'includes/html/print-graphrow.inc.php';
echo '</div>';
echo '</div>';
echo '</div>';
}

View File

@@ -0,0 +1,44 @@
<?php
// Polls backupninja statistics from script via SNMP
use LibreNMS\RRD\RrdDefinition;
$name = 'backupninja';
$app_id = $app['app_id'];
$output = 'OK';
try {
$backupninja_data = json_app_get($device, $name, 1)['data'];
} catch (JsonAppMissingKeysException $e) {
$backupninja_data = $e->getParsedJson();
} catch (JsonAppException $e) {
echo PHP_EOL . $name . ':' .$e->getCode().':'. $e->getMessage() . PHP_EOL;
update_application($app, $e->getCode().':'.$e->getMessage(), []); // Set empty metrics and error message
return;
}
$metrics = array();
$category = 'overview';
$rrd_name = array('app', $name, $app_id, $category);
$rrd_def = RrdDefinition::make()
->addDataset('last_actions', 'GAUGE', 0)
->addDataset('last_fatal', 'GAUGE', 0)
->addDataset('last_error', 'GAUGE', 0)
->addDataset('last_warning', 'GAUGE', 0);
$fields = array(
'last_actions' => $backupninja_data['last_actions'],
'last_fatal' => $backupninja_data['last_fatal'],
'last_error' => $backupninja_data['last_error'],
'last_warning' => $backupninja_data['last_warning'],
);
$metrics[$category] = $fields;
// Debug
d_echo("backupninja : $fields");
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
data_update($device, 'app', $tags, $fields);
update_application($app, $output, $metrics);