List Index out of Range
rmammina opened this issue · comments
Ryan commented
Felippe Silvestre commented
Hi @rmammina
it'll happen for all unloaded/unnecessary modules.
You can quickly fix it in this case by adding a response verification regexp for "No such command":
#IAX2 Peers
iax_result = mgr.command('iax2 show peers')
iax_results = iax_result.data.split('\n')
iax_total_line = iax_results[len(iax_results)-3]
if not re.findall(r'No such command',iax_total_line)[0]:
iax_peers_total = re.findall(r'([0-9]+) iax2 peers',iax_total_line)[0]
iax_peers_online = re.findall(r'\[([0-9]+) online',iax_total_line)[0]
iax_peers_offline = re.findall(r'([0-9]+) offline',iax_total_line)[0]
iax_peers_unmonitored = re.findall(r'([0-9]+) unmonitored',iax_total_line)[0]
print('Total IAX2 Peers')
print(iax_peers_total)
print('IAX2 Peers Online')
print(iax_peers_online)
print('IAX2 Peers Offline')
print(iax_peers_offline)
print('IAX2 Peers Unmonitored')
print(iax_peers_unmonitored)
I'll try to improve it since i'll use it for production monitoring too.
Hope that helps you.Miguel Torres commented
That's a good fix.. I'll try to put it on all the requests to the PBX through the AMI. Thanks a lot..
Miguel Torres commented
Fixed with #21