Notifications

Notification for Microsoft Teams

Description:

Nagios plugin to send notifications to MS Teams (MessageCard)

Current Version

Last Release Date

2019-03-01

Compatible With

  • Nagios 3.x
  • Nagios 4.x

Owner

License

Apache


Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Project Files
Project Notes
Reviews (2) Add a Review
Small changes make it work for me
by dlundh, October 31, 2019
No more empty Teams postings, and UTF-8 support:
#!/usr/bin/perl

#
# 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.

use warnings;
use strict;

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

my %opt_fields;
my %event;
my %nagios;
my @sections;
my @actions;
my @targets;
my $webhook = "https://outlook.office365.com/webhook/MISSING";
my $nagios_url = "";
my %color = ( 'OK' => '008000', 'WARNING' => 'ffff00', 'UNKNOWN' => '808080','CRITICAL' => 'ff0000',
'UP' => '008000', 'DOWN' => 'ff0000', 'UNREACHABLE' => 'ff8700');
$event{'title'} = "Nagios Notification";
$event{'@type'} = "MessageCard";
$event{'@context'} = "https://schema.org/extensions";
$nagios{'HOSTNOTES'} = "not defined";


#
# Get command-line options
#
GetOptions ("webhook=s" => $webhook, "nagios_url=s" => $nagios_url, "field=s%" => %opt_fields)
or die("Error in command line argumentsn");

#
# Read Nagios events
#
while ((my $k, my $v) = each %ENV) {
next unless $k =~ /^(?:NAGIOS|ICINGA)_(.*)$/;
$nagios{$1} = $v;
print STDERR "$1 is $nagios{$1}n";
}

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

#
# Format message card
#
if (not length($nagios{'SERVICESTATE'})) {
# if service state env is not defnined or empty, event is host notification.
$nagios{'SERVICEDESC'} = "host status";
$nagios{'SERVICESTATE'} = $nagios{'HOSTSTATE'};
$nagios{'SERVICEOUTPUT'} = $nagios{'HOSTOUTPUT'};
}
$event{'themeColor'} = $color{"$nagios{'SERVICESTATE'}"};
$event{'title'} = "$nagios{'HOSTALIAS'}/$nagios{'SERVICEDESC'} is $nagios{'SERVICESTATE'}";
$event{'summary'} = $event{'title'};
my @facts = ({
'name' => "Host:",
'value' => "$nagios{'HOSTALIAS'}"
},{
'name' => "Details:",
'value' => "$nagios{'SERVICEOUTPUT'}"
});
my %section = ( 'facts' => @facts, );
push(@sections, %section);
$event{'sections'} = @sections;

if ($nagios_url ne '') {
my %target = (
'os' => 'default',
'uri' => "$nagios_url/cgi-bin/status.cgi?host=$nagios{'HOSTNAME'}"
);
push(@targets, %target);
my %link = (
'@type' => 'OpenUri',
'name' => 'View in Nagios',
'targets' => @targets
);
push(@actions, %link);
$event{'potentialAction'} = @actions;
}
my $json = encode_json %event;

#
# Make the request
#

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

my $req = HTTP::Request->new('POST', $webhook);
$req->header('Content-Type' => 'application/json;charset=utf-8');
$req->content(Encode::decode_utf8($json));

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

my $resp = $ua->request($req);
$s = $resp->as_string;
print STDERR "Response:n$sn";
Owner's Reply:

it'd be great if you could create a PR to the git repo : https://github.com/akadoya/nagios-msteams/pulls


Helpful? Yes  No 
Passing ENV to script
by jeyminee, June 30, 2019
This is exactly what i needed but... the notification sent to teams is empty as it seems the environment variables are not set.

What could be the problem ?
Owner's Reply:

If your core is not Nagios core, some times the environment variables' names are different.
This may be relate to your question : https://github.com/akadoya/nagios-msteams/issues/2


1 of 1 found this review helpful.
Helpful? Yes 1 No 0
Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
4 (2)
Favorites
0
Views
17,439