From f3272eb3dfca58b216f57841c41c998c4e017f0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Thu, 5 May 2022 17:36:07 +0200 Subject: [PATCH 1/6] Applied fix for snmp --- pandora_console/include/class/AgentWizard.class.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index bc34fa5258..df9299078f 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -3572,7 +3572,12 @@ class AgentWizard extends HTML if ($full_output === true) { $output[] = $key.' = '.$oid_unit; } else { - preg_match('/\.\d+$/', $key, $index); + $index = []; + $index[] = preg_replace('/^'.$oid.'/', '', $key); + if (empty($index) === true) { + preg_match('/\.\d+$/', $key, $index); + } + $tmp = explode(': ', $oid_unit); $output[$index[0]] = str_replace('"', '', ($tmp[1] ?? '')); } From dfc4786ef187a9063412c91bbac995e6c177ff8f Mon Sep 17 00:00:00 2001 From: Calvo Date: Fri, 6 May 2022 13:35:04 +0200 Subject: [PATCH 2/6] Changed snmpwalk parameters for wizard --- .../modules/manage_network_components_form_wizard.php | 1 + pandora_console/include/class/AgentWizard.class.php | 3 ++- pandora_console/include/functions.php | 11 ++++++----- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/modules/manage_network_components_form_wizard.php b/pandora_console/godmode/modules/manage_network_components_form_wizard.php index 0fa9d763c5..15b8f2a508 100644 --- a/pandora_console/godmode/modules/manage_network_components_form_wizard.php +++ b/pandora_console/godmode/modules/manage_network_components_form_wizard.php @@ -178,6 +178,7 @@ switch ($type) { break; } +$query_filter = []; if (empty($query_filter) === false) { $query_filter = json_decode($query_filter, true); } diff --git a/pandora_console/include/class/AgentWizard.class.php b/pandora_console/include/class/AgentWizard.class.php index bc34fa5258..671142817f 100644 --- a/pandora_console/include/class/AgentWizard.class.php +++ b/pandora_console/include/class/AgentWizard.class.php @@ -3559,7 +3559,8 @@ class AgentWizard extends HTML $this->targetPort, $this->server, $this->extraArguments, - (($full_output === false) ? '-Oa -On' : '-Oa') + (($full_output === false) ? '-On' : '-Oa'), + '' ); if ($pure === true) { diff --git a/pandora_console/include/functions.php b/pandora_console/include/functions.php index ca0c9dad7d..172b8de169 100644 --- a/pandora_console/include/functions.php +++ b/pandora_console/include/functions.php @@ -1993,7 +1993,8 @@ function get_snmpwalk( $snmp_port='', $server_to_exec=0, $extra_arguments='', - $format='-Oa' + $format='-Oa', + $load_mibs='-m ALL' ) { global $config; @@ -2057,15 +2058,15 @@ function get_snmpwalk( case '3': switch ($snmp3_security_level) { case 'authNoPriv': - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; case 'noAuthNoPriv': - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -l '.escapeshellarg($snmp3_security_level).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; default: - $command_str = $snmpwalk_bin.' -m ALL '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$format.' '.$extra_arguments.' -v 3'.' -u '.escapeshellarg($snmp3_auth_user).' -A '.escapeshellarg($snmp3_auth_pass).' -l '.escapeshellarg($snmp3_security_level).' -a '.escapeshellarg($snmp3_auth_method).' -x '.escapeshellarg($snmp3_privacy_method).' -X '.escapeshellarg($snmp3_privacy_pass).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } break; @@ -2074,7 +2075,7 @@ function get_snmpwalk( case '2c': case '1': default: - $command_str = $snmpwalk_bin.' -m ALL '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; + $command_str = $snmpwalk_bin.' '.$load_mibs.' '.$extra_arguments.' '.$format.' -v '.escapeshellarg($snmp_version).' -c '.escapeshellarg(io_safe_output($snmp_community)).' '.escapeshellarg($ip_target).' '.$base_oid.' 2> '.$error_redir_dir; break; } From 15d92d5cd6c8ecfac04dfaf645f5dc215386d151 Mon Sep 17 00:00:00 2001 From: Daniel Maya Date: Wed, 11 May 2022 13:51:16 +0200 Subject: [PATCH 3/6] #8517 Fixed module name --- pandora_server/lib/PandoraFMS/Recon/Base.pm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pandora_server/lib/PandoraFMS/Recon/Base.pm b/pandora_server/lib/PandoraFMS/Recon/Base.pm index f0b70cd0df..66d47a782a 100644 --- a/pandora_server/lib/PandoraFMS/Recon/Base.pm +++ b/pandora_server/lib/PandoraFMS/Recon/Base.pm @@ -1628,9 +1628,14 @@ sub database_scan($$$) { $self->{'summary'}->{'discovered'} += 1; $self->{'summary'}->{'alive'} += 1; + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 1, description => $type . ' availability' @@ -1778,8 +1783,14 @@ sub app_scan($) { # Update progress $self->call('update_progress', $global_percent + (90 / (scalar @targets))); $self->{'summary'}->{'not_alive'} += 1; + + my $name = $type . ' connection'; + if (defined $obj->{'prefix_module_name'} && $obj->{'prefix_module_name'} ne '') { + $name = $obj->{'prefix_module_name'} . $type . ' connection'; + } + push @modules, { - name => $type . ' connection', + name => $name, type => 'generic_proc', data => 0, description => $type . ' availability' From 0a99b608c5d04477b36a94f32b7fdb6552708ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Gonz=C3=A1lez?= Date: Wed, 25 May 2022 17:53:58 +0200 Subject: [PATCH 4/6] Fix several issues with SNMP Alert view --- .../godmode/snmpconsole/snmp_alert.php | 782 ++++++++++-------- pandora_console/include/styles/pandora.css | 7 + 2 files changed, 449 insertions(+), 340 deletions(-) diff --git a/pandora_console/godmode/snmpconsole/snmp_alert.php b/pandora_console/godmode/snmpconsole/snmp_alert.php index 6829d445e1..35fcaf172c 100755 --- a/pandora_console/godmode/snmpconsole/snmp_alert.php +++ b/pandora_console/godmode/snmpconsole/snmp_alert.php @@ -1,8 +1,20 @@ __('Other'), ]; -// Form submitted -// ============= +// Form submitted. $update_alert = (bool) get_parameter('update_alert', false); $create_alert = (bool) get_parameter('create_alert', false); $save_alert = (bool) get_parameter('save_alert', false); $modify_alert = (bool) get_parameter('modify_alert', false); $delete_alert = (bool) get_parameter('delete_alert', false); $multiple_delete = (bool) get_parameter('multiple_delete', false); -$add_action = (bool) get_parameter('add_alert', 0); +$add_action = (bool) get_parameter('add_alert', false); $delete_action = get_parameter('delete_action', 0); $duplicate_alert = get_parameter('duplicate_alert', 0); -if ($add_action) { +if ($add_action === true) { $values['id_alert_snmp'] = (int) get_parameter('id_alert_snmp'); $values['alert_type'] = (int) get_parameter('alert_type'); $values[db_escape_key_identifier('al_field1')] = get_parameter('field1_value'); @@ -79,37 +91,41 @@ if ($delete_action) { } if ($update_alert || $modify_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Update alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_update_tab', - false - ); + $subTitle = __('Update alert'); + $helpString = 'snmp_alert_update_tab'; } else if ($create_alert || $save_alert) { - ui_print_page_header( - __('SNMP Console').' » '.__('Create alert'), - 'images/op_snmp.png', - false, - 'snmp_alert_overview_tab', - false - ); + $subTitle = __('Create alert'); + $helpString = 'snmp_alert_overview_tab'; } else { - ui_print_page_header( - __('SNMP Console').' » '.__('Alert overview'), - 'images/op_snmp.png', - false, - '', - false - ); + $subTitle = __('Alert overview'); + $helpString = ''; } +ui_print_standard_header( + $subTitle, + 'images/op_snmp.png', + false, + $helpString, + false, + [], + [ + [ + 'link' => '', + 'label' => __('Alerts'), + ], + [ + 'link' => '', + 'label' => __('SNMP Console'), + ], + ] +); + if ($save_alert || $modify_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); $source_ip = (string) get_parameter_post('source_ip'); $alert_type = (int) get_parameter_post('alert_type'); - // Event, e-mail + // Event, e-mail. $description = (string) get_parameter_post('description'); $oid = (string) get_parameter_post('oid'); $custom_value = (string) get_parameter_post('custom_value'); @@ -269,7 +285,7 @@ if ($save_alert || $modify_alert) { $result = db_process_sql_insert('talert_snmp', $values); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, 'Fail try to create snmp alert' @@ -278,7 +294,10 @@ if ($save_alert || $modify_alert) { } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Create snmp alert #$result" + sprintf( + 'Create snmp alert #%s', + $result + ) ); ui_print_success_message(__('Successfully created')); } @@ -405,24 +424,29 @@ if ($save_alert || $modify_alert) { $result = db_process_sql($sql); - if (!$result) { + if ((bool) $result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to update snmp alert #$id_as" + sprintf( + 'Fail try to update snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem updating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Update snmp alert #$id_as" + sprintf( + 'Update snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully updated')); } } } -// From variable init -// ================== +// From variable init. if ($update_alert || $duplicate_alert) { $id_as = (int) get_parameter('id_alert_snmp', -1); @@ -516,11 +540,11 @@ if ($update_alert || $duplicate_alert) { return; } } else if ($create_alert) { - // Variable init + // Variable init. $id_as = -1; $source_ip = ''; $alert_type = 1; - // Event, e-mail + // Event, e-mail. $description = ''; $oid = ''; $custom_value = ''; @@ -595,40 +619,46 @@ if ($update_alert || $duplicate_alert) { $group = 0; } -// Duplicate alert snmp +// Duplicate alert snmp. if ($duplicate_alert) { $values_duplicate = $alert; - if (!empty($values_duplicate)) { + if (empty($values_duplicate) === false) { unset($values_duplicate['id_as']); $result = db_process_sql_insert('talert_snmp', $values_duplicate); if (!$result) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Duplicate snmp alert #$id_as" + sprintf( + 'Duplicate snmp alert #%s', + $id_as + ) ); ui_print_success_message(__('Successfully Duplicate')); } } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to duplicate snmp alert #$id_as" + sprintf( + 'Fail try to duplicate snmp alert #%s', + $id_as + ) ); ui_print_error_message(__('There was a problem duplicating the alert')); } } -// Header -// Alert Delete -// ============= if ($delete_alert) { - // Delete alert + // Delete alert. $alert_delete = (int) get_parameter_get('delete_alert', 0); $result = db_process_sql_delete( @@ -639,13 +669,19 @@ if ($delete_alert) { if ($result === false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); ui_print_error_message(__('There was a problem deleting the alert')); } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); ui_print_success_message(__('Successfully deleted')); } @@ -666,18 +702,24 @@ if ($multiple_delete) { if ($result !== false) { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Delete snmp alert #$alert_delete" + sprintf( + 'Delete snmp alert #%s', + $alert_delete + ) ); $count++; } else { db_pandora_audit( AUDIT_LOG_SNMP_MANAGEMENT, - "Fail try to delete snmp alert #$alert_delete" + sprintf( + 'Fail try to delete snmp alert #%s', + $alert_delete + ) ); } } - if ($count == $total) { + if ($count === $total) { ui_print_success_message( __('Successfully deleted alerts (%s / %s)', $count, $total) ); @@ -692,7 +734,7 @@ $user_groups = users_get_groups($config['id_user'], 'AR', true); $str_user_groups = ''; $i = 0; foreach ($user_groups as $id => $name) { - if ($i == 0) { + if ($i === 0) { $str_user_groups .= $id; } else { $str_user_groups .= ','.$id; @@ -701,10 +743,9 @@ foreach ($user_groups as $id => $name) { $i++; } -// Alert form +// Alert form. if ($create_alert || $update_alert) { - // if (isset ($_GET["update_alert"])) { - // the update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated + // The update_alert means the form should be displayed. If update_alert > 1 then an existing alert is updated. echo '
'; html_print_input_hidden('id_alert_snmp', $id_as); @@ -717,32 +758,39 @@ if ($create_alert || $update_alert) { html_print_input_hidden('modify_alert', 1); } - // SNMP alert filters + // SNMP alert filters. echo ''; - // Description - echo ''.''.''.''; + // Description. + echo ''; + echo ''; + echo ''; + echo ''; - // echo ''; - // OID - echo ''.''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Custom + // Custom. echo ''; + echo ''; + echo ''; - // SNMP Agent + // SNMP Agent. echo ''; + echo ''; + echo ''; $return_all_group = false; @@ -750,7 +798,7 @@ if ($create_alert || $update_alert) { $return_all_group = true; } - // Group + // Group. echo ''; + echo ''; + echo ''; - // Trap type + // Trap type. echo ''; + echo ''; + echo ''; - // Single value + // Single value. echo ''; + echo ''; + echo ''; - // Variable bindings/Data #1 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #2 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #3 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #4 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #5 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #6 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #7 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #8 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #9 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #10 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #11 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #12 - echo ''.''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #13 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #14 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #15 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #16 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #17 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #18 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #19 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Variable bindings/Data #20 - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; - // Alert fields + // Alert fields. $al = [ 'al_field1' => $al_field1, 'al_field2' => $al_field2, @@ -974,7 +1061,7 @@ if ($create_alert || $update_alert) { 'al_field20' => $al_field20, ]; - // Hidden div with help hint to fill with javascript + // Hidden div with help hint to fill with javascript. html_print_div(['id' => 'help_snmp_alert_hint', 'content' => ui_print_help_icon('snmp_alert_field1', true), 'hidden' => true]); for ($i = 1; $i <= $config['max_macro_fields']; $i++) { @@ -984,7 +1071,7 @@ if ($create_alert || $update_alert) { echo ''; } - // Max / Min alerts + // Max / Min alerts. echo ''; - // Time Threshold + // Time Threshold. echo ''; - // Priority + // Priority. echo ''; @@ -1048,10 +1135,11 @@ if ($create_alert || $update_alert) { echo "
'.__('Description').''; - html_print_textarea('description', 3, 2, $description, 'class="w400px"'); - echo '
'.__('Description').''; + html_print_textarea('description', 3, 2, $description, 'class="w400px"'); + echo '
' . __('Alert filters') . ui_print_help_icon("snmp_alert_filters", true) . '
'.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; + // OID. + echo '
'.__('Enterprise String').ui_print_help_tip(__('Matches substrings. End the string with $ for exact matches.'), true).''; html_print_input_text('oid', $oid, '', 50, 255); - echo '
'.__('Custom Value/OID'); echo ''; html_print_textarea('custom_value', 2, 2, $custom_value, 'class="w400px"'); - echo '
'.__('SNMP Agent').' (IP)'; html_print_input_text('source_ip', $source_ip, '', 20); - echo '
'.__('Group').''; echo '
'; html_print_select_groups( @@ -774,183 +822,222 @@ if ($create_alert || $update_alert) { false ); echo '
'; - echo '
'.__('Trap type').''; echo html_print_select($trap_types, 'trap_type', $trap_type, '', '', '', false, false, false); - echo '
'.__('Single value').''; html_print_input_text('single_value', $single_value, '', 20); - echo '
'.__('Variable bindings/Data').''; + // Variable bindings/Data #1. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_1', $order_1, '', 4); html_print_input_text('custom_oid_data_1', $custom_oid_data_1, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #2. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_2', $order_2, '', 4); html_print_input_text('custom_oid_data_2', $custom_oid_data_2, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #3. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_3', $order_3, '', 4); html_print_input_text('custom_oid_data_3', $custom_oid_data_3, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #4. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_4', $order_4, '', 4); html_print_input_text('custom_oid_data_4', $custom_oid_data_4, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #5. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_5', $order_5, '', 4); html_print_input_text('custom_oid_data_5', $custom_oid_data_5, '', 60); - echo '
'.__('Variable bindings/Data'); - // echo ui_print_help_icon ("snmp_alert_custom", true); - echo ''; + // Variable bindings/Data #6. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_6', $order_6, '', 4); html_print_input_text('custom_oid_data_6', $custom_oid_data_6, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #7. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_7', $order_7, '', 4); html_print_input_text('custom_oid_data_7', $custom_oid_data_7, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #8. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_8', $order_8, '', 4); html_print_input_text('custom_oid_data_8', $custom_oid_data_8, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #9. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_9', $order_9, '', 4); html_print_input_text('custom_oid_data_9', $custom_oid_data_9, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #10. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_10', $order_10, '', 4); html_print_input_text('custom_oid_data_10', $custom_oid_data_10, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #11. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_11', $order_11, '', 4); html_print_input_text('custom_oid_data_11', $custom_oid_data_11, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #12. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_12', $order_12, '', 4); html_print_input_text('custom_oid_data_12', $custom_oid_data_12, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #13. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_13', $order_13, '', 4); html_print_input_text('custom_oid_data_13', $custom_oid_data_13, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #14. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_14', $order_14, '', 4); html_print_input_text('custom_oid_data_14', $custom_oid_data_14, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #15. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_15', $order_15, '', 4); html_print_input_text('custom_oid_data_15', $custom_oid_data_15, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #16. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_16', $order_16, '', 4); html_print_input_text('custom_oid_data_16', $custom_oid_data_16, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #17. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_17', $order_17, '', 4); html_print_input_text('custom_oid_data_17', $custom_oid_data_17, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #18. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_18', $order_18, '', 4); html_print_input_text('custom_oid_data_18', $custom_oid_data_18, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #19. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_19', $order_19, '', 4); html_print_input_text('custom_oid_data_19', $custom_oid_data_19, '', 60); - echo '
'.__('Variable bindings/Data'); - echo ''; + // Variable bindings/Data #20. + echo '
'.__('Variable bindings/Data').''; echo '#'; html_print_input_text('order_20', $order_20, '', 4); html_print_input_text('custom_oid_data_20', $custom_oid_data_20, '', 60); - echo '
'.__('Min. number of alerts').''; html_print_input_text('min_alerts', $min_alerts, '', 3); @@ -992,7 +1079,7 @@ if ($create_alert || $update_alert) { html_print_input_text('max_alerts', $max_alerts, '', 3); echo '
'.__('Time threshold').''; $fields = []; @@ -1014,7 +1101,7 @@ if ($create_alert || $update_alert) { html_print_input_text('time_other', 0, '', 6); echo ' '.__('seconds').'
'.__('Priority').''; echo html_print_select(get_priorities(), 'priority', $priority, '', '', '0', false, false, false); echo '
"; echo '
'; + html_print_button(__('Back'), 'button_back', false, '', 'class="sub cancel margin-right-05"'); if ($id_as > 0) { - html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"', false); + html_print_submit_button(__('Update'), 'submit', false, 'class="sub upd"'); } else { - html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"', false); + html_print_submit_button(__('Create'), 'submit', false, 'class="sub wand"'); } echo '
'; @@ -1089,119 +1177,68 @@ if ($create_alert || $update_alert) { $form_filter .= ''; $form_filter .= '
'; - // echo "
"; ui_toggle($form_filter, __('Alert SNMP control filter'), __('Toggle filter(s)')); $filter = []; $offset = (int) get_parameter('offset'); $limit = (int) $config['block_size']; if ($filter_param) { - // Move the first page + // Move the first page. $offset = 0; - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter; } else { - $url_pagination = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'free_search='.$free_search.'&'.'trap_type_filter='.$trap_type_filter.'&'.'priority_filter='.$priority_filter.'&'.'offset='.$offset; + $url_pagination = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&free_search='.$free_search.'&trap_type_filter='.$trap_type_filter.'&priority_filter='.$priority_filter.'&offset='.$offset; } $where_sql = ''; - if (!empty($free_search)) { - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND `trap_type` = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND `priority` = '.$priority_filter; - } - - $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' - OR `_snmp_f10_` LIKE '%".$free_search."%' - OR `_snmp_f9_` LIKE '%".$free_search."%' - OR `_snmp_f8_` LIKE '%".$free_search."%' - OR `_snmp_f7_` LIKE '%".$free_search."%' - OR `_snmp_f6_` LIKE '%".$free_search."%' - OR `_snmp_f5_` LIKE '%".$free_search."%' - OR `_snmp_f4_` LIKE '%".$free_search."%' - OR `_snmp_f3_` LIKE '%".$free_search."%' - OR `_snmp_f2_` LIKE '%".$free_search."%' - OR `_snmp_f1_` LIKE '%".$free_search."%' - OR `oid` LIKE '%".$free_search."%' - OR `custom_oid` LIKE '%".$free_search."%' - OR `agent` LIKE '%".$free_search."%' - OR `description` LIKE '%".$free_search."%')"; - break; - - case 'oracle': - // $where_sql = ' 1 = 1'; - if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { - $where_sql .= ' AND trap_type = '.$trap_type_filter; - } - - if ($priority_filter != -1) { - $where_sql .= ' AND priority = '.$priority_filter; - } - - $where_sql .= " AND (single_value LIKE '%".$free_search."%' - OR \"_snmp_f10_\" LIKE '%".$free_search."%' - OR \"_snmp_f9_\" LIKE '%".$free_search."%' - OR \"_snmp_f8_\" LIKE '%".$free_search."%' - OR \"_snmp_f7_\" LIKE '%".$free_search."%' - OR \"_snmp_f6_\" LIKE '%".$free_search."%' - OR \"_snmp_f5_\" LIKE '%".$free_search."%' - OR \"_snmp_f4_\" LIKE '%".$free_search."%' - OR \"_snmp_f3_\" LIKE '%".$free_search."%' - OR \"_snmp_f2_\" LIKE '%".$free_search."%' - OR \"_snmp_f1_\" LIKE '%".$free_search."%' - OR oid LIKE '%".$free_search."%' - OR custom_oid LIKE '%".$free_search."%' - OR agent LIKE '%".$free_search."%' - OR description LIKE '%".$free_search."%')"; - break; + if (empty($free_search) === false) { + if ($trap_type_filter != SNMP_TRAP_TYPE_NONE) { + $where_sql .= ' AND `trap_type` = '.$trap_type_filter; } + + if ($priority_filter != -1) { + $where_sql .= ' AND `priority` = '.$priority_filter; + } + + $where_sql .= " AND (`single_value` LIKE '%".$free_search."%' + OR `_snmp_f10_` LIKE '%".$free_search."%' + OR `_snmp_f9_` LIKE '%".$free_search."%' + OR `_snmp_f8_` LIKE '%".$free_search."%' + OR `_snmp_f7_` LIKE '%".$free_search."%' + OR `_snmp_f6_` LIKE '%".$free_search."%' + OR `_snmp_f5_` LIKE '%".$free_search."%' + OR `_snmp_f4_` LIKE '%".$free_search."%' + OR `_snmp_f3_` LIKE '%".$free_search."%' + OR `_snmp_f2_` LIKE '%".$free_search."%' + OR `_snmp_f1_` LIKE '%".$free_search."%' + OR `oid` LIKE '%".$free_search."%' + OR `custom_oid` LIKE '%".$free_search."%' + OR `agent` LIKE '%".$free_search."%' + OR `description` LIKE '%".$free_search."%')"; } - $count = db_get_value_sql( - "SELECT COUNT(*) - FROM talert_snmp WHERE id_group IN ($str_user_groups) ".$where_sql + $count = (int) db_get_value_sql( + 'SELECT COUNT(*) + FROM talert_snmp WHERE id_group IN ('.$str_user_groups.') '.$where_sql ); $result = []; - // Overview - if ($count == 0) { + // Overview. + if ($count === 0) { $result = []; ui_print_info_message(['no_close' => true, 'message' => __('There are no SNMP alerts') ]); } else { ui_pagination($count, $url_pagination); - switch ($config['dbtype']) { - case 'mysql': - case 'postgresql': - $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; - $result = db_get_all_rows_sql( - "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql - ); - break; - case 'oracle': - $sql = "SELECT * - FROM talert_snmp - WHERE id_group IN ($str_user_groups) ".$where_sql; - $set = []; - if (isset($offset) && isset($limit)) { - $set['limit'] = $limit; - $set['offset'] = $offset; - } - - $result = oracle_recode_query($sql, $set, 'AND', false); - break; - } + $where_sql .= ' LIMIT '.$limit.' OFFSET '.$offset; + $result = db_get_all_rows_sql( + 'SELECT * + FROM talert_snmp + WHERE id_group IN ('.$str_user_groups.') '.$where_sql + ); } $table = new stdClass(); @@ -1250,7 +1287,7 @@ if ($create_alert || $update_alert) { $data = []; $data[0] = $row['position']; - $url = 'index.php?'.'sec=snmpconsole&'.'sec2=godmode/snmpconsole/snmp_alert&'.'id_alert_snmp='.$row['id_as'].'&'.'update_alert=1'; + $url = 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&id_alert_snmp='.$row['id_as'].'&update_alert=1'; $data[1] = ''; $data[1] .= ''; @@ -1281,50 +1318,86 @@ if ($create_alert || $update_alert) { } $data[1] .= '
'; - - $data[2] = $row['agent']; $data[3] = $row['oid']; $data[4] = $row['custom_oid']; $data[5] = $row['description']; $data[6] = $row['times_fired']; - if (($row['last_fired'] != '1970-01-01 00:00:00') and ($row['last_fired'] != '01-01-1970 00:00:00')) { + if (($row['last_fired'] !== '1970-01-01 00:00:00') && ($row['last_fired'] !== '01-01-1970 00:00:00')) { $data[7] = ui_print_timestamp($row['last_fired'], true); } else { $data[7] = __('Never'); } - if (check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW')) { - $data[8] = ''.html_print_image( - 'images/copy.png', - true, - [ - 'alt' => __('Duplicate'), - 'title' => __('Duplicate'), - ] - ).''.''.html_print_image( - 'images/config.png', - true, - [ - 'border' => '0', - 'alt' => __('Update'), - ] - ).''.''.html_print_image( - 'images/add.png', - true, - [ - 'title' => __('Add action'), - ] - ).''.''.html_print_image( - 'images/cross.png', - true, - [ - 'border' => '0', - 'alt' => __('Delete'), - ] - ).''; + $data[8] = ''; + $data[9] = ''; + if ((bool) check_acl_restricted_all($config['id_user'], $row['id_group'], 'LW') === true) { + $data[8] = html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&duplicate_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/copy.png', + true, + [ + 'alt' => __('Duplicate'), + 'title' => __('Duplicate'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'index.php?sec=snmpconsole&sec2=godmode/snmpconsole/snmp_alert&update_alert=1&id_alert_snmp=%s', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/config.png', + true, + [ + 'alt' => __('Update'), + 'border' => 0, + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => sprintf( + 'javascript:show_add_action_snmp(\'%s\');"', + $row['id_as'] + ), + 'content' => html_print_image( + 'images/add.png', + true, + [ + 'title' => __('Add action'), + ] + ), + ], + true + ); + $data[8] .= html_print_anchor( + [ + 'href' => 'javascript: ', + 'content' => html_print_image( + 'images/cross.png', + true, + [ + 'title' => __('Delete action'), + ] + ), + 'onClick' => 'delete_snmp_alert('.$row['id_as'].')', + ], + true + ); $data[9] = html_print_checkbox_extended( 'delete_ids[]', @@ -1335,71 +1408,47 @@ if ($create_alert || $update_alert) { 'class="chk_delete"', true ); - } else { - $data[8] = ''; - $data[9] = ''; } $idx = count($table->data); - // The current index of the table is 1 less than the count of table data so we count before adding to table->data + // The current index of the table is 1 less than the count of table data so we count before adding to table->data. array_push($table->data, $data); $table->rowclass[$idx] = get_priority_class($row['priority']); } - // DIALOG ADD MORE ACTIONS + // DIALOG ADD MORE ACTIONS. echo '