mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
feature: Added pi-hole application support (#6782)
* added data to webui * added last step on docs * fix scrutinizer issue * fix blank lines
This commit is contained in:
@@ -25,6 +25,7 @@ Different applications support a variety of ways collect data: by direct connect
|
||||
1. [Open Grid Scheduler](#opengridscheduler) - SNMP extend
|
||||
1. [OS Updates](#os-updates) - SNMP extend
|
||||
1. [PHP-FPM](#php-fpm) - SNMP extend
|
||||
1. [Pi-hole](#pi-hole) - SNMP extend
|
||||
1. [Postfix](#postfix) - SNMP extend
|
||||
1. [Postgres](#postgres) - SNMP extend
|
||||
1. [PowerDNS](#powerdns) - Agent
|
||||
@@ -501,6 +502,24 @@ extend phpfpmsp /etc/snmp/phpfpm-sp
|
||||
|
||||
It is worth noting that this only monitors a single pool. If you want to monitor multiple pools, this won't do it.
|
||||
|
||||
### Pi-hole
|
||||
#### SNMP Extend
|
||||
|
||||
1: Copy the shell script, pi-hole, to the desired host (the host must be added to LibreNMS devices) (wget https://github.com/librenms/librenms-agent/raw/master/snmp/pi-hole -O /etc/snmp/pi-hole)
|
||||
|
||||
2: Make the script executable (chmod +x /etc/snmp/pi-hole)
|
||||
|
||||
3: Edit your snmpd.conf file and add:
|
||||
```
|
||||
extend pi-hole /etc/snmp/pi-hole
|
||||
```
|
||||
|
||||
4: To get all data you must get your API auth token from Pi-hole server and change the API_AUTH_KEY entry inside the snmp script.
|
||||
|
||||
5: Restard snmpd.
|
||||
|
||||
6: On the device page in Librenms, edit your host and check the `Pi-hole` under the Applications tab or wait for it to be auto-discovered.
|
||||
|
||||
|
||||
### Postfix
|
||||
#### SNMP Extend
|
||||
|
@@ -121,6 +121,9 @@ function nicecase($item)
|
||||
case 'sdfsinfo':
|
||||
return 'SDFS info';
|
||||
|
||||
case 'pi-hole':
|
||||
return 'Pi-hole';
|
||||
|
||||
default:
|
||||
return ucfirst($item);
|
||||
}
|
||||
|
58
html/includes/graphs/application/pihole_queries.inc.php
Normal file
58
html/includes/graphs/application/pihole_queries.inc.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage pi-hole
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 crcro
|
||||
* @author Cercel Valentin <crc@nuamchefazi.ro>
|
||||
*/
|
||||
|
||||
require 'includes/graphs/common.inc.php';
|
||||
|
||||
$scale_min = 0;
|
||||
$colours = 'mixed';
|
||||
$unit_text = 'Queries';
|
||||
$unitlen = 6;
|
||||
$bigdescrlen = 25;
|
||||
$smalldescrlen = 25;
|
||||
$dostack = 0;
|
||||
$printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 33;
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $app['app_type'], $app['app_id']));
|
||||
|
||||
$array = array(
|
||||
'query_a' => array('descr' => 'A Type','colour' => '000000',),
|
||||
'query_aaaa' => array('descr' => 'AAAA Type','colour' => '657C5E',),
|
||||
'query_ptr' => array('descr' => 'PTR Type','colour' => 'F44842',),
|
||||
'query_srv' => array('descr' => 'SRV Type','colour' => '912925',),
|
||||
);
|
||||
|
||||
$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: $rrd_filename";
|
||||
}
|
||||
|
||||
require 'includes/graphs/generic_v3_multiline_float.inc.php';
|
61
html/includes/graphs/application/pihole_stats.inc.php
Normal file
61
html/includes/graphs/application/pihole_stats.inc.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage pi-hole
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 crcro
|
||||
* @author Cercel Valentin <crc@nuamchefazi.ro>
|
||||
*/
|
||||
|
||||
require 'includes/graphs/common.inc.php';
|
||||
|
||||
$scale_min = 0;
|
||||
$colours = 'mixed';
|
||||
$unit_text = 'Stats';
|
||||
$unitlen = 6;
|
||||
$bigdescrlen = 25;
|
||||
$smalldescrlen = 25;
|
||||
$dostack = 0;
|
||||
$printtotal = 0;
|
||||
$addarea = 1;
|
||||
$transparency = 33;
|
||||
$rrd_filename = rrd_name($device['hostname'], array('app', $app['app_type'], $app['app_id']));
|
||||
|
||||
$array = array(
|
||||
'domains_blocked' => array('descr' => 'Blocked domains','colour' => '000000',),
|
||||
'dns_query' => array('descr' => 'Today DNS Queries','colour' => '657C5E',),
|
||||
'ads_blocked' => array('descr' => 'ADs blocked','colour' => 'F44842',),
|
||||
'ads_percentage' => array('descr' => 'ADs blocked %','colour' => '912925',),
|
||||
'unique_domains' => array('descr' => 'Unique domains','colour' => 'F44842',),
|
||||
'queries_forwarded' => array('descr' => 'Queries forwarded','colour' => '1F35A5',),
|
||||
'queries_cached' => array('descr' => 'Queries cached','colour' => '137C21',),
|
||||
);
|
||||
|
||||
$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: $rrd_filename";
|
||||
}
|
||||
|
||||
require 'includes/graphs/generic_v3_multiline_float.inc.php';
|
@@ -271,6 +271,11 @@ $graphs['sdfsinfo'] = array(
|
||||
'rates',
|
||||
);
|
||||
|
||||
$graphs['pi-hole'] = array(
|
||||
'stats',
|
||||
'queries',
|
||||
);
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
echo "<span style='font-weight: bold;'>Apps</span> » ";
|
||||
|
41
html/pages/device/apps/pi-hole.inc.php
Normal file
41
html/pages/device/apps/pi-hole.inc.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage pi-hole
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author crcro <crc@nuamchefazi.ro>
|
||||
*/
|
||||
|
||||
global $config;
|
||||
|
||||
$graphs = array(
|
||||
'pihole_stats' => 'Stats',
|
||||
'pihole_queries' => 'Queries',
|
||||
);
|
||||
|
||||
foreach ($graphs as $key => $text) {
|
||||
$graph_type = $key;
|
||||
$graph_array['height'] = '100';
|
||||
$graph_array['width'] = '215';
|
||||
$graph_array['to'] = $config['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/print-graphrow.inc.php';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
echo '</div>';
|
||||
}
|
61
includes/polling/applications/pi-hole.inc.php
Normal file
61
includes/polling/applications/pi-hole.inc.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* 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. Please see LICENSE.txt at the top level of
|
||||
* the source code distribution for details.
|
||||
*
|
||||
* @package LibreNMS
|
||||
* @subpackage pi-hole
|
||||
* @link http://librenms.org
|
||||
* @copyright 2017 LibreNMS
|
||||
* @author crcro <crc@nuamchefazi.ro>
|
||||
*/
|
||||
|
||||
use LibreNMS\RRD\RrdDefinition;
|
||||
|
||||
$name = 'pi-hole';
|
||||
$app_id = $app['app_id'];
|
||||
$options = '-O qv';
|
||||
$oid = '.1.3.6.1.4.1.8072.1.3.2.4.1.2.7.112.105.45.104.111.108.101';
|
||||
|
||||
$pihole = snmp_walk($device, $oid, $options);
|
||||
|
||||
if ($pihole) {
|
||||
update_application($app, $pihole);
|
||||
list($domains_blocked, $dns_query, $ads_blocked, $ads_percentage, $unique_domains, $queries_forwarded, $queries_cached, $query_a, $query_aaaa, $query_ptr, $query_srv) = explode("\n", $pihole);
|
||||
|
||||
$rrd_name = array('app', $name, $app_id);
|
||||
$rrd_def = RrdDefinition::make()
|
||||
->addDataset('domains_blocked', 'GAUGE', 0)
|
||||
->addDataset('dns_query', 'GAUGE', 0)
|
||||
->addDataset('ads_blocked', 'GAUGE', 0)
|
||||
->addDataset('ads_percentage', 'GAUGE', 0)
|
||||
->addDataset('unique_domains', 'GAUGE', 0)
|
||||
->addDataset('queries_forwarded', 'GAUGE', 0)
|
||||
->addDataset('queries_cached', 'GAUGE', 0)
|
||||
->addDataset('query_a', 'GAUGE', 0)
|
||||
->addDataset('query_aaaa', 'GAUGE', 0)
|
||||
->addDataset('query_ptr', 'GAUGE', 0)
|
||||
->addDataset('query_srv', 'GAUGE', 0);
|
||||
|
||||
$fields = array(
|
||||
'domains_blocked' => $domains_blocked,
|
||||
'dns_query' => $dns_query,
|
||||
'ads_blocked' => $ads_blocked,
|
||||
'ads_percentage' => $ads_percentage,
|
||||
'unique_domains' => $unique_domains,
|
||||
'queries_forwarded' => $queries_forwarded,
|
||||
'queries_cached' => $queries_cached,
|
||||
'query_a' => $query_a,
|
||||
'query_aaaa' => $query_aaaa,
|
||||
'query_ptr' => $query_ptr,
|
||||
'query_srv' => $query_srv,
|
||||
);
|
||||
|
||||
$tags = array('name' => $name, 'app_id' => $app_id, 'rrd_def' => $rrd_def, 'rrd_name' => $rrd_name);
|
||||
data_update($device, 'app', $tags, $fields);
|
||||
}
|
||||
|
||||
unset($pihole);
|
Reference in New Issue
Block a user