| #!/bin/env python |
| |
| import argparse |
| import requests |
| |
| 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_events(self): |
| r = self.session.get(self.url + 'xyz/openbmc_project/logging/entry/', |
| verify=False) |
| j = r.json() |
| if j['status'] != 'ok': |
| raise Exception("Failed to query entries: \n" + r.text) |
| |
| events = j['data'] |
| events.sort(key=lambda x: int(x.split("/")[-1])) |
| |
| return events |
| |
| def get_event(self, event): |
| r = self.session.get(self.url + event, verify=False) |
| |
| j = r.json() |
| if j['status'] != 'ok': |
| raise Exception("Failed to get event " + event + ": \n" + r.text) |
| |
| return j['data'] |
| |
| |
| def do_list_events(args): |
| s = BMC(server=args.server) |
| for e in s.list_events(): |
| print(e) |
| |
| |
| def do_view_event(args): |
| s = BMC(server=args.server) |
| print(s.get_event(args.event)) |
| |
| |
| parser = argparse.ArgumentParser() |
| parser.add_argument('--server', help='hostname or IP of BMC', type=str, |
| required=True) |
| |
| subparsers = parser.add_subparsers() |
| list_events = subparsers.add_parser('list', help='List all events on BMC') |
| list_events.set_defaults(func=do_list_events) |
| view_event = subparsers.add_parser( |
| 'view', help='View all data for an individual event') |
| view_event.add_argument('event', help='The event to view') |
| view_event.set_defaults(func=do_view_event) |
| |
| args = parser.parse_args() |
| |
| if 'func' in args: |
| args.func(args) |
| else: |
| parser.print_help() |