aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nagios_client/files/usr
diff options
context:
space:
mode:
authorStonewall Jackson <stonewall@sacredheartsc.com>2023-02-06 20:31:20 -0500
committerStonewall Jackson <stonewall@sacredheartsc.com>2023-02-06 20:36:16 -0500
commit969fc7c21dc7fa85dcc516aedf8e816ee8bc8bd6 (patch)
tree23ac2860839bfe9b6045841a9834f50a36f88a82 /roles/nagios_client/files/usr
parentd2e954c37b1b2111ae1ca7f489ae170180491522 (diff)
downloadselfhosted-969fc7c21dc7fa85dcc516aedf8e816ee8bc8bd6.tar.gz
selfhosted-969fc7c21dc7fa85dcc516aedf8e816ee8bc8bd6.zip
set max_retries to UINT32_MAX for asterisk registrations
After a brief internet outage, I noticed that asterisk had given up trying to reconnect to my upstream SIP server (looks like the default value of max_retries is 10). Although the asterisk "registration" object was disconnected, the "endpoint" object still reported being up, so the check_asterisk_endpoints nagios plugin did not alert me to the problem. This commit sets max_retries to UNIT32_MAX for asterisk registrations by default. It also adds a new nagios plugin, check_asterisk_registrations. Unfortunately, the ARI does not expose registrations via the REST API, so I had to write a hacky bash script to parse the asterisk CLI output.
Diffstat (limited to 'roles/nagios_client/files/usr')
-rw-r--r--roles/nagios_client/files/usr/lib64/nagios/plugins/check_asterisk_registrations40
1 files changed, 40 insertions, 0 deletions
diff --git a/roles/nagios_client/files/usr/lib64/nagios/plugins/check_asterisk_registrations b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_asterisk_registrations
new file mode 100644
index 0000000..132e4e3
--- /dev/null
+++ b/roles/nagios_client/files/usr/lib64/nagios/plugins/check_asterisk_registrations
@@ -0,0 +1,40 @@
+#!/bin/bash
+
+set -Eeu -o pipefail
+shopt -s lastpipe
+
+trap 'exit 3' ERR
+
+ok=()
+error=()
+
+sudo asterisk -rx 'pjsip show registrations' \
+ | sed '1,4d' \
+ | head -n2 \
+ | while read -r uri auth status
+do
+ msg="${auth} is ${status,,}"
+ if [ "$status" = Registered ]; then
+ ok+=("$msg")
+ else
+ err+=("$msg")
+ fi
+done
+
+if (( ${#error[@]} )); then
+ echo 'trunk is not registered!'
+ RC=2
+else
+ echo 'all trunks registered'
+ RC=0
+fi
+
+if (( ${#error[@]} )); then
+ printf 'CRIT: %s\n' "${error[@]}"
+fi
+
+if (( ${#ok[@]} )); then
+ printf 'OK: %s\n' "${ok[@]}"
+fi
+
+exit $RC