-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathfreeswitch.py
More file actions
100 lines (91 loc) · 3.11 KB
/
freeswitch.py
File metadata and controls
100 lines (91 loc) · 3.11 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
import sys
import subprocess
'''
add dataloop user to the daemon unix group and restart dataloop-agent service
'''
def show_calls_count():
command = ['/usr/local/freeswitch/bin/fs_cli', '-x', 'show calls count']
resp = subprocess.check_output(command).split('\n')
data = {}
for line in resp:
if 'total' in line:
data['show_calls_count.total'] = filter(lambda x: x.isdigit(), line)
return data
def sofia_status_internal():
command = ['/usr/local/freeswitch/bin/fs_cli', '-x', 'sofia status']
resp = subprocess.check_output(command).split('\n')
data = {}
for line in resp:
if 'internal' in line:
try:
details = line.split()
name = "sofia_status_%s.%s" % (details[0], details[2])
calls = details[4].replace('(', '').replace(')', '')
if details[3] == 'RUNNING':
data[name] = calls
except:
continue
return data
def sofia_status_external():
command = ['/usr/local/freeswitch/bin/fs_cli', '-x', 'sofia status']
resp = subprocess.check_output(command).split('\n')
data = {}
for line in resp:
if 'external' in line:
try:
details = line.split()
name = "sofia_status_%s.%s" % (details[0], details[2])
calls = details[4].replace('(', '').replace(')', '')
if details[3] == 'RUNNING':
data[name] = calls
except:
continue
return data
def sofia_status_profile_internal_failed_calls_in():
command = ['/usr/local/freeswitch/bin/fs_cli', '-x', 'sofia status profile internal']
resp = subprocess.check_output(command).split('\n')
data = {}
failed = 0
for line in resp:
if 'failed-calls-in' in line:
try:
details = line.split()
failed += 1
except:
continue
data['sofia_status_profile_internal_failed_calls_in.failed'] = failed
return data
def sofia_status_profile_internal_failed_calls_out():
command = ['/usr/local/freeswitch/bin/fs_cli', '-x', 'sofia status profile internal']
resp = subprocess.check_output(command).split('\n')
data = {}
failed = 0
for line in resp:
if 'failed-calls-out' in line:
try:
details = line.split()
failed += 1
except:
continue
data['sofia_status_profile_internal_failed_calls_out.failed'] = failed
return data
checks = [show_calls_count,
sofia_status_internal,
sofia_status_external,
sofia_status_profile_internal_failed_calls_in,
sofia_status_profile_internal_failed_calls_out]
# Compose big dict of all check output
raw_output = {}
for check in checks:
try:
raw_output.update(check())
except Exception, e:
print "Plugin Failed! %s" % e
sys.exit(2)
# Output in Nagios format
output = "OK | "
for k, v in raw_output.iteritems():
output += "%s=%s;;;; " % (k, v)
print output
sys.exit(0)