Snippets

Edel SM Get MPEs number player instances without the PIPE file in /tmp

Created by Edelberto Mania last modified
#!/usr/bin/env python

import requests,sys
from bs4 import BeautifulSoup

mpe_url='http://172.27.11.167/group2/api/?action=display_locid&type=MPE&locid=33'
service='Player+without+PIPE'
status_page='https://nagios.zenoradio.com/nagios/cgi-bin/extinfo.cgi?type=2&host={0}&service={1}'
status_page_login='edz-test'
status_page_password=''

## disable ssl warning
#requests.packages.urllib3.disable_warnings()

mpes=requests.get(mpe_url)

if mpes.status_code==200:mpes=mpes.json()
else:
    print('Error: {0}'.format(mpes.status_code))
    sys.exit(1)
    
for mpe in mpes['rows']:
    try:
        status_url=status_page.format(mpe['title'],service)
        output=requests.get(status_url,auth=(status_page_login,status_page_password),verify=False).text
        s=BeautifulSoup(output,'html.parser')
        data=s.body.find_all('table')[5].find_all('td')
        print('{0},{1}'.format(mpe['title'],data[5].string.split(':')[1]))
    except(IndexError):
        print('{0}, does not return correct ouput'.format(mpe['title']))
    

print(mpes['total'])

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.