From 7bd5851667b01318e083cc62075b31a76d70f113 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Tue, 19 Feb 2019 13:04:57 +0100 Subject: [PATCH 1/2] Add support for column macros. Former-commit-id: 8b826854c288754feefdbe270701655c6bbbfac9 --- .../agentes/module_manager_editor_network.php | 8 ++--- .../agentes/module_manager_editor_wmi.php | 4 +-- .../include/help/en/help_column_macros.php | 14 ++++++++ .../include/help/es/help_column_macros.php | 13 +++++++ .../include/help/ja/help_column_macros.php | 15 ++++++++ pandora_server/lib/PandoraFMS/Core.pm | 34 +++++++++++++++---- .../lib/PandoraFMS/NetworkServer.pm | 14 +++++--- pandora_server/lib/PandoraFMS/WMIServer.pm | 12 +++++-- 8 files changed, 95 insertions(+), 19 deletions(-) create mode 100644 pandora_console/include/help/en/help_column_macros.php create mode 100644 pandora_console/include/help/es/help_column_macros.php create mode 100644 pandora_console/include/help/ja/help_column_macros.php diff --git a/pandora_console/godmode/agentes/module_manager_editor_network.php b/pandora_console/godmode/agentes/module_manager_editor_network.php index 0eb5fad7cd..11402c8ca6 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_network.php +++ b/pandora_console/godmode/agentes/module_manager_editor_network.php @@ -128,7 +128,7 @@ $snmp_versions['2c'] = 'v. 2c'; $snmp_versions['3'] = 'v. 3'; $data = []; -$data[0] = __('SNMP community'); +$data[0] = __('SNMP community').ui_print_help_icon('column_macros', true); $adopt = false; if ($isFunctionPolicies !== ENTERPRISE_NOT_HOOK && isset($id_agent_module)) { $adopt = policies_is_module_adopt($id_agent_module); @@ -277,7 +277,7 @@ if (!isset($id_agent_module)) { } $data = []; -$data[0] = __('Auth user'); +$data[0] = __('Auth user').ui_print_help_icon('column_macros', true); $data[1] = html_print_input_text( 'snmp3_auth_user', $snmp3_auth_user, @@ -290,7 +290,7 @@ $data[1] = html_print_input_text( '', $classdisabledBecauseInPolicy ); -$data[2] = __('Auth password').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); +$data[2] = __('Auth password').ui_print_help_icon('column_macros', true).ui_print_help_tip(__('The pass length must be eight character minimum.'), true); $data[3] = html_print_input_password( 'snmp3_auth_pass', $snmp3_auth_pass, @@ -312,7 +312,7 @@ push_table_simple($data, 'field_snmpv3_row1'); $data = []; $data[0] = __('Privacy method'); $data[1] = html_print_select(['DES' => __('DES'), 'AES' => __('AES')], 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true, false, false, '', $disabledBecauseInPolicy); -$data[2] = __('Privacy pass').ui_print_help_tip(__('The pass length must be eight character minimum.'), true); +$data[2] = __('Privacy pass').ui_print_help_icon('column_macros', true).ui_print_help_tip(__('The pass length must be eight character minimum.'), true); $data[3] = html_print_input_password( 'snmp3_privacy_pass', $snmp3_privacy_pass, diff --git a/pandora_console/godmode/agentes/module_manager_editor_wmi.php b/pandora_console/godmode/agentes/module_manager_editor_wmi.php index e7f38447cf..d15cd6477f 100644 --- a/pandora_console/godmode/agentes/module_manager_editor_wmi.php +++ b/pandora_console/godmode/agentes/module_manager_editor_wmi.php @@ -60,7 +60,7 @@ $data[3] = html_print_input_text( push_table_simple($data, 'target_ip'); $data = []; -$data[0] = __('Username'); +$data[0] = __('Username').ui_print_help_icon('column_macros', true); $data[1] = html_print_input_text( 'plugin_user', $plugin_user, @@ -73,7 +73,7 @@ $data[1] = html_print_input_text( '', $classdisabledBecauseInPolicy ); -$data[2] = __('Password'); +$data[2] = __('Password').ui_print_help_icon('column_macros', true); $data[3] = html_print_input_password( 'plugin_pass', $plugin_pass, diff --git a/pandora_console/include/help/en/help_column_macros.php b/pandora_console/include/help/en/help_column_macros.php new file mode 100644 index 0000000000..85fe72f39f --- /dev/null +++ b/pandora_console/include/help/en/help_column_macros.php @@ -0,0 +1,14 @@ + +

Module macros

+ +

+The following macros are available: +

+

+

diff --git a/pandora_console/include/help/es/help_column_macros.php b/pandora_console/include/help/es/help_column_macros.php new file mode 100644 index 0000000000..b34ede1555 --- /dev/null +++ b/pandora_console/include/help/es/help_column_macros.php @@ -0,0 +1,13 @@ + +

Macros de módulos

+ +

+Las siguientes macros están disponibles: +

+ diff --git a/pandora_console/include/help/ja/help_column_macros.php b/pandora_console/include/help/ja/help_column_macros.php new file mode 100644 index 0000000000..9d925b1193 --- /dev/null +++ b/pandora_console/include/help/ja/help_column_macros.php @@ -0,0 +1,15 @@ + +

モジュールマクロ

+ +

+次のマクロが利用できます: +

+ +

+

diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 3bfd1e1a7d..3016ae64b2 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -236,6 +236,7 @@ our @EXPORT = qw( pandora_self_monitoring pandora_process_policy_queue subst_alert_macros + subst_column_macros locate_agent get_agent get_agent_from_alias @@ -3707,11 +3708,6 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) { } } - -########################################################################## -# Utility functions, not to be exported. -########################################################################## - ########################################################################## # Search string for macros and substitutes them with their values. ########################################################################## @@ -3746,6 +3742,19 @@ sub subst_alert_macros ($$;$$$$) { return $string; } +########################################################################## +# Substitute macros if the string begins with an underscore. +########################################################################## +sub subst_column_macros ($$;$$$$) { + my ($string, $macros, $pa_config, $dbh, $agent, $module) = @_; + + # Do not attempt to substitute macros unless the string + # begins with an underscore. + return $string unless substr($string, 0, 1) eq '_'; + + return subst_alert_macros($string, $macros, $pa_config, $dbh, $agent, $module); +} + ########################################################################## # Load macros that access the database on demand. ########################################################################## @@ -3774,9 +3783,16 @@ sub on_demand_macro($$$$$$) { } elsif ($macro eq '_name_tag_') { return (defined ($module)) ? pandora_get_module_tags ($pa_config, $dbh, $module->{'id_agente_modulo'}) : ''; } elsif ($macro =~ /_agentcustomfield_(\d+)_/) { - return '' unless defined ($agent); + my $agent_id = undef; + if (defined($module)) { + $agent_id = $module->{'id_agente'}; + } elsif (defined($agent)) { + $agent_id = $agent->{'id_agente'}; + } else { + return ''; + } my $field_number = $1; - my $field_value = get_db_value($dbh, 'SELECT description FROM tagent_custom_data WHERE id_field=? AND id_agent=?', $field_number, $agent->{'id_agente'}); + my $field_value = get_db_value($dbh, 'SELECT description FROM tagent_custom_data WHERE id_field=? AND id_agent=?', $field_number, $agent_id); return (defined($field_value)) ? $field_value : ''; } elsif ($macro eq '_prevdata_') { return '' unless defined ($module); @@ -3840,6 +3856,10 @@ sub on_demand_macro($$$$$$) { } } +########################################################################## +# Utility functions, not to be exported. +########################################################################## + ########################################################################## # Process module data. ########################################################################## diff --git a/pandora_server/lib/PandoraFMS/NetworkServer.pm b/pandora_server/lib/PandoraFMS/NetworkServer.pm index cea3733764..72ff78d975 100644 --- a/pandora_server/lib/PandoraFMS/NetworkServer.pm +++ b/pandora_server/lib/PandoraFMS/NetworkServer.pm @@ -344,14 +344,20 @@ sub pandora_snmp_get_command ($$$$$$$$$$$) { sub pandora_query_snmp ($$$$) { my ($pa_config, $module, $ip_target, $dbh) = @_; + # Initialize macros. + my %macros = ( + '_agentcustomfield_\d+_' => undef, + ); + + my $snmp_version = $module->{"tcp_send"}; # (1, 2, 2c or 3) my $snmp3_privacy_method = $module->{"custom_string_1"}; # DES/AES - my $snmp3_privacy_pass = safe_output(pandora_output_password($pa_config, $module->{"custom_string_2"})); + my $snmp3_privacy_pass = safe_output(pandora_output_password($pa_config, subst_column_macros($module->{"custom_string_2"}, \%macros, $pa_config, $dbh, undef, $module))); my $snmp3_security_level = $module->{"custom_string_3"}; # noAuthNoPriv|authNoPriv|authPriv - my $snmp3_auth_user = safe_output($module->{"plugin_user"}); - my $snmp3_auth_pass = safe_output(pandora_output_password($pa_config, $module->{"plugin_pass"})); + my $snmp3_auth_user = safe_output(subst_column_macros($module->{"plugin_user"}, \%macros, $pa_config, $dbh, undef, $module)); + my $snmp3_auth_pass = safe_output(pandora_output_password($pa_config, subst_column_macros($module->{"plugin_pass"}, \%macros, $pa_config, $dbh, undef, $module))); my $snmp3_auth_method = $module->{"plugin_parameter"}; #MD5/SHA1 - my $snmp_community = $module->{"snmp_community"}; + my $snmp_community = safe_output(subst_column_macros($module->{"snmp_community"}, \%macros, $pa_config, $dbh, undef, $module)); my $snmp_target = $ip_target; my $snmp_oid = $module->{"snmp_oid"}; my $snmp_port = $module->{"tcp_port"}; diff --git a/pandora_server/lib/PandoraFMS/WMIServer.pm b/pandora_server/lib/PandoraFMS/WMIServer.pm index b667de6a91..3606166508 100644 --- a/pandora_server/lib/PandoraFMS/WMIServer.pm +++ b/pandora_server/lib/PandoraFMS/WMIServer.pm @@ -142,13 +142,21 @@ sub data_consumer ($$) { my $module = get_db_single_row ($dbh, 'SELECT * FROM tagente_modulo WHERE id_agente_modulo = ?', $module_id); return unless defined $module; + # Initialize macros. + my %macros = ( + '_agentcustomfield_\d+_' => undef, + ); + # Build command to execute my $wmi_command = ''; if (defined ($module->{'plugin_pass'}) && $module->{'plugin_pass'} ne "") { - $wmi_command = $pa_config->{'wmi_client'} . ' -U "' . safe_output($module->{'plugin_user'}) . '"%"' . pandora_output_password($pa_config, $module->{'plugin_pass'}) . '"'; + my $user = safe_output(subst_column_macros($module->{'plugin_user'}, \%macros, $pa_config, $dbh, undef, $module)); + my $pass = safe_output(pandora_output_password($pa_config, subst_column_macros($module->{'plugin_pass'}, \%macros, $pa_config, $dbh, undef, $module))); + $wmi_command = $pa_config->{'wmi_client'} . ' -U "' . $user . '"%"' . $pass . '"'; } elsif (defined ($module->{'plugin_user'}) && $module->{'plugin_user'} ne "") { - $wmi_command = $pa_config->{'wmi_client'} . ' -U "' . safe_output($module->{'plugin_user'}) . '"'; + my $user = safe_output(subst_column_macros($module->{'plugin_user'}, \%macros, $pa_config, $dbh, undef, $module)); + $wmi_command = $pa_config->{'wmi_client'} . ' -U "' . $user . '"'; } else { $wmi_command = $pa_config->{'wmi_client'} . ' -N'; From c36241de4fbd12c6038cbb81adea195141cb8678 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Wed, 20 Feb 2019 09:04:15 +0100 Subject: [PATCH 2/2] Add additional help icons. Former-commit-id: 9641eb9ceaefde1c24503fcfb4c7965afedf8fbc --- .../modules/manage_network_components_form_network.php | 8 ++++---- .../modules/manage_network_components_form_wmi.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandora_console/godmode/modules/manage_network_components_form_network.php b/pandora_console/godmode/modules/manage_network_components_form_network.php index 329d8d1405..8befa28555 100755 --- a/pandora_console/godmode/modules/manage_network_components_form_network.php +++ b/pandora_console/godmode/modules/manage_network_components_form_network.php @@ -57,16 +57,16 @@ $data = []; $data[0] = __('SNMP Enterprise String'); $data[1] = html_print_input_text('snmp_oid', $snmp_oid, '', 30, 400, true); // $table->colspan['snmp_2'][1] = 3; -$data[2] = __('SNMP community'); +$data[2] = __('SNMP community').ui_print_help_icon('column_macros', true); $data[3] = html_print_input_text('snmp_community', $snmp_community, '', 15, 60, true); push_table_row($data, 'snmp_2'); $data = []; -$data[0] = __('Auth user'); +$data[0] = __('Auth user').ui_print_help_icon('column_macros', true); $data[1] = html_print_input_text('snmp3_auth_user', $snmp3_auth_user, '', 15, 60, true); -$data[2] = __('Auth password'); +$data[2] = __('Auth password').ui_print_help_icon('column_macros', true); $data[3] = html_print_input_password('snmp3_auth_pass', $snmp3_auth_pass, '', 15, 60, true); $data[3] .= html_print_input_hidden_extended('active_snmp_v3', 0, 'active_snmp_v3_mncfn', true); push_table_row($data, 'field_snmpv3_row1'); @@ -74,7 +74,7 @@ push_table_row($data, 'field_snmpv3_row1'); $data = []; $data[0] = __('Privacy method'); $data[1] = html_print_select(['DES' => __('DES'), 'AES' => __('AES')], 'snmp3_privacy_method', $snmp3_privacy_method, '', '', '', true); -$data[2] = __('Privacy pass'); +$data[2] = __('Privacy pass').ui_print_help_icon('column_macros', true); $data[3] = html_print_input_password('snmp3_privacy_pass', $snmp3_privacy_pass, '', 15, 60, true); push_table_row($data, 'field_snmpv3_row2'); diff --git a/pandora_console/godmode/modules/manage_network_components_form_wmi.php b/pandora_console/godmode/modules/manage_network_components_form_wmi.php index 35b846250e..f88441f5d5 100755 --- a/pandora_console/godmode/modules/manage_network_components_form_wmi.php +++ b/pandora_console/godmode/modules/manage_network_components_form_wmi.php @@ -44,9 +44,9 @@ $data[3] = html_print_input_text('tcp_send', $tcp_send, '', 25, 255, true); push_table_row($data, 'wmi_2'); $data = []; -$data[0] = __('Username'); +$data[0] = __('Username').ui_print_help_icon('column_macros', true); $data[1] = html_print_input_text('plugin_user', $plugin_user, '', 15, 255, true); -$data[2] = __('Password'); +$data[2] = __('Password').ui_print_help_icon('column_macros', true); $data[3] = html_print_input_password('plugin_pass', $plugin_pass, '', 25, 255, true); push_table_row($data, 'wmi_3');