diff --git a/LibreNMS/Alert/Transport/Msteams.php b/LibreNMS/Alert/Transport/Msteams.php index 4d5657e9dc..0193d574cd 100644 --- a/LibreNMS/Alert/Transport/Msteams.php +++ b/LibreNMS/Alert/Transport/Msteams.php @@ -28,7 +28,6 @@ class Msteams extends Transport public function contactMsteams($obj, $opts) { $url = $opts['url']; - $data = array( 'title' => $obj['title'], 'themeColor' => self::getColorForState($obj['state']), @@ -43,9 +42,11 @@ class Msteams extends Transport 'Expect:' )); curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); + if ($this->config['use-json'] === 'on' && $obj['uid'] !== '000') { + curl_setopt($curl, CURLOPT_POSTFIELDS, $obj['msg']); + } $ret = curl_exec($curl); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - if ($code != 200) { var_dump("Microsoft Teams returned Error, retry later"); return false; @@ -62,6 +63,13 @@ class Msteams extends Transport 'name' => 'msteam-url', 'descr' => 'Microsoft Teams Webhook URL', 'type' => 'text', + ], + [ + 'title' => 'Use JSON?', + 'name' => 'use-json', + 'descr' => 'Compose MessageCard with JSON rather than Markdown', + 'type' => 'checkbox', + 'default' => false, ] ], 'validation' => [ diff --git a/doc/Alerting/Templates.md b/doc/Alerting/Templates.md index 87a8929dc6..e6bfe93fb2 100644 --- a/doc/Alerting/Templates.md +++ b/doc/Alerting/Templates.md @@ -361,21 +361,6 @@ Template: CPU alert
@endif ``` -#### MS Teams formatted default template - -``` -{{ $alert->title }} -
Device name: {{ $alert->sysName }}
-Severity: {{ $alert->severity }}
-@if ($alert->state == 0)Time elapsed:{{ $alert->elapsed }}
-@endifTimestamp: {{ $alert->timestamp }}
-Unique-ID: {{ $alert->uid }}
-Rule:@if ($alert->name) {{ $alert->name }} @else {{ $alert->rule }} @endif
-
@if ($alert->faults) Faults:
- @foreach ($alert->faults as $key => $value)  #{{ $key }}: {{ $value['string'] }}
- @endforeach 
@endif -``` - ## Included We include a few templates for you to use, these are specific to the @@ -388,3 +373,131 @@ The included templates apart from the default template are: - BGP Sessions - Ports - Temperature + +## Other Examples + +#### Microsoft Teams - Markdown + +``` +[{{ $alert->title }}](https://your.librenms.url/device/device={{ $alert->device_id }}/) +**Device name:** {{ $alert->sysName }} +**Severity:** {{ $alert->severity }} +@if ($alert->state == 0) +**Time elapsed:** {{ $alert->elapsed }} +@endif +**Timestamp:** {{ $alert->timestamp }} +**Unique-ID:** {{ $alert->uid }} +@if ($alert->name) +**Rule:** {{ $alert->name }} +@else +**Rule:** {{ $alert->rule }} +@endif +@if ($alert->faults) +**Faults:**@foreach ($alert->faults as $key => $value) {{ $key }}: {{ $value['string'] }} +@endforeach +@endif +``` + +#### Microsoft Teams - JSON + +``` +{ + "@context": "https://schema.org/extensions", + "@type": "MessageCard", + "title": "{{ $alert->title }}", +@if ($alert->state === 0) + "themeColor": "00FF00", +@elseif ($alert->state === 1) + "themeColor": "FF0000", +@elseif ($alert->state === 2) + "themeColor": "337AB7", +@elseif ($alert->state === 3) + "themeColor": "FF0000", +@elseif ($alert->state === 4) + "themeColor": "F0AD4E", +@else + "themeColor": "337AB7", +@endif + "summary": "LibreNMS", + "sections": [ + { +@if ($alert->name) + "facts": [ + { + "name": "Rule:", + "value": "[{{ $alert->name }}](https://your.librenms.url/device/device={{ $alert->device_id }}/tab=alert/)" + }, +@else + { + "name": "Rule:", + "value": "[{{ $alert->rule }}](https://your.librenms.url/device/device={{ $alert->device_id }}/tab=alert/)" + }, +@endif + { + "name": "Severity:", + "value": "{{ $alert->severity }}" + }, + { + "name": "Unique-ID:", + "value": "{{ $alert->uid }}" + }, + { + "name": "Timestamp:", + "value": "{{ $alert->timestamp }}" + }, +@if ($alert->state == 0) + { + "name": "Time elapsed:", + "value": "{{ $alert->elapsed }}" + }, +@endif + { + "name": "Hostname:", + "value": "[{{ $alert->hostname }}](https://your.librenms.url/device/device={{ $alert->device_id }}/)" + }, + { + "name": "Hardware:", + "value": "{{ $alert->hardware }}" + }, + { + "name": "IP:", + "value": "{{ $alert->ip }}" + }, + { + "name": "Faults:", + "value": " " + } + ] +@if ($alert->faults) +@foreach ($alert->faults as $key => $value) + }, + { + "facts": [ + { + "name": "Port:", + "value": "[{{ $value['ifName'] }}](https://your.librenms.url/device/device={{ $alert->device_id }}/tab=port/port={{ $value['port_id'] }}/)" + }, + { + "name": "Description:", + "value": "{{ $value['ifAlias'] }}" + }, +@if ($alert->state != 0) + { + "name": "Status:", + "value": "down" + } + ] +@else + { + "name": "Status:", + "value": "up" + } + ] +@endif +@endforeach +@endif + } + ] +} +``` + diff --git a/doc/Alerting/Transports.md b/doc/Alerting/Transports.md index 37c8ab4a03..9ed98bac85 100644 --- a/doc/Alerting/Transports.md +++ b/doc/Alerting/Transports.md @@ -356,14 +356,19 @@ As a small reminder, here is it's configuration directives including defaults: ## Microsoft Teams -Microsoft Teams. LibreNMS can send alerts to Microsoft Teams Connector -API which are then posted to a specific channel. +LibreNMS can send alerts to Microsoft Teams [Incoming Webhooks](https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/add-incoming-webhook) which are +then posted to a specific channel. Microsoft recommends using +[markdown](https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format#markdown-formatting-for-connector-cards) formatting for connector cards. +Administrators can opt to [compose](https://messagecardplayground.azurewebsites.net/) +the [MessageCard](https://docs.microsoft.com/en-us/outlook/actionable-messages/message-card-reference) +themselves using JSON to get the full functionality. **Example:** | Config | Example | | ------ | ------- | | WebHook URL | | +| Use JSON? | x | ## Nagios Compatible