Application DHCP Upgrade

This commit is contained in:
SourceDoctor
2020-05-22 23:02:19 +02:00
parent 5927983c50
commit cbe572f959
14 changed files with 423 additions and 22 deletions

View File

@@ -1279,6 +1279,7 @@ function get_postgres_databases($device_id)
function get_arrays_with_application($device, $app_id, $app_name, $category = null)
{
$entries = array();
$separator = '-';
if ($category) {
$pattern = sprintf('%s/%s-%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id, $category);
@@ -1286,10 +1287,13 @@ function get_arrays_with_application($device, $app_id, $app_name, $category = nu
$pattern = sprintf('%s/%s-%s-%s-*.rrd', get_rrd_dir($device['hostname']), 'app', $app_name, $app_id);
}
# app_name contains a separator character? consider it
$offset = substr_count($app_name, $separator);
foreach (glob($pattern) as $rrd) {
$filename = basename($rrd, '.rrd');
list(,,, $entry) = explode("-", $filename, 4);
$entry = explode($separator, $filename, 4 + $offset)[3 + $offset];
if ($entry) {
array_push($entries, $entry);
@@ -1328,6 +1332,21 @@ function get_arrays_with_seafile($device, $app_id, $category)
return get_arrays_with_application($device, $app_id, $app_name, $category);
}
/**
* Get all dhcp data from the collected
* rrd files.
*
* @param array $device device for which we get the rrd's
* @param int $app_id application id on the device
* @param string $category which category of dhcp graphs are searched
* @return array list of dhcp data
*/
function get_arrays_with_dhcpstats($device, $app_id, $category)
{
$app_name = 'dhcp-stats';
return get_arrays_with_application($device, $app_id, $app_name, $category);
}
/**
* Get all mdadm arrays from the collected
* rrd files.

View File

@@ -0,0 +1,36 @@
<?php
$unit_text = 'Current';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$category = 'networks';
$rrdVar = 'current';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => $net.'/'.$subnet,
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,36 @@
<?php
$unit_text = 'Max';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$category = 'networks';
$rrdVar = 'max';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => $net.'/'.$subnet,
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,36 @@
<?php
$unit_text = 'Percent';
$unitlen = 20;
$bigdescrlen = 20;
$smalldescrlen = 20;
$category = 'networks';
$rrdVar = 'percent';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
list($net, $subnet) = explode('_', str_replace($category.'-', '', $array));
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => $net.'/'.$subnet,
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,37 @@
<?php
$unit_text = 'Current';
$unitlen = 33;
$bigdescrlen = 33;
$smalldescrlen = 33;
$category = 'pools';
$rrdVar = 'current';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => str_replace($category.'-', '', $array),
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,37 @@
<?php
$unit_text = 'Max';
$unitlen = 33;
$bigdescrlen = 33;
$smalldescrlen = 33;
$category = 'pools';
$rrdVar = 'max';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => str_replace($category.'-', '', $array),
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -0,0 +1,37 @@
<?php
$unit_text = 'Percent';
$unitlen = 33;
$bigdescrlen = 33;
$smalldescrlen = 33;
$category = 'pools';
$rrdVar = 'percent';
$name = 'dhcp-stats';
$app_id = $app['app_id'];
$colours = 'mega';
$dostack = 0;
$printtotal = 0;
$addarea = 1;
$transparency = 15;
$arrays = get_arrays_with_dhcpstats($device, $app_id, $category);
$int=0;
while (isset($arrays[$int])) {
$array = $arrays[$int];
$rrd_filename = rrd_name($device['hostname'], array('app', $name, $app_id, $array));
if (rrdtool_check_rrd_exists($rrd_filename)) {
$rrd_list[] = array(
'filename' => $rrd_filename,
'descr' => str_replace($category.'-', '', $array),
'ds' => $rrdVar,
);
}
$int++;
}
require 'includes/html/graphs/generic_multi_line_exact_numbers.inc.php';

View File

@@ -124,6 +124,12 @@ $graphs['os-updates'] = array(
);
$graphs['dhcp-stats'] = array(
'stats',
'pools_percent',
'pools_current',
'pools_max',
'networks_percent',
'networks_current',
'networks_max',
);
$graphs['fail2ban'] = array(
'banned',

View File

@@ -1,14 +1,20 @@
<?php
$graphs = array(
'dhcp-stats_stats' => 'DHCP Stats',
'dhcp-stats_stats' => 'Stats',
'dhcp-stats_pools_percent' => 'Pools Percent',
'dhcp-stats_pools_current' => 'Pools Current',
'dhcp-stats_pools_max' => 'Pools Max',
'dhcp-stats_networks_percent' => 'Networks Percent',
'dhcp-stats_networks_current' => 'Networks Current',
'dhcp-stats_networks_max' => 'Networks Max',
);
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['to'] = time();
$graph_array['id'] = $app['app_id'];
$graph_array['type'] = 'application_'.$key;