Merge branch 'ent-3436-custom-fields-como-macros-en-el-server' into 'develop'
Add support for column macros. See merge request artica/pandorafms!2182 Former-commit-id: 93dad8f6c54f6e46e5e54dab347a96cffe2fd240
This commit is contained in:
commit
36410a26d1
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
|
@ -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>
|
|
@ -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>
|
|
@ -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>
|
|
@ -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
|
||||
|
@ -3717,11 +3718,6 @@ sub pandora_evaluate_snmp_alerts ($$$$$$$$$) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# Utility functions, not to be exported.
|
||||
##########################################################################
|
||||
|
||||
##########################################################################
|
||||
# Search string for macros and substitutes them with their values.
|
||||
##########################################################################
|
||||
|
@ -3756,6 +3752,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.
|
||||
##########################################################################
|
||||
|
@ -3784,9 +3793,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);
|
||||
|
@ -3850,6 +3866,10 @@ sub on_demand_macro($$$$$$) {
|
|||
}
|
||||
}
|
||||
|
||||
##########################################################################
|
||||
# Utility functions, not to be exported.
|
||||
##########################################################################
|
||||
|
||||
##########################################################################
|
||||
# Process module data.
|
||||
##########################################################################
|
||||
|
|
|
@ -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"};
|
||||
|
|
|
@ -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';
|
||||
|
|
Loading…
Reference in New Issue