Microsoft Teams Connector for notifications

I just added a small Update to the Docs, as there was a required perl module missing. Just make sure that you also have Perl URI::Encode installed.

Hello Rafael,

I wanted to know if you could help clarify how to setup this plugin please. I have imported json basket and created a command from it but am not sure where to go from there.

zones.d/director-global/command_templates.conf
template NotificationCommand "Teams Command" {
    import "plugin-notification-command"
    command = [ PluginDir + "/teams-service-notification" ]
    arguments += {
        "-p" = {
            required = true
            value = "https://.webhook.office.com/abc123"
        }
    }
}

What do I need to create in Director to get the notifications sent out? I was able to get this to send a test notification from the command line so I know it works. Any information you are willing to provide would be greatly appreciated.

Thank you,
Adam

Iam on that atm but i dont get any notifications.May i can see your config for that ? Are u using the director or local configs ?

I’am using the director. My config for the director is on github too. Just import the json.

Sry, havn’t seen you post. Have you got it up and running?

Hello Rafael

I came across this thread because I am also trying to send notification to teams. I have done the steps and run the script with -p but get the following error message.

root@server:/etc/icinga2/scripts# /etc/icinga2/scripts/teams-service-notification.pl -p https://xxx.webhook.office.com/webhookb2/e9xxxx-2a6xxcxxxx9040c17@522dxxxx5-4edb-b7ea-3ee1xxxxxxd1b/IncomingWebhook/95dxxxxx
syntax error at /etc/icinga2/scripts/teams-service-notification.pl line 33, near "my "
Global symbol "$icingaweb2url" requires explicit package name (did you forget to declare "my $icingaweb2url"?) at /etc/icinga2/scripts/teams-service-notification.pl line 33.
Global symbol "$icingaweb2url" requires explicit package name (did you forget to declare "my $icingaweb2url"?) at /etc/icinga2/scripts/teams-service-notification.pl line 56.
Global symbol "$icingaweb2url" requires explicit package name (did you forget to declare "my $icingaweb2url"?) at /etc/icinga2/scripts/teams-service-notification.pl line 104.
Global symbol "$icingaweb2url" requires explicit package name (did you forget to declare "my $icingaweb2url"?) at /etc/icinga2/scripts/teams-service-notification.pl line 108.
Execution of /etc/icinga2/scripts/teams-service-notification.pl aborted due to compilation errors.

In the given line this looks like

my $icingaweb2url = "https://monitoring.xxx.com";

This does not tell me anything…Can you give me some advice here?
Thanks a lot!

Please can you paste here the first 35 lines of your Perl script (obfuscating
any passwords etc)?

Antony.

Hello Antony,

Thanks for your reply!

Sure

#!/usr/bin/perl
#V0.2
#
# 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.

# modified version of nagios-mstreams.pl for icinga2 without env's
use warnings;
use strict;
#use URI::Encode;

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

my %event;
my %nagios;
my @sections;
my @actions;
my @targets;
my $webhook = "https://xxx.webhook.office.com/webhookb2/e964d501-xxxx89-fd3659040c17@522dexxxx/IncomingWebhook/xxxx"
my $icingaweb2url = "https://monitoring.xxx.com/";
my $proxyUrl = '';
my %color = ( 'OK' => '008000', 'WARNING' => 'ffff00', 'UNKNOWN' => '808080','CRITICAL' => 'ff0000',
              'UP' => '008000', 'DOWN' => 'ff0000', 'UNREACHABLE' => 'ff8700');
my $webhookuid;

L For Luketastic

No problem. You are missing a semicolon at the end of the previous line.

Antony.

Hello Antony!

Thank you very much! What a … fail from my side. I got a teams notification :)! But i got it without any kind of information.

teams

The first line looks like this:

public function init()
    {
        $service = new Service(
            $this->backend,
            $this->params->getRequired('host'),
            $this->params->getRequired('service')

Do you have an idea?

Thank you!

Hi, did you found your solution?
If you only use the “p” parameter the rest of the informations are missing. Normaly they are filled by Icinga if you uses the director template. For lazy testing purposes i have not added a check if required variables are missing :wink:

For a complete example line, check the log posted here: