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:
Zane C. Bowers-Hadley
2019-08-06 19:16:34 -05:00
committed by Tony Murray
parent c18ba96f08
commit 0a6ded9ba3
7 changed files with 475 additions and 56 deletions

View File

@@ -571,7 +571,7 @@ function generate_sensor_url($sensor, $vars = array())
return generate_url(array('page' => 'graphs', 'id' => $sensor['sensor_id'], 'type' => $sensor['graph_type'], 'from' => Config::get('time.day')), $vars);
}//end generate_sensor_url()
function generate_port_url($port, $vars = array())
{
return generate_url(array('page' => 'device', 'device' => $port['device_id'], 'tab' => 'port', 'port' => $port['port_id']), $vars);
@@ -1640,3 +1640,105 @@ function get_sensor_label_color($sensor, $type = 'sensors')
$unit = __("$type.{$sensor['sensor_class']}.unit");
return "<span class='label $label_style'>".trim(format_si($sensor['sensor_current']).$unit)."</span>";
}
/**
* @params int unix time
* @params int seconds
* @return int
*
* Rounds down to the nearest interval.
*
* The first argument is required and it is the unix time being
* rounded down.
*
* The second value is the time interval. If not specified, it
* defaults to 300, or 5 minutes.
*/
function lowest_time($time, $seconds = 300)
{
return $time - ($time % $seconds);
}
/**
* @params int
* @return string
*
* This returns the subpath for working with nfdump.
*
* 1 value is taken and that is a unix time stamp. It will be then be rounded
* off to the lowest five minutes earlier.
*
* The return string will be a path partial you can use with nfdump to tell it what
* file or range of files to use.
*
* Below ie a explanation of the layouts as taken from the NfSen config file.
* 0 no hierachy levels - flat layout - compatible with pre NfSen version
* 1 %Y/%m/%d year/month/day
* 2 %Y/%m/%d/%H year/month/day/hour
* 3 %Y/%W/%u year/week_of_year/day_of_week
* 4 %Y/%W/%u/%H year/week_of_year/day_of_week/hour
* 5 %Y/%j year/day-of-year
* 6 %Y/%j/%H year/day-of-year/hour
* 7 %Y-%m-%d year-month-day
* 8 %Y-%m-%d/%H year-month-day/hour
*/
function time_to_nfsen_subpath($time)
{
$time=lowest_time($time);
$layout=Config::get('nfsen_subdirlayout');
if ($layout == 0) {
return 'nfcapd.'.date('YmdHi', $time);
} elseif ($layout == 1) {
return date('Y\/m\/d\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 2) {
return date('Y\/m\/d\/H\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 3) {
return date('Y\/W\/w\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 4) {
return date('Y\/W\/w\/H\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 5) {
return date('Y\/z\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 6) {
return date('Y\/z\/H\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 7) {
return date('Y\-m\-d\/\n\f\c\a\p\d\.YmdHi', $time);
} elseif ($layout == 8) {
return date('Y\-m\-d\/H\/\n\f\c\a\p\d\.YmdHi', $time);
}
}
/**
* @params string hostname
* @return string
*
* Takes a hostname and transforms it to the name
* used by nfsen.
*/
function nfsen_hostname($hostname)
{
$nfsen_hostname=str_replace('.', Config::get('nfsen_split_char'), $hostname);
if (!is_null(Config::get('nfsen_suffix'))) {
$nfsen_hostname=str_replace(Config::get('nfsen_suffix'), '', $nfsen_hostname);
}
return $nfsen_hostname;
}
/**
* @params string hostname
* @return string
*
* Takes a hostname and returns the path to the nfsen
* live dir.
*/
function nfsen_live_dir($hostname)
{
$hostname=nfsen_hostname($hostname);
foreach (Config::get('nfsen_base') as $base_dir) {
if (file_exists($base_dir) && is_dir($base_dir)) {
return $base_dir.'/profiles-data/live/'.$hostname;
}
}
}