Add support for column macros.

Former-commit-id: 8b826854c288754feefdbe270701655c6bbbfac9
This commit is contained in:
Ramon Novoa 2019-02-19 13:04:57 +01:00
parent b8fe20e373
commit 7bd5851667
8 changed files with 95 additions and 19 deletions

View File

@ -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,

View File

@ -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,

View File

@ -0,0 +1,14 @@
<?php
/**
* @package Include/help/en
*/
?>
<h1>Module macros</h1>
<p>
The following macros are available:
<ul>
<li>_agentcustomfield_<i>n</i>_: Agent custom field number <i>n</i> (eg. _agentcustomfield_9_).</li>
</ul>
<p>
</p>

View File

@ -0,0 +1,13 @@
<?php
/**
* @package Include/help/en
*/
?>
<h1>Macros de módulos</h1>
<p>
Las siguientes macros están disponibles:
</p>
<ul>
<li>_agentcustomfield_<i>n</i>_: Campo personalizado número <i>n</i> del agente (eg. _agentcustomfield_9_). </li>
</ul>

View File

@ -0,0 +1,15 @@
<?php
/**
* @package Include/help/ja
*/
?>
<h1>モジュールマクロ</h1>
<p>
次のマクロが利用できます:
</p>
<ul>
<li>_agentcustomfield_<i>n</i>_ : エージェントカスタムフィールド番号<i>n</i> (: _agentcustomfield_9_). </li>
</ul>
<p>
</p>

View File

@ -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.
##########################################################################

View File

@ -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"};

View File

@ -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';