(plugin) notification::microsoft::office365::teams::plugin - adding redirection to newer resource status pages (#3863)

This commit is contained in:
lchrdn 2022-08-25 17:12:28 +02:00 committed by GitHub
parent c0fd53f947
commit 707f625907
1 changed files with 115 additions and 5 deletions

View File

@ -24,6 +24,7 @@ use strict;
use warnings;
use base qw(centreon::plugins::mode);
use URI::Encode;
use JSON::XS;
sub new {
my ($class, %options) = @_;
@ -42,6 +43,7 @@ sub new {
'host-name:s' => { name => 'host_name' },
'host-output:s' => { name => 'host_output', default => '' },
'host-state:s' => { name => 'host_state' },
'legacy:s' => { name => 'legacy' },
'notification-type:s' => { name => 'notif_type'},
'service-description:s' => { name => 'service_name' },
'service-output:s' => { name => 'service_output', default => '' },
@ -67,6 +69,99 @@ sub check_options {
}
}
sub build_resource_status_filters {
my ($self, %options) = @_;
my $data_format = URI::Encode->new({encode_reserved => 1});
my $raw_resource_status_filters = {
"id" => "",
"name" => "New+filter",
"criterias" => [
{
"name" => "resource_types",
"object_type" => undef,
"type" => "multi_select",
"value" => [
{
"id" => "service",
"name" => "Service"
}
]
},
{
"name" => "states",
"object_type" => undef,
"type" => "multi_select",
"value" => [
]
},
{
"name" => "statuses",
"object_type" => undef,
"type" => "multi_select",
"value" => [
]
},
{
"name" => "status_types",
"object_type" => undef,
"type" => "multi_select",
"value" => [
]
},
{
"name" => "host_groups",
"object_type" => "host_groups",
"type" => "multi_select",
"value" => [
]
},
{
"name" => "service_groups",
"object_type" => "service_groups",
"type" => "multi_select",
"value" => [
]
},
{
"name" => "monitoring_servers",
"object_type" => "monitoring_servers",
"type" => "multi_select",
"value" => [
]
},
{
"name" => "search",
"object_type" => undef,
"type" => "text",
"value"=> "s.description:$self->{option_results}->{service_name} h.name:$self->{option_results}->{host_name}"
},
{
"name" => "sort",
"object_type" => undef,
"type" => "array",
"value" => [
"status_severity_code",
"asc"
]
}
]
};
my $link_url_path = '/monitoring/resources?filter=';
my $encoded_resource_status_filters = JSON::XS->new->utf8->encode($raw_resource_status_filters);
my $encoded_data_for_uri = $data_format->encode($encoded_resource_status_filters);
$link_url_path .= $encoded_data_for_uri;
return $link_url_path;
}
sub build_payload {
my ($self, %options) = @_;
@ -149,12 +244,20 @@ sub build_message {
$self->{output}->option_exit();
}
my $uri = URI::Encode->new({encode_reserved => 0});
my $link_url_path = '/main.php?p=2020'; # only for the 'old' pages for now
$link_url_path .= ($resource_type eq 'service') ?
'1&o=svc&host_search=' . $self->{option_results}->{host_name} . '&search=' . $self->{option_results}->{service_name} :
'2&o=svc&host_search=' . $self->{option_results}->{host_name};
my $link_url_path;
if (defined($self->{option_results}->{legacy})){
$link_url_path = '/main.php?p=2020'; # deprecated pages
$link_url_path .= ($resource_type eq 'service') ?
'1&o=svc&host_search=' . $self->{option_results}->{host_name} . '&search=' . $self->{option_results}->{service_name} :
'2&o=svc&host_search=' . $self->{option_results}->{host_name};
my $link_uri_encoded = $uri->encode($self->{option_results}->{centreon_url} . $link_url_path);
my $link_uri_encoded = $uri->encode($self->{option_results}->{centreon_url} . $link_url_path);
} else {
$link_url_path = $self->build_resource_status_filters();
}
my $link_uri_encoded = $uri->encode($self->{option_results}->{centreon_url}) . $link_url_path;
push @{$self->{potentialAction}}, {
'@type' => 'OpenUri',
@ -179,6 +282,7 @@ sub build_message {
}]
};
}
}
return $self;
}
@ -265,6 +369,12 @@ Specify extra information about author and comment (only for ACK and DOWNTIME ty
Specify the extra info display format (Default: 'Author: %s, Comment: %s').
=item B<--legacy>
Only to be used with Centreon.
Permit redirection to Centreon legacy resource status pages.
To be used with --action-links.
=back
=cut