Merge branch 'ent-3763-Nuevas-macros-alertas' into 'develop'

add new macros #3763

See merge request artica/pandorafms!4640
This commit is contained in:
Daniel Rodriguez 2022-02-01 09:34:15 +00:00
commit 75f8c02eaf
2 changed files with 121 additions and 82 deletions

View File

@ -1262,6 +1262,13 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
$group = get_db_single_row ($dbh, 'SELECT * FROM tgrupo WHERE id_grupo = ?', $agent->{'id_grupo'}); $group = get_db_single_row ($dbh, 'SELECT * FROM tgrupo WHERE id_grupo = ?', $agent->{'id_grupo'});
} }
my $agent_status;
if(ref ($module) eq "HASH") {
$agent_status = get_db_single_row ($dbh, 'SELECT * FROM tagente_estado WHERE id_agente_modulo = ?', $module->{'id_agente_modulo'});
}
my $time_down = (defined ($agent_status)) ? (time() - $agent_status->{'last_status_change'}) : undef;
if (is_numeric($data)) { if (is_numeric($data)) {
my $data_precision = $pa_config->{'graph_precision'}; my $data_precision = $pa_config->{'graph_precision'};
$data = sprintf("%.$data_precision" . "f", $data); $data = sprintf("%.$data_precision" . "f", $data);
@ -1274,7 +1281,8 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
# TODO: Reuse queries. For example, tag data can be extracted with a single query. # TODO: Reuse queries. For example, tag data can be extracted with a single query.
# Alert macros # Alert macros
my %macros = (_field1_ => $field1, my %macros = (
_field1_ => $field1,
_field2_ => $field2, _field2_ => $field2,
_field3_ => $field3, _field3_ => $field3,
_field4_ => $field4, _field4_ => $field4,
@ -1345,6 +1353,12 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
_all_address_ => undef, _all_address_ => undef,
'_addressn_\d+_' => undef, '_addressn_\d+_' => undef,
_secondarygroups_ => undef, _secondarygroups_ => undef,
_time_down_seconds_ => (defined ($time_down)) ? int($time_down) : '',
_time_down_human_ => seconds_totime($time_down),
_warning_threshold_min_ => (defined ($module->{'min_warning'})) ? $module->{'min_warning'} : '',
_warning_threshold_max_ => (defined ($module->{'max_warning'})) ? $module->{'max_warning'} : '',
_critical_threshold_min_ => (defined ($module->{'min_critical'})) ? $module->{'min_critical'} : '',
_critical_threshold_max_ => (defined ($module->{'max_critical'})) ? $module->{'max_critical'} : '',
); );
if ((defined ($extra_macros)) && (ref($extra_macros) eq "HASH")) { if ((defined ($extra_macros)) && (ref($extra_macros) eq "HASH")) {
@ -1357,7 +1371,6 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
load_module_macros ($module->{'module_macros'}, \%macros); load_module_macros ($module->{'module_macros'}, \%macros);
} }
#logger($pa_config, "Clean name ".$clean_name, 10); #logger($pa_config, "Clean name ".$clean_name, 10);
# User defined alert # User defined alert
if ($action->{'internal'} == 0) { if ($action->{'internal'} == 0) {

View File

@ -147,6 +147,7 @@ our @EXPORT = qw(
ping ping
resolve_hostname resolve_hostname
ticks_totime ticks_totime
seconds_totime
safe_input safe_input
safe_output safe_output
month_have_days month_have_days
@ -1409,6 +1410,31 @@ sub ticks_totime ($){
return "$days days, $hours hours, $minutes minutes, $seconds seconds"; return "$days days, $hours hours, $minutes minutes, $seconds seconds";
} }
################################################################################
## SUB human_time_readable
# Transform a seconds count in a human readable date
################################################################################
sub seconds_totime ($){
my $SECONDS_PER_MINUTE = 60;
my $SECONDS_PER_HOUR = $SECONDS_PER_MINUTE * 60;
my $SECONDS_PER_DAY = $SECONDS_PER_HOUR * 24;
my $orig_seconds = shift;
if (!defined($orig_seconds)){
return "";
}
my $seconds = int($orig_seconds) % 60;
my $minutes = int($orig_seconds / $SECONDS_PER_MINUTE) % 60;
my $hours = int($orig_seconds / $SECONDS_PER_HOUR) % 24;
my $days = int($orig_seconds / $SECONDS_PER_DAY);
return "$days days, $hours hours, $minutes minutes, $seconds seconds";
}
################################################################################ ################################################################################
=head2 C<< pandora_ping (I<$pa_config>, I<$host>) >> =head2 C<< pandora_ping (I<$pa_config>, I<$host>) >>