blob: c54dc976a3c176a88072a006e2b13e38f6dc1a71 [file] [log] [blame]
#!/bin/env python
import argparse
import requests
import json
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
class BMC:
def __init__(self, server):
self.url = "https://{0}/".format(server)
self.session = requests.Session()
self.login()
def login(self):
r = self.session.post(self.url + 'login',
json={'data': ['root', '0penBmc']},
verify=False)
j = r.json()
if j['status'] != 'ok':
raise Exception("Failed to login: \n" + r.text)
def list_all(self):
r = self.session.get(self.url + 'xyz/openbmc_project/sensors/enumerate',
verify=False)
j = r.json()
if j['status'] != 'ok':
raise Exception("Failed to query sensors: \n" + r.text)
sensors = j['data']
#sensors.sort(key=lambda x: int(x.split("/")[-1]))
return sensors
def get_sensor(self, sensor):
r = self.session.get(self.url + sensor, verify=False)
j = r.json()
if j['status'] != 'ok':
raise Exception("Failed to get sensor " + sensor + ": \n" + r.text)
return j['data']
def do_list_all(args):
s = BMC(server=args.server)
for e in s.list_all():
print(e)
def do_view_sensor(args):
s = BMC(server=args.server)
print(s.get_sensor(args.sensor))
print json.dumps(s.get_sensor(args.sensor), indent=4)
parser = argparse.ArgumentParser()
parser.add_argument('--server', help='hostname or IP of BMC', type=str,
required=True)
subparsers = parser.add_subparsers()
list_all_sensors = subparsers.add_parser('list', help='List all sensors on BMC')
list_all_sensors.set_defaults(func=do_list_all)
view_sensor = subparsers.add_parser(
'view', help='View all data for an individual sensor')
view_sensor.add_argument('sensor', help='The sensor to view')
view_sensor.set_defaults(func=do_view_sensor)
args = parser.parse_args()
if 'func' in args:
args.func(args)
else:
parser.print_help()