Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Allow nagios notification to be filtered by service group #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions nagios.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
use HTTP::Request::Common qw(POST);
use HTTP::Status qw(is_client_error);
use LWP::UserAgent;
use List::Util qw(any);


#
Expand All @@ -72,7 +73,11 @@
#

my %opt_fields;
GetOptions("field=s%" => \%opt_fields);
my $opt_service_group;
GetOptions(
"field=s%" => \%opt_fields,
"service_group:s" => \$opt_service_group,
);


#
Expand All @@ -97,14 +102,23 @@
# Make the request
#

my $ua = LWP::UserAgent->new;
$ua->timeout(15);
if (length $event{SERVICEGROUPNAMES} and length $opt_service_group) {
my @service_groups = split /, */, $event{SERVICEGROUPNAMES};
slack_notif() if any { $_ eq $opt_service_group } @service_groups;
} else {
slack_notif();
}

sub slack_notif {
my $ua = LWP::UserAgent->new;
$ua->timeout(15);

my $req = POST("https://${opt_domain}/services/hooks/nagios?token=${opt_token}", \%event);
my $req = POST("https://${opt_domain}/services/hooks/nagios?token=${opt_token}", \%event);

my $s = $req->as_string;
print STDERR "Request:\n$s\n";
my $s = $req->as_string;
print STDERR "Request:\n$s\n";

my $resp = $ua->request($req);
$s = $resp->as_string;
print STDERR "Response:\n$s\n";
my $resp = $ua->request($req);
$s = $resp->as_string;
print STDERR "Response:\n$s\n";
}