diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index e7e771a6c5ed..39f1dccebf00 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -26,6 +26,7 @@ Table of Content: - [VictorOps](#transports-victorops) - [Canopsis](#transports-canopsis) - [osTicket](#transports-osticket) + - [Microsoft Teams](#transports-msteams) - [Entities](#entities) - [Devices](#entity-devices) - [BGP Peers](#entity-bgppeers) @@ -542,6 +543,22 @@ $config['alert']['transports']['osticket']['token'] = '123456789'; ``` ~~ +## Microsoft Teams + +[Using a proxy?](../Support/Configuration.md#proxy-support) + +Microsoft Teams. LibreNMS can send alerts to Microsoft Teams Connector API which are then posted to a specific channel. To configure the transport, go to: + +Global Settings -> Alerting Settings -> Microsoft Teams Transport. + +This can also be done manually in config.php : + +~ +```php +$config['alert']['transports']['msteams']['url'] = 'https://outlook.office365.com/webhook/123456789'; +``` +~ + # Entities Entities as described earlier are based on the table and column names within the database, if you are unsure of what the entity is you want then have a browse around inside MySQL using `show tables` and `desc `. diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 02a11bb5e3ef..632efb6e64c8 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -985,6 +985,28 @@ + + + + + '; +$msteams_url = get_config_by_name('alert.transports.msteams.url'); +echo ' +
+
+

+ Microsoft Teams transport +

+
+
+
+
+ +
+ +
diff --git a/includes/alerts/transport.msteams.php b/includes/alerts/transport.msteams.php new file mode 100644 index 000000000000..9aa49b5e1aa4 --- /dev/null +++ b/includes/alerts/transport.msteams.php @@ -0,0 +1,36 @@ +/* + * LibreNMS + * + * Copyright (c) 2016 Søren Friis Rosiak + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$url = $opts['url']; +$color = ($obj['state'] == 0 ? '#00FF00' : '#FF0000'); +$data = array( + 'title' => ($obj['name'] ? $obj['name'] . ' on ' . $obj['hostname'] : $obj['title']) , + 'themeColor' => $color , + 'text' => strip_tags($obj['msg']) +); +$curl = curl_init(); +set_curl_proxy($curl); +curl_setopt($curl, CURLOPT_URL, $url); +curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); +curl_setopt($curl, CURLOPT_HTTPHEADER, array( + 'Content-type' => 'application/json', + 'Expect:' +)); +curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); +$ret = curl_exec($curl); +$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + +if ($code != 200) { + var_dump("Microsoft Teams returned Error, retry later"); + return false; +} + +return true; diff --git a/sql-schema/151.sql b/sql-schema/151.sql new file mode 100644 index 000000000000..6ff9ca969262 --- /dev/null +++ b/sql-schema/151.sql @@ -0,0 +1 @@ +INSERT INTO config VALUES ('','alert.transports.msteams.url','','','Microsoft Teams Webhook URL','alerting',0, 'transports', 0, 0, 0);