Hi all,
We’re in the process of setting up alerts specifically for RSSI changes on microwave links, and the alert itself is all good.
The hurdle we have at the moment is allowing an acknowledgement of an alert via the API from the teams notification itself, but worth noting this isnt an issue to do with teams, it would affect any transport method, and fundamentally we’re unable to access some data to generate the correct URL.
An example alert currently gives us the following data in the notification.
$alert->id = 249.
But if we check the list of alerts from the command line with curl, using alerts?state=1 that same alert has an id of 23, and 23 is infact the correct id to send the API request to acknowledge.
Where are we going wrong to bring in the ID of the alert so the acknowledgement address can be correctly generated in the notifcation?
Also note, most of this code is taken then modified directly from either the inbuilt templates or from LibreNMS official docs page.
See below code for reference, and before anyone is concerned, the IP’s and token is all for our lab environment only, so not worried about censoring.
Thanks!
{
"@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": [
{
"facts": [
{
"name": "Rule:",
"value": "[{{ $alert->name }}](http://10.211.55.12/device/device={{ $alert->device_id }}/tab=alert/)"
},
{
"name": "Severity:",
"value": "{{ $alert->severity }}"
},
{
"name": "Unique-ID:",
"value": "{{ $alert->id }}"
},
{
"name": "Timestamp:",
"value": "{{ $alert->timestamp }}"
},
{
"name": "Hostname:",
"value": "[{{ $alert->hostname }}](http://10.211.55.12/device/device={{ $alert->device_id }}/)"
},
{
"name": "Hardware:",
"value": "{{ $alert->hardware }}"
},
{
"name": "IP:",
"value": "{{ $alert->ip }}"
},
{
"name": "Faults:",
"value": "
@foreach ($alert->faults as $key => $value)
@php($unit = __("sensors.${value["sensor_class"]}.unit"))
{{ $key }}: {{ $value['sensor_descr'] ?? 'Sensor' }}
Current: {{ $value['sensor_current'].$value['sensor_current.unit'].' dBm' }}
Previous: {{ $value['sensor_prev'].' dBm' }}
Warning Limit: {{ $value['sensor_limit_low_warn'].' dBm'}}
Critical Limit: {{ $value['sensor_limit_low'].' dBm' }}
@endforeach
"
}
],
@if ($alert->state != 0)
"potentialAction": [
{
"@type": "ActionCard",
"name": "Acknowledge",
"inputs": [
{
"@type": "TextInput",
"id": "acknowledgeComment",
"isMultiline": false,
"title": "Comment (optional)"
}
],
"actions": [
{
"@type": "HttpPOST",
"name": "Acknowledge",
"target": "http://10.211.55.12/api/v0/alerts/{{$alert->id}}",
"headers": [
{
"name": "X-Auth-Token",
"value": "6935907ea0e79497188ac96a1f52c230"
}
],
"body": "{\"comment\": \"{{ $acknowledgeComment }}\"}"
}
]
}
]
@endif
}
]
}