blob: d9f4fc0b2ddfd601d8c2945293ec4c5f08f5f1e3 [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
Andrew Geissler39541fd2017-08-19 08:31:07 -05006import urllib3
7urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8
Patrick Williams533c13a2017-03-27 15:28:51 -05009
Patrick Williamsb19c34c2017-03-27 14:52:28 -050010class BMC:
11 def __init__(self, server):
12 self.url = "https://{0}/".format(server)
13 self.session = requests.Session()
14 self.login()
15
16 def login(self):
17 r = self.session.post(self.url + 'login',
Patrick Williams533c13a2017-03-27 15:28:51 -050018 json={'data': ['root', '0penBmc']},
Patrick Williamsb19c34c2017-03-27 14:52:28 -050019 verify=False)
20 j = r.json()
21 if j['status'] != 'ok':
22 raise Exception("Failed to login: \n" + r.text)
23
Patrick Williamsec472d82017-03-27 15:15:43 -050024 def list_events(self):
25 r = self.session.get(self.url + 'xyz/openbmc_project/logging/entry/',
26 verify=False)
27 j = r.json()
28 if j['status'] != 'ok':
29 raise Exception("Failed to query entries: \n" + r.text)
30
31 events = j['data']
32 events.sort(key=lambda x: int(x.split("/")[-1]))
33
34 return events
Patrick Williamsb19c34c2017-03-27 14:52:28 -050035
Patrick Williams5e98b3a2017-03-27 15:28:35 -050036 def get_event(self, event):
37 r = self.session.get(self.url + event, verify=False)
38
39 j = r.json()
40 if j['status'] != 'ok':
41 raise Exception("Failed to get event " + event + ": \n" + r.text)
42
43 return j['data']
44
Patrick Williamsb19c34c2017-03-27 14:52:28 -050045
Patrick Williams9b05ea32017-03-27 15:22:31 -050046def do_list_events(args):
47 s = BMC(server=args.server)
48 for e in s.list_events():
49 print(e)
50
Patrick Williams5e98b3a2017-03-27 15:28:35 -050051
52def do_view_event(args):
53 s = BMC(server=args.server)
54 print(s.get_event(args.event))
55
Patrick Williams4296f4b2017-03-27 16:26:41 -050056
Patrick Williams7a09b672017-03-27 15:39:12 -050057def do_get_esel(args):
58 s = BMC(server=args.server)
59 e = s.get_event(args.event)
60 if e['Message'] != 'org.open_power.Error.Host.Event' and\
61 e['Message'] != 'org.open_power.Error.Host.Event.Event':
62 raise Exception("Event is not from Host: " + e['Message'])
63 for d in e['AdditionalData']:
Patrick Williams842308b2017-03-27 15:49:38 -050064 data = d.split("=")
65 tag = data.pop(0)
Patrick Williams7a09b672017-03-27 15:39:12 -050066 if tag != 'ESEL':
67 continue
68 data = "=".join(data)
Patrick Williams6f5c3ea2017-03-27 16:23:52 -050069 if args.binary:
70 data = data.split(" ")
71 if '' == data[-1]:
72 data.pop()
73 data = "".join(map(lambda x: chr(int(x, 16)), data))
Patrick Williams7a09b672017-03-27 15:39:12 -050074 print(data)
75
Patrick Williams5e98b3a2017-03-27 15:28:35 -050076
Patrick Williams9b05ea32017-03-27 15:22:31 -050077parser = argparse.ArgumentParser()
78parser.add_argument('--server', help='hostname or IP of BMC', type=str,
79 required=True)
80
81subparsers = parser.add_subparsers()
82list_events = subparsers.add_parser('list', help='List all events on BMC')
83list_events.set_defaults(func=do_list_events)
Patrick Williams5e98b3a2017-03-27 15:28:35 -050084view_event = subparsers.add_parser(
85 'view', help='View all data for an individual event')
86view_event.add_argument('event', help='The event to view')
87view_event.set_defaults(func=do_view_event)
Patrick Williams7a09b672017-03-27 15:39:12 -050088get_esel = subparsers.add_parser(
89 'get-esel', help='Extract OpenPOWER eSEL data for an individual event')
90get_esel.add_argument('event', help='The event to get eSEL from')
Patrick Williams6f5c3ea2017-03-27 16:23:52 -050091get_esel.add_argument('--binary', help='Print event in raw binary',
92 action='store_const', const=True)
Patrick Williams7a09b672017-03-27 15:39:12 -050093get_esel.set_defaults(func=do_get_esel)
Patrick Williams9b05ea32017-03-27 15:22:31 -050094
95args = parser.parse_args()
96
97if 'func' in args:
98 args.func(args)
99else:
100 parser.print_help()