diff --git a/pandora_console/godmode/menu.php b/pandora_console/godmode/menu.php index af15b28f7a..8b2ef974e1 100644 --- a/pandora_console/godmode/menu.php +++ b/pandora_console/godmode/menu.php @@ -364,6 +364,11 @@ if ($access_console_node === true) { $sub2['godmode/setup/setup§ion=net']['text'] = __('Netflow'); $sub2['godmode/setup/setup§ion=net']['refr'] = 0; } + + if ((bool) $config['activate_sflow'] === true) { + $sub2['godmode/setup/setup§ion=sflow']['text'] = __('Sflow'); + $sub2['godmode/setup/setup§ion=sflow']['refr'] = 0; + } } $sub2['godmode/setup/setup§ion=ehorus']['text'] = __('eHorus'); diff --git a/pandora_console/godmode/setup/setup.php b/pandora_console/godmode/setup/setup.php index 8c8587b1ef..846ea7a57f 100644 --- a/pandora_console/godmode/setup/setup.php +++ b/pandora_console/godmode/setup/setup.php @@ -154,6 +154,20 @@ if (check_acl($config['id_user'], 0, 'AW')) { ).'', ]; } + + if ($config['activate_sflow']) { + $buttons['sflow'] = [ + 'active' => false, + 'text' => ''.html_print_image( + 'images/op_netflow.png', + true, + [ + 'title' => __('Sflow'), + 'class' => 'invert_filter', + ] + ).'', + ]; + } } $buttons['integria'] = [ @@ -272,6 +286,12 @@ switch ($section) { $help_header = 'setup_netflow_tab'; break; + case 'sflow': + $buttons['sflow']['active'] = true; + $subpage = ' » '.__('Sflow'); + $help_header = 'setup_flow_tab'; + break; + case 'ehorus': $buttons['ehorus']['active'] = true; $subpage = ' » '.__('eHorus'); @@ -381,6 +401,10 @@ switch ($section) { include_once $config['homedir'].'/godmode/setup/setup_netflow.php'; break; + case 'sflow': + include_once $config['homedir'].'/godmode/setup/setup_sflow.php'; + break; + case 'vis': include_once $config['homedir'].'/godmode/setup/setup_visuals.php'; break; diff --git a/pandora_console/godmode/setup/setup_general.php b/pandora_console/godmode/setup/setup_general.php index fc169f91a2..348746ea60 100644 --- a/pandora_console/godmode/setup/setup_general.php +++ b/pandora_console/godmode/setup/setup_general.php @@ -246,7 +246,31 @@ $table->data[$i++][1] = html_print_checkbox_switch_extended( true ); +$table->data[$i][0] = __('Enable Sflow'); +$rbt_disabled = false; +if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN') { + $rbt_disabled = true; +} +$table->data[$i++][1] = html_print_checkbox_switch_extended( + 'activate_sflow', + 1, + $config['activate_sflow'], + $rbt_disabled, + '', + '', + true +); + +$table->data[$i][0] = __('General network path'); +$table->data[$i++][1] = html_print_input_text( + 'general_network_path', + $config['general_network_path'], + '', + 40, + 255, + true +); $zone_name = [ 'Africa' => __('Africa'), 'America' => __('America'), diff --git a/pandora_console/godmode/setup/setup_netflow.php b/pandora_console/godmode/setup/setup_netflow.php index 48a2947bb2..00f6ecbe05 100644 --- a/pandora_console/godmode/setup/setup_netflow.php +++ b/pandora_console/godmode/setup/setup_netflow.php @@ -45,7 +45,8 @@ $table->class = 'databox filters'; $table->data = []; $table->data[0][0] = ''.__('Data storage path').''; -$table->data[0][1] = html_print_input_text('netflow_path', $config['netflow_path'], false, 50, 200, true); +$table->data[0][1] = html_print_input_text('netflow_name_dir', $config['netflow_name_dir'], false, 50, 200, true); +$table->data[0][1] .= ''; $table->data[1][0] = ''.__('Daemon interval').''; $table->data[1][1] = html_print_input_text('netflow_interval', $config['netflow_interval'], false, 50, 200, true); diff --git a/pandora_console/godmode/setup/setup_sflow.php b/pandora_console/godmode/setup/setup_sflow.php new file mode 100644 index 0000000000..2610bc3361 --- /dev/null +++ b/pandora_console/godmode/setup/setup_sflow.php @@ -0,0 +1,84 @@ +width = '100%'; +$table->border = 0; +$table->cellspacing = 3; +$table->cellpadding = 5; +$table->class = 'databox filters'; + +$table->data = []; + +$table->data[0][0] = ''.__('Data storage path').''; +$table->data[0][1] = html_print_input_text('sflow_name_dir', $config['sflow_name_dir'], false, 50, 200, true); +$table->data[0][1] .= ''; + + +$table->data[1][0] = ''.__('Daemon interval').''; +$table->data[1][1] = html_print_input_text('sflow_interval', $config['sflow_interval'], false, 50, 200, true); + +$table->data[2][0] = ''.__('Daemon binary path').''; +$table->data[2][1] = html_print_input_text('sflow_daemon', $config['sflow_daemon'], false, 50, 200, true); + +$table->data[3][0] = ''.__('Nfdump binary path').''; +$table->data[3][1] = html_print_input_text('sflow_nfdump', $config['sflow_nfdump'], false, 50, 200, true); + +$table->data[4][0] = ''.__('Nfexpire binary path').''; +$table->data[4][1] = html_print_input_text('sflow_nfexpire', $config['sflow_nfexpire'], false, 50, 200, true); + +$table->data[5][0] = ''.__('Maximum chart resolution').''; +$table->data[5][1] = html_print_input_text('sflow_max_resolution', $config['sflow_max_resolution'], false, 50, 200, true); + +$table->data[6][0] = ''.__('Disable custom live view filters').''; +$table->data[6][1] = html_print_checkbox_switch('sflow_disable_custom_lvfilters', 1, $config['sflow_disable_custom_lvfilters'], true); +$table->data[7][0] = ''.__('Max. sflow lifetime').''; +$table->data[7][1] = html_print_input_text('sflow_max_lifetime', $config['sflow_max_lifetime'], false, 50, 200, true); + +$table->data[8][0] = ''.__('Name resolution for IP address').''; +$onclick = "if (!confirm('".__('Warning').'. '.__('IP address resolution can take a lot of time')."')) return false;"; +$table->data[8][1] = html_print_checkbox_switch_extended('sflow_get_ip_hostname', 1, $config['sflow_get_ip_hostname'], false, $onclick, '', true); + +echo '
'; diff --git a/pandora_console/include/functions_config.php b/pandora_console/include/functions_config.php index 24d2de537d..66b978a0d2 100644 --- a/pandora_console/include/functions_config.php +++ b/pandora_console/include/functions_config.php @@ -260,6 +260,24 @@ function config_update_config() $error_update[] = __('Enable Netflow'); } + if (config_update_value('activate_sflow', (bool) get_parameter('activate_sflow'), true) === false) { + $error_update[] = __('Enable Sflow'); + } + + if (config_update_value('general_network_path', get_parameter('general_network_path'), true) === false) { + $error_update[] = __('General network path'); + } else { + if (empty($config['netflow_name_dir']) === false && $config['netflow_name_dir'] !== '') { + $path = get_parameter('general_network_path'); + config_update_value('netflow_path', $path.$config['netflow_name_dir']); + } + + if (empty($config['sflow_name_dir']) === false && $config['sflow_name_dir'] !== '') { + $path = get_parameter('general_network_path'); + config_update_value('sflow_path', $path.$config['sflow_name_dir']); + } + } + $timezone = (string) get_parameter('timezone'); if (empty($timezone) === true || config_update_value('timezone', $timezone, true) === false) { $error_update[] = __('Timezone setup'); @@ -1501,8 +1519,13 @@ function config_update_config() break; case 'net': - if (config_update_value('netflow_path', get_parameter('netflow_path'), true) === false) { - $error_update[] = __('Data storage path'); + if (config_update_value('netflow_name_dir', get_parameter('netflow_name_dir'), true) === false) { + $error_update[] = __('Name storage path'); + } else { + if (empty($config['general_network_path']) === false && $config['general_network_path'] !== '') { + $name = get_parameter('netflow_name_dir'); + config_update_value('netflow_path', $config['general_network_path'].$name); + } } if (config_update_value('netflow_interval', (int) get_parameter('netflow_interval'), true) === false) { @@ -1538,6 +1561,49 @@ function config_update_config() } break; + case 'sflow': + if (config_update_value('sflow_name_dir', get_parameter('sflow_name_dir'), true) === false) { + $error_update[] = __('Sflow name dir'); + } else { + if (empty($config['general_network_path']) === false && $config['general_network_path'] !== '') { + $name = get_parameter('sflow_name_dir'); + config_update_value('sflow_path', $config['general_network_path'].$name); + } + } + + if (config_update_value('sflow_interval', (int) get_parameter('sflow_interval'), true) === false) { + $error_update[] = __('Daemon interval'); + } + + if (config_update_value('sflow_daemon', get_parameter('sflow_daemon'), true) === false) { + $error_update[] = __('Daemon binary path'); + } + + if (config_update_value('sflow_nfdump', get_parameter('sflow_nfdump'), true) === false) { + $error_update[] = __('Nfdump binary path'); + } + + if (config_update_value('sflow_nfexpire', get_parameter('sflow_nfexpire'), true) === false) { + $error_update[] = __('Nfexpire binary path'); + } + + if (config_update_value('sflow_max_resolution', (int) get_parameter('sflow_max_resolution'), true) === false) { + $error_update[] = __('Maximum chart resolution'); + } + + if (config_update_value('sflow_disable_custom_lvfilters', get_parameter('sflow_disable_custom_lvfilters'), true) === false) { + $error_update[] = __('Disable custom live view filters'); + } + + if (config_update_value('sflow_max_lifetime', (int) get_parameter('sflow_max_lifetime'), true) === false) { + $error_update[] = __('Sflow max lifetime'); + } + + if (config_update_value('sflow_get_ip_hostname', (int) get_parameter('sflow_get_ip_hostname'), true) === false) { + $error_update[] = __('Name resolution for IP address'); + } + break; + case 'log': if (config_update_value('elasticsearch_ip', get_parameter('elasticsearch_ip'), true) === false) { $error_update[] = __('IP ElasticSearch server'); @@ -2768,6 +2834,28 @@ function config_process_config() config_update_value('activate_netflow', 0); } + if (!isset($config['activate_sflow'])) { + config_update_value('activate_sflow', 0); + } + + if (!isset($config['general_network_path'])) { + if ($is_windows) { + $default = 'C:\PandoraFMS\Pandora_Server\data_in\\'; + } else { + $default = '/var/spool/pandora/data_in/'; + } + + config_update_value('general_network_path', $default); + } + + if (!isset($config['netflow_name_dir'])) { + config_update_value('netflow_name_dir', 'netflow'); + } + + if (!isset($config['sflow_name_dir'])) { + config_update_value('sflow_name_dir', 'sflow'); + } + if (!isset($config['netflow_path'])) { if ($is_windows) { $default = 'C:\PandoraFMS\Pandora_Server\data_in\netflow'; @@ -2806,6 +2894,48 @@ function config_process_config() config_update_value('netflow_max_lifetime', '5'); } + if (!isset($config['sflow_interval'])) { + config_update_value('sflow_interval', SECONDS_10MINUTES); + } + + if (!isset($config['sflow_daemon'])) { + config_update_value('sflow_daemon', '/usr/bin/nfcapd'); + } + + if (!isset($config['sflow_nfdump'])) { + config_update_value('sflow_nfdump', '/usr/bin/nfdump'); + } + + if (!isset($config['sflow_nfexpire'])) { + config_update_value('sflow_nfexpire', '/usr/bin/nfexpire'); + } + + if (!isset($config['sflow_max_resolution'])) { + config_update_value('sflow_max_resolution', '50'); + } + + if (!isset($config['sflow_disable_custom_lvfilters'])) { + config_update_value('sflow_disable_custom_lvfilters', 0); + } + + if (!isset($config['sflow_max_lifetime'])) { + config_update_value('sflow_max_lifetime', '5'); + } + + if (!isset($config['sflow_name_dir'])) { + config_update_value('sflow_name_dir', 'sflow'); + } + + if (!isset($config['sflow_path'])) { + if ($is_windows) { + $default = 'C:\PandoraFMS\Pandora_Server\data_in\sflow'; + } else { + $default = '/var/spool/pandora/data_in/sflow'; + } + + config_update_value('sflow_path', $default); + } + if (!isset($config['auth'])) { config_update_value('auth', 'mysql'); } diff --git a/pandora_console/include/functions_netflow.php b/pandora_console/include/functions_netflow.php index e4ac71e690..be271ef974 100644 --- a/pandora_console/include/functions_netflow.php +++ b/pandora_console/include/functions_netflow.php @@ -1025,9 +1025,29 @@ function netflow_get_command($options, $filter) // Build command. $command = io_safe_output($config['netflow_nfdump']).' -N'; - // Netflow data path. - if (isset($config['netflow_path']) && $config['netflow_path'] != '') { - $command .= ' -R. -M '.$config['netflow_path']; + if ($config['activate_sflow'] && $config['activate_netflow']) { + if (isset($config['sflow_name_dir']) && $config['sflow_name_dir'] !== '' + && isset($config['netflow_name_dir']) && $config['netflow_name_dir'] !== '' + && isset($config['general_network_path']) && $config['general_network_path'] !== '' + ) { + $command .= ' -R. -M '.$config['general_network_path'].$config['netflow_name_dir'].':'.$config['sflow_name_dir']; + } + } else { + if ($config['activate_sflow']) { + if (isset($config['sflow_name_dir']) && $config['sflow_name_dir'] !== '' + && isset($config['general_network_path']) && $config['general_network_path'] !== '' + ) { + $command .= ' -R. -M '.$config['general_network_path'].$config['sflow_name_dir']; + } + } + + if ($config['activate_netflow']) { + if (isset($config['netflow_name_dir']) && $config['netflow_name_dir'] !== '' + && isset($config['general_network_path']) && $config['general_network_path'] !== '' + ) { + $command .= ' -R. -M '.$config['general_network_path'].$config['netflow_name_dir']; + } + } } // Add options. @@ -1035,7 +1055,7 @@ function netflow_get_command($options, $filter) // Filter options. $command .= ' '.netflow_get_filter_arguments($filter); - + hd($command, true); return $command; } diff --git a/pandora_console/operation/menu.php b/pandora_console/operation/menu.php index 62984b4078..7dd1126cd9 100644 --- a/pandora_console/operation/menu.php +++ b/pandora_console/operation/menu.php @@ -205,7 +205,7 @@ if ($access_console_node === true) { $sub['operation/inventory/inventory']['refr'] = 0; } - if ($config['activate_netflow']) { + if ($config['activate_netflow'] || $config['activate_sflow']) { $sub['network_traffic'] = [ 'text' => __('Network'), 'id' => 'Network', @@ -213,34 +213,20 @@ if ($access_console_node === true) { 'subtype' => 'nolink', 'refr' => 0, ]; - - // Initialize the submenu. - $netflow_sub = []; - - $netflow_sub = array_merge( - $netflow_sub, - [ - 'operation/netflow/netflow_explorer' => [ - 'text' => __('Netflow explorer'), - 'id' => 'Netflow explorer', - ], - 'operation/netflow/nf_live_view' => [ - 'text' => __('Netflow Live View'), - 'id' => 'Netflow Live View', - ], - ] - ); - - $netflow_sub = array_merge( - $netflow_sub, - [ - 'operation/network/network_usage_map' => [ - 'text' => __('Network usage map'), - 'id' => 'Network usage map', - ], - ] - ); - + $netflow_sub = [ + 'operation/netflow/netflow_explorer' => [ + 'text' => __('Netflow explorer'), + 'id' => 'Netflow explorer', + ], + 'operation/netflow/nf_live_view' => [ + 'text' => __('Netflow Live View'), + 'id' => 'Netflow Live View', + ], + 'operation/network/network_usage_map' => [ + 'text' => __('Network usage map'), + 'id' => 'Network usage map', + ], + ]; $sub['network_traffic']['sub2'] = $netflow_sub; } diff --git a/pandora_console/pandoradb_data.sql b/pandora_console/pandoradb_data.sql index acb6636dca..f79f17b8cd 100644 --- a/pandora_console/pandoradb_data.sql +++ b/pandora_console/pandoradb_data.sql @@ -72,6 +72,8 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('stats_interval', '60'), ('activate_gis', '0'), ('activate_netflow', '0'), +('activate_sflow', '0'), +('general_network_path', '/var/spool/pandora/data_in/'), ('timezone', 'Europe/Berlin'), ('string_purge', 7), ('audit_purge', 15), @@ -87,6 +89,10 @@ INSERT INTO `tconfig` (`token`, `value`) VALUES ('netflow_daemon', '/usr/bin/nfcapd'), ('netflow_nfdump', '/usr/bin/nfdump'), ('netflow_max_resolution', '50'), +('sflow_interval', '3600'), +('sflow_daemon', '/usr/bin/nfcapd'), +('sflow_nfdump', '/usr/bin/nfdump'), +('sflow_max_resolution', '50'), ('event_fields', 'mini_severity,evento,estado,agent_name,timestamp'), ('status_monitor_fields', 'policy,agent,data_type,module_name,server_type,interval,status,last_status_change,graph,warn,data,timestamp'), ('list_ACL_IPs_for_API', '127.0.0.1'),