File: //usr/lib/python2.7/site-packages/lap/check_asterisk_udp_ports.py
import os
import subprocess
import shlex
import sys,linecache, types, time
def __run__(params):
try:
norm = int(params.get("norm"))
warn = int(params.get("warn"))
crit = int(params.get("crit"))
except Exception, e:
return [2, "CRITICAL - Error getting params: %s" % repr(e)]
try:
command = "netstat -nupl | grep -c asterisk"
p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
stdout = p.communicate()[0]
count = int(stdout)
if count <= norm:
return [0, "OK - Used ports: %s" % (count)]
if count >= norm and count <= warn:
return [1, "WARN - Used ports: %s" % (count)]
else:
return [2, "CRIT - Used ports: %s" % (count)]
except Exception, e:
exc_type, exc_obj, tb = sys.exc_info()
f = tb.tb_frame
lineno = tb.tb_lineno
filename = f.f_code.co_filename
linecache.checkcache(filename)
line = linecache.getline(filename, lineno, f.f_globals)
return [2, 'Exception in ({}, line {} "{}"): {}'.format(filename, lineno, line.strip(), exc_obj)]