Created
December 2, 2022 09:30
-
-
Save khorsmann/fef11952a99114bb2097e2cc66237e38 to your computer and use it in GitHub Desktop.
kamailio uac module state checker for nagios or check_mk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/env python3 | |
import sys | |
import shlex | |
import json | |
from subprocess import Popen | |
from subprocess import PIPE | |
get_pid = shlex.split("pgrep -c [k]amailio") | |
uac_cmd = shlex.split("/usr/sbin/kamctl rpc uac.reg_dump") | |
check_name = "uac_reg_" | |
def getProcessOutput(cmd): | |
p1 = Popen(cmd, stdout=PIPE) | |
p1.wait() | |
data, err = p1.communicate() | |
if p1.returncode is 0: | |
return data.decode("utf-8") | |
else: | |
return err | |
def print_checkmk(msg, exit=0, check_name=check_name): | |
print("{0} {1} - {2}".format(exit, check_name, msg)) | |
if not getProcessOutput(get_pid): | |
sys.exit(0) | |
try: | |
input_json = getProcessOutput(uac_cmd) | |
input_dict = json.loads(input_json) | |
except: | |
sys.exit(1) | |
if "result" not in input_dict: | |
sys.exit(0) | |
okay = 0 | |
warning = 1 | |
crit = 2 | |
unknown = 3 | |
for dic in input_dict["result"]: | |
check = check_name + dic["l_uuid"] | |
if dic["flags"] == 1: | |
message = "l_uuid: {l_uuid} register flag: {flags} Status: ADMIN DISABLED".format( | |
**dic | |
) | |
print_checkmk(check_name=check, msg=message, exit=okay) | |
elif dic["flags"] == 2: | |
message = "l_uuid: {l_uuid} register flag: {flags} Status: IN PROGRESS".format( | |
**dic | |
) | |
print_checkmk(check_name=check, msg=message, exit=warning) | |
elif dic["flags"] == 16: | |
message = "l_uuid: {l_uuid} register flag: {flags} Status: INITIALIZE".format( | |
**dic | |
) | |
print_checkmk(check_name=check, msg=message, exit=crit) | |
elif dic["flags"] == 20: | |
message = "l_uuid: {l_uuid} register flag: {flags} Status: OK Re-Register in: {diff_expires} sec".format( | |
**dic | |
) | |
print_checkmk(check_name=check, msg=message, exit=okay) | |
else: | |
message = "l_uuid: {l_uuid} register flag: {flags} Status: UNKNOWN".format(**dic) | |
print_checkmk(check_name=check, msg=message, exit=crit) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment