Home Directory Plugins Notifications Notification for Microsoft Teams

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

Notification for Microsoft Teams

Rating
2 votes
Favoured:
0
Last Release Date
2019-03-01
Compatible With
  • Nagios 3.x
  • Nagios 4.x
Owner
License
Apache
Hits
17316
Files:
FileDescription
Screen Shot 2019-03-01 at 10.40.39 PM.pngScreen Shot 2019-03-01 at 10.40.39 PM.png
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!
Nagios plugin to send notifications to MS Teams (MessageCard)
Reviews (2)
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 arguments\n");

#
# 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$s\n";

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

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

byjeyminee, June 26, 2019
1 of 1 people found this review helpful
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