| #!/bin/env python |
| |
| import argparse |
| import requests |
| |
| 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_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 clear_event(self,event): |
| r = self.session.delete(self.url + event) |
| j = r.json() |
| if j['status'] != 'ok': |
| raise Exception("Failed to clear event " + event + ": \n" + r.text) |
| |
| |
| 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)) |
| |
| def do_clear_event(args): |
| s = BMC(server=args.server) |
| s.clear_event(args.event) |
| |
| def do_get_esel(args): |
| s = BMC(server=args.server) |
| e = s.get_event(args.event) |
| if e['Message'] != 'org.open_power.Error.Host.Event' and\ |
| e['Message'] != 'org.open_power.Error.Host.Event.Event': |
| raise Exception("Event is not from Host: " + e['Message']) |
| for d in e['AdditionalData']: |
| data = d.split("=") |
| tag = data.pop(0) |
| if tag != 'ESEL': |
| continue |
| data = "=".join(data) |
| if args.binary: |
| data = data.split(" ") |
| if '' == data[-1]: |
| data.pop() |
| data = "".join(map(lambda x: chr(int(x, 16)), data)) |
| print(data) |
| |
| |
| 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) |
| |
| get_esel = subparsers.add_parser( |
| 'get-esel', help='Extract OpenPOWER eSEL data for an individual event') |
| get_esel.add_argument('event', help='The event to get eSEL from') |
| get_esel.add_argument('--binary', help='Print event in raw binary', |
| action='store_const', const=True) |
| get_esel.set_defaults(func=do_get_esel) |
| |
| clear_event = subparsers.add_parser( |
| 'clear', help="Clear individual event") |
| clear_event.add_argument('event', help="The event to clear") |
| clear_event.set_defaults(func=do_clear_event) |
| |
| args = parser.parse_args() |
| |
| if 'func' in args: |
| args.func(args) |
| else: |
| parser.print_help() |