Page 1 of 1

Slack Integration 5.5.1

Posted: Wed Sep 05, 2018 12:37 pm
by ahoward12
Hey everyone,

I followed the guides for slack integration into my Nagios XI box. I was wondering if anyone knows how to put the Rapid Response URL in the message? Prior to slack integration I had %responseurl% in the emails/text messages.

Here is my slack_nagios.pl

Code: Select all

#!/usr/bin/perl


# Copyright 2013 Tiny Speck, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


#
# A nagios/icinga plugin for sending alerts to Slack. See more documentation on the team services page at:
# https://my.slack.com/services/new/nagios
#
# Requires these perl modules:
# HTTP::Request
# LWP::UserAgent
#
# I am not a perl programmer. Beware.
#
# An example Nagios config:
#
# define contact {
#       contact_name                             slack
#       alias                                    Slack
#       service_notification_period              24x7
#       host_notification_period                 24x7
#       service_notification_options             w,u,c,r
#       host_notification_options                d,r
#       service_notification_commands            notify-service-by-slack
#       host_notification_commands               notify-host-by-slack
# }
#
# define command {
#       command_name     notify-service-by-slack
#       command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#alerts
# }
#
#define command {
#       command_name     notify-host-by-slack
#       command_line     /usr/local/bin/slack_nagios.pl -field slack_channel=#alerts
# }
#

use warnings;
use strict;

use Getopt::Long;
use HTTP::Request::Common qw(POST);
use HTTP::Status qw(is_client_error);
use LWP::UserAgent;


#
# Customizable vars. Set these to the information for your team
#

my $opt_domain = "mydomain.slack.com"; # Your team's domain
my $opt_token = "my token"; # The token from your Nagios services page


#
# Get command-line opts
#

my %opt_fields;
GetOptions("field=s%" => \%opt_fields);


#
# DO THINGS
#

my %event;

# Get all Nagios variables
while ((my $k, my $v) = each %ENV) {
        next unless $k =~ /^(?:NAGIOS|ICINGA)_(.*)$/;
        $event{$1} = $v;
}

# Merge in passed-in variables
%event = (%event, %opt_fields);

$event{"slack_version"} = "1.1";


#
# Make the request
#

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

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 $resp = $ua->request($req);
$s = $resp->as_string;
print STDERR "Response:\n$s\n";
Here are my notification commands:

Code: Select all

$USER1$/slack_nagios.pl -field slack_channel="#alerts" -field HOSTALIAS="$HOSTNAME$" -field HOSTSTATE="$HOSTSTATE$" -field HOSTOUTPUT="$HOSTOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$" 

Code: Select all

$USER1$/slack_nagios.pl -field slack_channel="#alerts" -field HOSTALIAS="$HOSTNAME$" -field SERVICEDESC="$SERVICEDESC$" -field SERVICESTATE="$SERVICESTATE$" -field SERVICEOUTPUT="$SERVICEOUTPUT$" -field NOTIFICATIONTYPE="$NOTIFICATIONTYPE$"

Re: Slack Integration 5.5.1

Posted: Wed Sep 05, 2018 12:54 pm
by scottwilkerson
Unfortunately this is not possible as the responseurl is something specifically created inside of the xi_host_notification_handler and xi_service_notification_handler and is not available as a macro out of nagios

Re: Slack Integration 5.5.1

Posted: Thu Sep 06, 2018 12:51 pm
by ahoward12
Appreciate the answer. You can close the thread.

Re: Slack Integration 5.5.1

Posted: Thu Sep 06, 2018 1:00 pm
by scottwilkerson
ahoward12 wrote:Appreciate the answer. You can close the thread.
Closing