Slack Integration 5.5.1

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
ahoward12
Posts: 137
Joined: Thu Jan 05, 2017 10:24 am

Slack Integration 5.5.1

Post 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$"
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Slack Integration 5.5.1

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
ahoward12
Posts: 137
Joined: Thu Jan 05, 2017 10:24 am

Re: Slack Integration 5.5.1

Post by ahoward12 »

Appreciate the answer. You can close the thread.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Slack Integration 5.5.1

Post by scottwilkerson »

ahoward12 wrote:Appreciate the answer. You can close the thread.
Closing
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked