| #!/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 do_list_events(args): |
| s = BMC(server=args.server) |
| for e in s.list_events(): |
| print(e) |
| |
| 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) |
| |
| args = parser.parse_args() |
| |
| if 'func' in args: |
| args.func(args) |
| else: |
| parser.print_help() |