-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_asterisk_pri.py
More file actions
executable file
·67 lines (55 loc) · 1.81 KB
/
check_asterisk_pri.py
File metadata and controls
executable file
·67 lines (55 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/python
# Script: check_asterisk_pri.py
# Author: Haris Buchal blog.axiomdynamics.com
# Description: Plugin for Nagios (and forks) to check status for PRI status
# on Asterisk server. It uses 'pri show spans' command and parses the
# output for status on each card found. It requires python 2.6+.
# THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY.
# License: GPLv2
# Version: 1.0
# 20160429 Created plugin
import subprocess
import sys
import os
CMD="/usr/sbin/asterisk"
CMD_ARG1="-x"
CMD_ARG1_VAL="pri show spans"
#Nagios exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
if not (os.path.isfile(CMD) and os.access(CMD,os.X_OK)):
print "Unknown: ",CMD," not found"
sys.exit(STATE_UNKNOWN)
cmd = subprocess.Popen(['sudo',CMD, CMD_ARG1, CMD_ARG1_VAL],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
try:
result = cmd.communicate()
except OSError, e:
print >>sys.stderr, "Execution failed:",e
sys.exit(STATE_UNKNOWN)
if result[1] == "": # no error
output = result[0]
if output == "" or len(output) <=0:
print "Warning: No PRI spans present"
sys.exit(STATE_WARNING)
pri_spans = output.splitlines()
problem_pri_span = []
for i in pri_spans:
pri_span = i.split(':')
pri_span_status = pri_span[1].strip()
if "Up,Active" not in "".join(pri_span_status.split()):
problem_pri_span.append(i)
if len(problem_pri_span) > 0:
for i in problem_pri_span:
print "Critical:",i
sys.exit(STATE_CRITICAL)
else:
for i in pri_spans:
print "OK:",i
sys.exit(STATE_OK)
else:
print "Command",ocmd,"returned error:",result[1]
sys.exit(STATE_UNKNOWN)