blob: ac0615b742416e7f663250b1374f9300d7e8111b [file] [log] [blame]
Patrick Williamsb19c34c2017-03-27 14:52:28 -05001#!/bin/env python
2
Patrick Williams9b05ea32017-03-27 15:22:31 -05003import argparse
Patrick Williamsb19c34c2017-03-27 14:52:28 -05004import requests
5
Patrick Williams533c13a2017-03-27 15:28:51 -05006
Patrick Williamsb19c34c2017-03-27 14:52:28 -05007class BMC:
8 def __init__(self, server):
9 self.url = "https://{0}/".format(server)
10 self.session = requests.Session()
11 self.login()
12
13 def login(self):
14 r = self.session.post(self.url + 'login',
Patrick Williams533c13a2017-03-27 15:28:51 -050015 json={'data': ['root', '0penBmc']},
Patrick Williamsb19c34c2017-03-27 14:52:28 -050016 verify=False)
17 j = r.json()
18 if j['status'] != 'ok':
19 raise Exception("Failed to login: \n" + r.text)
20
Patrick Williamsec472d82017-03-27 15:15:43 -050021 def list_events(self):
22 r = self.session.get(self.url + 'xyz/openbmc_project/logging/entry/',
23 verify=False)
24 j = r.json()
25 if j['status'] != 'ok':
26 raise Exception("Failed to query entries: \n" + r.text)
27
28 events = j['data']
29 events.sort(key=lambda x: int(x.split("/")[-1]))
30
31 return events
Patrick Williamsb19c34c2017-03-27 14:52:28 -050032
Patrick Williams5e98b3a2017-03-27 15:28:35 -050033 def get_event(self, event):
34 r = self.session.get(self.url + event, verify=False)
35
36 j = r.json()
37 if j['status'] != 'ok':
38 raise Exception("Failed to get event " + event + ": \n" + r.text)
39
40 return j['data']
41
Patrick Williamsb19c34c2017-03-27 14:52:28 -050042
Patrick Williams9b05ea32017-03-27 15:22:31 -050043def do_list_events(args):
44 s = BMC(server=args.server)
45 for e in s.list_events():
46 print(e)
47
Patrick Williams5e98b3a2017-03-27 15:28:35 -050048
49def do_view_event(args):
50 s = BMC(server=args.server)
51 print(s.get_event(args.event))
52
Patrick Williams4296f4b2017-03-27 16:26:41 -050053
Patrick Williams7a09b672017-03-27 15:39:12 -050054def do_get_esel(args):
55 s = BMC(server=args.server)
56 e = s.get_event(args.event)
57 if e['Message'] != 'org.open_power.Error.Host.Event' and\
58 e['Message'] != 'org.open_power.Error.Host.Event.Event':
59 raise Exception("Event is not from Host: " + e['Message'])
60 for d in e['AdditionalData']:
Patrick Williams842308b2017-03-27 15:49:38 -050061 data = d.split("=")
62 tag = data.pop(0)
Patrick Williams7a09b672017-03-27 15:39:12 -050063 if tag != 'ESEL':
64 continue
65 data = "=".join(data)
Patrick Williams6f5c3ea2017-03-27 16:23:52 -050066 if args.binary:
67 data = data.split(" ")
68 if '' == data[-1]:
69 data.pop()
70 data = "".join(map(lambda x: chr(int(x, 16)), data))
Patrick Williams7a09b672017-03-27 15:39:12 -050071 print(data)
72
Patrick Williams5e98b3a2017-03-27 15:28:35 -050073
Patrick Williams9b05ea32017-03-27 15:22:31 -050074parser = argparse.ArgumentParser()
75parser.add_argument('--server', help='hostname or IP of BMC', type=str,
76 required=True)
77
78subparsers = parser.add_subparsers()
79list_events = subparsers.add_parser('list', help='List all events on BMC')
80list_events.set_defaults(func=do_list_events)
Patrick Williams5e98b3a2017-03-27 15:28:35 -050081view_event = subparsers.add_parser(
82 'view', help='View all data for an individual event')
83view_event.add_argument('event', help='The event to view')
84view_event.set_defaults(func=do_view_event)
Patrick Williams7a09b672017-03-27 15:39:12 -050085get_esel = subparsers.add_parser(
86 'get-esel', help='Extract OpenPOWER eSEL data for an individual event')
87get_esel.add_argument('event', help='The event to get eSEL from')
Patrick Williams6f5c3ea2017-03-27 16:23:52 -050088get_esel.add_argument('--binary', help='Print event in raw binary',
89 action='store_const', const=True)
Patrick Williams7a09b672017-03-27 15:39:12 -050090get_esel.set_defaults(func=do_get_esel)
Patrick Williams9b05ea32017-03-27 15:22:31 -050091
92args = parser.parse_args()
93
94if 'func' in args:
95 args.func(args)
96else:
97 parser.print_help()