mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-28 08:14:38 +02:00
alert_command send notification
Former-commit-id: ff0eb13b51cdab9c2d188362da0c8b2c4191b2cf
This commit is contained in:
parent
851050f04e
commit
d40ced2043
@ -1975,3 +1975,8 @@ CREATE TABLE `tnotification_source_group_user` (
|
|||||||
FOREIGN KEY (`id_group`) REFERENCES `tnotification_source_group`(`id_group`)
|
FOREIGN KEY (`id_group`) REFERENCES `tnotification_source_group`(`id_group`)
|
||||||
ON UPDATE CASCADE ON DELETE CASCADE
|
ON UPDATE CASCADE ON DELETE CASCADE
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||||
|
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
-- Add alert command 'Generate notification'
|
||||||
|
-- ----------------------------------------------------------------------
|
||||||
|
INSERT INTO `talert_commands` (`name`, `command`, `description`, `internal`, `fields_descriptions`, `fields_values`) VALUES ('Generate Notification','Internal type','This command allows you to send an internal notification to any user or group.',1,'[\"Destination user\",\"Destination group\",\"Title\",\"Message\",\"Link\",\"Criticity\",\"\",\"\",\"\",\"\",\"\"]','[\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\",\"\"]');
|
||||||
|
File diff suppressed because one or more lines are too long
@ -249,6 +249,7 @@ our @EXPORT = qw(
|
|||||||
pandora_delete_graph_source
|
pandora_delete_graph_source
|
||||||
pandora_delete_custom_graph
|
pandora_delete_custom_graph
|
||||||
pandora_edit_custom_graph
|
pandora_edit_custom_graph
|
||||||
|
notification_set_targets
|
||||||
);
|
);
|
||||||
|
|
||||||
# Some global variables
|
# Some global variables
|
||||||
@ -1459,6 +1460,35 @@ sub pandora_execute_action ($$$$$$$$$;$) {
|
|||||||
|
|
||||||
pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_email, $ticket_owner, $ticket_description);
|
pandora_create_integria_ticket($pa_config, $api_path, $api_pass, $integria_user, $integria_user_pass, $ticket_name, $ticket_group_id, $ticket_priority, $ticket_email, $ticket_owner, $ticket_description);
|
||||||
|
|
||||||
|
|
||||||
|
# Generate notification
|
||||||
|
} elsif ($clean_name eq "Generate Notification") {
|
||||||
|
|
||||||
|
# Translate macros
|
||||||
|
$field3 = subst_alert_macros($field3, \%macros, $pa_config, $dbh, $agent, $module);
|
||||||
|
$field4 = subst_alert_macros($field4, \%macros, $pa_config, $dbh, $agent, $module);
|
||||||
|
|
||||||
|
# If no targets ignore notification
|
||||||
|
if (defined($field1) && defined($field2) && ($field1 ne "" || $field2 ne "")) {
|
||||||
|
my @user_list = map {clean_blank($_)} split /,/, $field1;
|
||||||
|
my @group_list = map {clean_blank($_)} split /,/, $field2;
|
||||||
|
|
||||||
|
my $notification = {};
|
||||||
|
$notification->{'subject'} = safe_input($field3);
|
||||||
|
$notification->{'mensaje'} = safe_input($field4);
|
||||||
|
$notification->{'id_source'} = get_db_value($dbh, 'SELECT id FROM tnotification_source WHERE description = ?', safe_input('System status'));
|
||||||
|
|
||||||
|
# Create message
|
||||||
|
my $notification_id = db_process_insert($dbh,'id_mensaje','tmensajes',$notification);
|
||||||
|
if (!$notification_id) {
|
||||||
|
logger($pa_config, "Failed action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined($agent) ? $agent->{'alias'} : 'N/A') . "'.", 3);
|
||||||
|
} else {
|
||||||
|
notification_set_targets($pa_config, $dbh, $notification_id, \@user_list, \@group_list);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger($pa_config, "Failed action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined($agent) ? $agent->{'alias'} : 'N/A') . "' Empty targets. Ignored.", 3);
|
||||||
|
}
|
||||||
|
|
||||||
# Unknown
|
# Unknown
|
||||||
} else {
|
} else {
|
||||||
logger($pa_config, "Unknown action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'alias'} : 'N/A') . "'.", 3);
|
logger($pa_config, "Unknown action '" . $action->{'name'} . "' for alert '". $alert->{'name'} . "' agent '" . (defined ($agent) ? $agent->{'alias'} : 'N/A') . "'.", 3);
|
||||||
@ -5746,6 +5776,62 @@ sub pandora_safe_mode_modules_update {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
|
||||||
|
=head2 C<< message_set_targets (I<$dbh>, I<$pa_config>, I<$notification_id>, I<$users>, I<$groups>) >>
|
||||||
|
Set targets for given messaje (users and groups in hash ref)
|
||||||
|
=cut
|
||||||
|
|
||||||
|
##########################################################################
|
||||||
|
sub notification_set_targets {
|
||||||
|
my ($pa_config, $dbh, $notification_id, $users, $groups) = @_;
|
||||||
|
my $ret = undef;
|
||||||
|
|
||||||
|
if (!defined($pa_config)) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!defined($notification_id)) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ref($users) eq "ARRAY") {
|
||||||
|
my $values = {};
|
||||||
|
foreach my $user (@{$users}) {
|
||||||
|
if (defined($user) && $user eq "") {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values->{'id_mensaje'} = $notification_id;
|
||||||
|
$values->{'id_user'} = $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = db_process_insert($dbh, '', 'tnotification_user', $values);
|
||||||
|
if (!$ret) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ref($groups) eq "ARRAY") {
|
||||||
|
my $values = {};
|
||||||
|
foreach my $group (@{$groups}) {
|
||||||
|
if ($group != 0 && empty($group)) {
|
||||||
|
next;
|
||||||
|
}
|
||||||
|
|
||||||
|
$values->{'id_mensaje'} = $notification_id;
|
||||||
|
$values->{'id_group'} = $group;
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = db_process_insert($dbh, '', 'tnotification_group', $values);
|
||||||
|
if (!$ret) {
|
||||||
|
return undef;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
# End of function declaration
|
# End of function declaration
|
||||||
# End of defined Code
|
# End of defined Code
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user