mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
nfdump support for with NFSen (#10376)
* rework the nfsen stuff * add the new netflow stats page * update the docs for nfsen * add the functions back in * readd the defaults * rework lowest_five_minutes into lowest_time * nfsen_channel_rrds removed and will rework it in later post rewriting * rework something that accidentally got nuked in merging * rework formatting a bit * remove a accidentaly added chunk of text =^.^= * rework some tag capitalization * remove a accidentally added [ * '='=>' = '
This commit is contained in:
committed by
Tony Murray
parent
c18ba96f08
commit
0a6ded9ba3
@@ -9,25 +9,27 @@ $link_array = array(
|
||||
);
|
||||
|
||||
echo generate_link('General', $link_array, array('nfsen' => 'general'));
|
||||
echo '|';
|
||||
echo generate_link('Stats', $link_array, array('nfsen' => 'stats'));
|
||||
|
||||
$printedChannel=false;
|
||||
$nfsenHostname = str_replace('.', \LibreNMS\Config::get('nfsen_split_char'), $device['hostname']);
|
||||
foreach ((array)\LibreNMS\Config::get('nfsen_rrds', []) as $nfsenDir) {
|
||||
$hostDir=$nfsenDir.'/'.$nfsenHostname.'/';
|
||||
$printedChannel = false;
|
||||
$nfsen_hostname = nfsen_hostname($device['hostname']);
|
||||
foreach (\LibreNMS\Config::get('nfsen_rrds') as $nfsenDir) {
|
||||
$hostDir = $nfsenDir.'/'.$nfsen_hostname.'/';
|
||||
if (is_dir($hostDir)) {
|
||||
$nfsenRRDchannelGlob=$hostDir.'*.rrd';
|
||||
$nfsenRRDchannelGlob = $hostDir.'*.rrd';
|
||||
foreach (glob($nfsenRRDchannelGlob) as $nfsenRRD) {
|
||||
$channel = str_replace(array($hostDir, '.rrd'), '', $nfsenRRD);
|
||||
|
||||
if (!$printedChannel) {
|
||||
echo '|Channels:';
|
||||
$printedChannel=true;
|
||||
$printedChannel = true;
|
||||
} else {
|
||||
echo ',';
|
||||
}
|
||||
|
||||
if ($vars['channel'] == $channel) {
|
||||
$channelFilter=$hostDir.$channel.'-filter.txt';
|
||||
$channelFilter = $hostDir.$channel.'-filter.txt';
|
||||
}
|
||||
|
||||
echo generate_link($channel, $link_array, array('nfsen' => 'channel', 'channel' => $channel));
|
||||
@@ -37,9 +39,12 @@ foreach ((array)\LibreNMS\Config::get('nfsen_rrds', []) as $nfsenDir) {
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
$nfsen_type = basename($vars['nfsen'] ?? 'general');
|
||||
if (is_file("includes/html/pages/device/nfsen/$nfsen_type.inc.php")) {
|
||||
include "includes/html/pages/device/nfsen/$nfsen_type.inc.php";
|
||||
if (!$vars['nfsen']) {
|
||||
$vars['nfsen'] = 'general';
|
||||
}
|
||||
|
||||
if (is_file('includes/html/pages/device/nfsen/'.mres($vars['nfsen']).'.inc.php')) {
|
||||
include 'includes/html/pages/device/nfsen/'.mres($vars['nfsen']).'.inc.php';
|
||||
} else {
|
||||
include 'includes/html/pages/device/nfsen/general.inc.php';
|
||||
}
|
||||
|
||||
153
includes/html/pages/device/nfsen/stats.inc.php
Normal file
153
includes/html/pages/device/nfsen/stats.inc.php
Normal file
@@ -0,0 +1,153 @@
|
||||
<?php
|
||||
|
||||
print_optionbar_start();
|
||||
|
||||
echo '<form action = "'.generate_url($link_array, array('nfsen' => 'stats')).'" iOCd = "FlowStats" method = "SUBMIT">';
|
||||
|
||||
echo 'Top N:
|
||||
<select name = "topN" id = "topN" size = 1>
|
||||
';
|
||||
|
||||
$option_default = $vars['topN'] ?? \LibreNMS\Config::get('nfsen_top_default');
|
||||
|
||||
$option_int = 0;
|
||||
foreach (\LibreNMS\Config::get('nfsen_top_N') as $option) {
|
||||
if (strcmp($option_default, $option) == 0) {
|
||||
echo '<option value = "'.$option.'" selected>'.$option.'</option>';
|
||||
} else {
|
||||
echo '<option value = "'.$option.'">'.$option.'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>
|
||||
During the last:
|
||||
<select name = "lastN" id = "lastN" size = 1>
|
||||
';
|
||||
|
||||
$option_keys = array_keys(\LibreNMS\Config::get('nfsen_lasts'));
|
||||
$options = \LibreNMS\Config::get('nfsen_lasts');
|
||||
foreach ($option_keys as $option) {
|
||||
if (strcmp($option_default, $option) == 0) {
|
||||
echo '<option value = "'.$option.'" selected>'.$options[$option].'</option>';
|
||||
} else {
|
||||
echo '<option value = "'.$option.'">'.$options[$option].'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>
|
||||
, Stat Type:
|
||||
<select name = "stattype" id = "StatTypeSelector" size = 1>
|
||||
';
|
||||
|
||||
$option_default = $vars['stattype'] ?? \LibreNMS\Config::get('nfsen_stats_default');
|
||||
|
||||
$stat_types = array(
|
||||
'record'=>'Flow Records',
|
||||
'ip'=>'Any IP Address',
|
||||
'srcip'=>'SRC IP Address',
|
||||
'dstip'=>'DST IP Address',
|
||||
'port'=>'Any Port',
|
||||
'srcport'=>'SRC Port',
|
||||
'dstport'=>'DST Port',
|
||||
'srctos'=>'SRC TOS',
|
||||
'dsttos'=>'DST TOS',
|
||||
'tos'=>'TOS',
|
||||
'as'=>'AS',
|
||||
'srcas'=>'SRC AS',
|
||||
'dstas'=>'DST AS',
|
||||
);
|
||||
|
||||
// puts together the drop down options
|
||||
foreach ($stat_types as $option => $descr) {
|
||||
if (strcmp($option_default, $option) == 0) {
|
||||
echo '<option value = "'.$option.'" selected>'.$descr."</option>\n";
|
||||
} else {
|
||||
echo '<option value = "'.$option.'">'.$descr."</option>\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>
|
||||
, Order By:
|
||||
<select name = "statorder" id = "statorder" sizeOC = 1>
|
||||
';
|
||||
|
||||
$option_default = \LibreNMS\Config::get('nfsen_order_default');
|
||||
if (isset($vars['statorder'])) {
|
||||
$option_default = $vars['statorder'];
|
||||
}
|
||||
|
||||
|
||||
// WARNING: order is relevant as it has to match the
|
||||
// check later in the process part of this page.
|
||||
$order_types = array(
|
||||
'flows'=>1,
|
||||
'packets'=>1,
|
||||
'bytes'=>1,
|
||||
'pps'=>1,
|
||||
'bps'=>1,
|
||||
'bpp'=>1,
|
||||
);
|
||||
|
||||
// puts together the drop down options
|
||||
foreach ($order_types as $option => $descr) {
|
||||
if (strcmp($option_default, $option) == 0) {
|
||||
echo '<option value = "'.$option.'" selected>'.$option."</option>\n";
|
||||
} else {
|
||||
echo '<option value = "'.$option.'">'.$option."</option>\n";
|
||||
}
|
||||
}
|
||||
|
||||
echo '
|
||||
</select>
|
||||
<input type = "submit" name = "process" value = "process" size = "1">
|
||||
';
|
||||
echo '</form>';
|
||||
|
||||
print_optionbar_end();
|
||||
|
||||
// process stuff now if we the button was clicked on
|
||||
if (isset($vars['process'])) {
|
||||
// Make sure we have a sane value for lastN
|
||||
$lastN = 900;
|
||||
if (isset($vars['lastN']) &&
|
||||
is_numeric($vars['lastN']) &&
|
||||
($vars['lastN'] <= \LibreNMS\Config::get('nfsen_last_max'))
|
||||
) {
|
||||
$lastN = $vars['lastN'];
|
||||
}
|
||||
|
||||
// Make sure we have a sane value for lastN
|
||||
$topN = 20; // The default if not set or something invalid is set
|
||||
if (isset($vars['topN']) &&
|
||||
is_numeric($vars['topN']) &&
|
||||
($vars['topN'] <= \LibreNMS\Config::get('nfsen_top_max'))
|
||||
) {
|
||||
$topN = $vars['topN'];
|
||||
}
|
||||
|
||||
// Handle the stat order.
|
||||
$stat_order = 'pps'; // The default if not set or something invalid is set
|
||||
if (isset($vars['statorder']) && isset($order_types[$vars['statorder']])) {
|
||||
$stat_order = $vars['statorder'];
|
||||
}
|
||||
|
||||
// Handle the stat type.
|
||||
$stat_type = 'srcip'; // The default if not set or something invalid is set
|
||||
if (isset($vars['stattype']) && isset($stat_types[$vars['stattype']])) {
|
||||
$stat_type = $vars['stattype'];
|
||||
}
|
||||
|
||||
$current_time = lowest_time(time() - 300);
|
||||
$last_time = lowest_time($current_time - $lastN - 300);
|
||||
|
||||
$command = \LibreNMS\Config::get('nfdump').' -M '.nfsen_live_dir($device['hostname']).' -T -R '.
|
||||
time_to_nfsen_subpath($last_time).':'.time_to_nfsen_subpath($current_time).
|
||||
' -n '.$topN.' -s '.$stat_type.'/'.$stat_order;
|
||||
|
||||
echo '<pre>';
|
||||
system($command);
|
||||
echo '</pre>';
|
||||
}
|
||||
Reference in New Issue
Block a user