Initial commit
This commit is contained in:
33
plugins/asterisk.py
Normal file
33
plugins/asterisk.py
Normal file
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env python3
|
||||
import subprocess
|
||||
|
||||
#
|
||||
# Put plugin in /lib/check_mk_agent/plugins
|
||||
#
|
||||
|
||||
print("<<<asterisk_endpoints>>>")
|
||||
endpoints = []
|
||||
res = subprocess.check_output(["asterisk", "-rx", "pjsip show endpoints"]).decode('utf8')
|
||||
res = res.split("==\n\n")[1]
|
||||
res = res.split("Objects found")[0]
|
||||
|
||||
# Split the data into the endpoints and parse them info the list (endpoint, Contact, state(available/unavailable))
|
||||
for endpoint in res.split('Endpoint:')[1:]:
|
||||
endpoint = endpoint.strip()
|
||||
#print(endpoint)
|
||||
endpointV = endpoint.split(' ')[0]
|
||||
# Find the current state of the endpoint
|
||||
endP = endpoint.split('\n')[0].split()
|
||||
indexOfOF = endP.index('of')
|
||||
state = endP[1:indexOfOF-1]
|
||||
# Join state
|
||||
state = '_'.join(state)
|
||||
|
||||
channelUsed = endP[-1]
|
||||
channelAvail = endP[-3]
|
||||
|
||||
print(f'{endpointV}\t{state}\t{channelUsed}\t{channelAvail}')
|
||||
|
||||
|
||||
#asterisk -rx 'pjsip show endpoints'
|
||||
|
||||
Reference in New Issue
Block a user