Microsoft Teams Connector for notifications

added the variable notification_icingaweb2url to the Notification template it’s worked a treat, just needed to get the fqdn and path sorted. Thanks for the help

1 Like

Its funny: by reading the code, i have no idea why that is working :slight_smile:

Here is an example for the notifications:

Hi!
I have imported the JSON file for director BASKET…
I have also restore the 2 notifications commands from JSON

I created a command like this:
/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx

But no notification arrive to my channel…
How do I have to create the command for notification ?
THX

Do you get any output from the command when running it from the command line?
Have you tried adding more parameters, like hostname, servicename, serviceouput?

if you execute your command line from the console it should work.

“/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx” are enough parameters to send the notification. It willl throw some errors, but it works.

the Output on the console should look like this:

/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/x
Use of uninitialized value $servicestate in string at /etc/icinga2/scripts/teams-service-notification.pl line 80.
Use of uninitialized value $hostdisplayname in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $servicename in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $servicestate in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $hostdisplayname in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $servicename in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $serviceoutput in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $servicename in substitution (s///) at /etc/icinga2/scripts/teams-service-notification.pl line 106.
Use of uninitialized value $hostname in substitution (s///) at /etc/icinga2/scripts/teams-service-notification.pl line 107.
Use of uninitialized value $hostname in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 108.
Use of uninitialized value $servicename in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 108.
Request:
POST https://outlook.office.com/webhook/x
Content-Type: application/json

{"sections":[{"facts":[{"value":"","name":"Host:"},{"value":"","name":"Service:"},{"value":"","name":"Details:"}]}],"summary":" :  is ","title":" :  is ","themecolor":null,"@type":"MessageCard","@context":"https://schema.org/extensions","potentialAction":[{"targets":[{"os":"default","uri":"https://dom/icingaweb2/monitoring/service/show?host=&service="}],"@type":"OpenUri","name":"Open in Icinga2"}]}

Response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Mon, 09 Mar 2020 07:51:44 GMT
Pragma: no-cache
Content-Length: 1
Content-Type: text/plain; charset=utf-8
Expires: -1
[...]

1

{"sections":[{"facts":[{"value":"","name":"Host:"},{"value":"","name":"Service:"},{"value":"","name":"Details:"}]}],"summary":" :  is ","title":" :  is ","themecolor":null,"@type":"MessageCard","@context":"https://schema.org/extensions","potentialAction":[{"targets":[{"os":"default","uri":"https://dom/icingaweb2/monitoring/service/show?host=&service="}],"@type":"OpenUri","name":"Open in Icinga2"}]}r

If this is not working you have some other problems.

Hi and thanks for the plugin.

Could you please guide me how to import the json to get the command with all arguments?

I just imported the json into a basket using director but I cannot see the command with arguments imported… I had to create the command manually and use the -p = $user.pager$ to make it work as a test.

Hi,

after import, click on Snapshots, select the only one that is there and click import.

1 Like

Thank you for your help. Now I’m getting notifications on teams.

Cris,

1 Like

Hello,

I have already configured this addon.
But the Problem ist, i couldnt receive any notifications.
When i try “/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx”

The Notification is in Teams…
What i did wrong?

Kind regrads :slight_smile:

Update:
I used the -p option and
I removed the Value “$user.pager$” and set my webhook link and it works.
(“value”: “$user.pager$”)
:slight_smile:

1 Like

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: