[packages/nagios-plugin-check_sip_peer] Initial
arekm
arekm at pld-linux.org
Thu Mar 23 10:00:13 CET 2023
commit ebeb9c504d5f7e78f4c3487c48336f9a38037c47
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Thu Mar 23 09:59:44 2023 +0100
Initial
check_sip_peer.py | 66 +++++++++++++++++++++++++++++++++++++++
nagios-plugin-check_sip_peer.spec | 41 ++++++++++++++++++++++++
2 files changed, 107 insertions(+)
---
diff --git a/nagios-plugin-check_sip_peer.spec b/nagios-plugin-check_sip_peer.spec
new file mode 100644
index 0000000..af0de82
--- /dev/null
+++ b/nagios-plugin-check_sip_peer.spec
@@ -0,0 +1,41 @@
+Summary: Nagios plugin to check SIP peer status
+Name: nagios-plugin-check_sip_peer
+Version: 0.1
+Release: 1
+License: GPL v3+
+Group: Networking
+Source0: check_sip_peer.py
+# Source0-md5: 6bccc1b1fcd481df7065c6285aadbe25
+BuildRequires: rpm-pythonprov
+BuildRequires: rpmbuild(macros) >= 1.654
+Requires: nagios-core
+Requires: nagios-plugins-libs
+Requires: python3-modules
+Requires: python3-sarge
+BuildArch: noarch
+BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
+
+%define _plugindir %{_prefix}/lib/nagios/plugins
+%define _sysconfdir /etc/nagios/plugins
+
+%define _noautoreq_perl utils
+
+%description
+This plugin will test a SIP peer status.
+
+%prep
+%setup -q -c -T
+
+%install
+rm -rf $RPM_BUILD_ROOT
+
+install -d $RPM_BUILD_ROOT{%{_sysconfdir},%{_plugindir}}
+
+cp -p %{SOURCE0} $RPM_BUILD_ROOT%{_plugindir}/check_sip_peer
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%files
+%defattr(644,root,root,755)
+%attr(755,root,root) %{_plugindir}/check_sip_peer
diff --git a/check_sip_peer.py b/check_sip_peer.py
new file mode 100755
index 0000000..d2ef1e6
--- /dev/null
+++ b/check_sip_peer.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python3
+# GPL v3+ arekm at pld
+
+import argparse
+import re
+import sarge
+import sys
+
+NAGIOS_OK = 0
+NAGIOS_WARNING = 1
+NAGIOS_CRITICAL = 2
+NAGIOS_UNKNOWN = 3
+
+STATUS_MAP = {NAGIOS_CRITICAL: 'CRITICAL', NAGIOS_WARNING: 'WARNING', NAGIOS_OK: 'OK', NAGIOS_UNKNOWN: 'UNKNOWN'}
+
+nagios_status = NAGIOS_OK
+
+try:
+ parser = argparse.ArgumentParser(description='Check SIP peer status in Asterisk')
+ parser.add_argument('--peer', action='store', dest='peer', help='SIP peer name', required=True)
+ parser.add_argument('--socket', action='store', dest='socket', help='Asterisk socket path', default=" /var/run/asterisk/asterisk.ctl")
+ args = parser.parse_args()
+except Exception as e:
+ nagios_status = NAGIOS_UNKNOWN
+ print("{status}: {msg}".format(status=STATUS_MAP[nagios_status], msg=e))
+ sys.exit(nagios_status)
+
+try:
+ cmd = '/usr/sbin/asterisk -r -s {socket} -x "sip show peer {peer}"'.format(socket=args.socket, peer=args.peer)
+ c = sarge.capture_both(cmd)
+ if c.returncode != 0:
+ nagios_status = NAGIOS_CRITICAL
+ print("{status}: peer={peer}, {msg}".format(status=STATUS_MAP[nagios_status], peer=args.peer,
+ msg=c.stdout.text.replace('\n', '; ') + "; " + c.stderr.text.replace('\n', '; ')))
+ sys.exit(nagios_status)
+
+ host = re.search(r"Addr->IP\s+: (.*)", c.stdout.text)
+ if host:
+ host = host.group(1)
+ else:
+ host = "(unknown host)"
+ status = re.search(r"Status\s+: (.*)", c.stdout.text)
+ if not status:
+ nagios_status = NAGIOS_CRITICAL
+ print("{status}: peer={peer}, {msg}".format(status=STATUS_MAP[nagios_status], peer=args.peer,
+ msg=c.stdout.text.replace('\n', '; ') + "; " + c.stderr.text.replace('\n', '; ')))
+ sys.exit(nagios_status)
+
+ sip_status = status.group(1)
+ if sip_status.find("OK") >= 0:
+ nagios_status = NAGIOS_OK
+ elif sip_status.find("LAGGED") >= 0:
+ nagios_status = NAGIOS_WARNING
+ elif sip_status.find("UNREACHABLE") >= 0:
+ nagios_status = NAGIOS_CRITICAL
+ else:
+ nagios_status = NAGIOS_UNKNOWN
+ print("{status}: peer={peer}, sip_status={sip_status}, host={host}".format(status=STATUS_MAP[nagios_status],
+ peer=args.peer, sip_status=sip_status, host=host))
+ sys.exit(nagios_status)
+
+except Exception as e:
+ nagios_status = NAGIOS_UNKNOWN
+ print("{status}: peer={peer}, {msg}".format(status=STATUS_MAP[nagios_status], peer=args.peer, msg=e))
+ sys.exit(nagios_status)
+
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/nagios-plugin-check_sip_peer.git/commitdiff/ebeb9c504d5f7e78f4c3487c48336f9a38037c47
More information about the pld-cvs-commit
mailing list