blob: 95785a85eff7c59fa207a910ad69148177321e4b [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
6class BMC:
7 def __init__(self, server):
8 self.url = "https://{0}/".format(server)
9 self.session = requests.Session()
10 self.login()
11
12 def login(self):
13 r = self.session.post(self.url + 'login',
14 json={ 'data': [ 'root', '0penBmc']},
15 verify=False)
16 j = r.json()
17 if j['status'] != 'ok':
18 raise Exception("Failed to login: \n" + r.text)
19
Patrick Williamsec472d82017-03-27 15:15:43 -050020 def list_events(self):
21 r = self.session.get(self.url + 'xyz/openbmc_project/logging/entry/',
22 verify=False)
23 j = r.json()
24 if j['status'] != 'ok':
25 raise Exception("Failed to query entries: \n" + r.text)
26
27 events = j['data']
28 events.sort(key=lambda x: int(x.split("/")[-1]))
29
30 return events
Patrick Williamsb19c34c2017-03-27 14:52:28 -050031
Patrick Williams5e98b3a2017-03-27 15:28:35 -050032 def get_event(self, event):
33 r = self.session.get(self.url + event, verify=False)
34
35 j = r.json()
36 if j['status'] != 'ok':
37 raise Exception("Failed to get event " + event + ": \n" + r.text)
38
39 return j['data']
40
Patrick Williamsb19c34c2017-03-27 14:52:28 -050041
Patrick Williams9b05ea32017-03-27 15:22:31 -050042def do_list_events(args):
43 s = BMC(server=args.server)
44 for e in s.list_events():
45 print(e)
46
Patrick Williams5e98b3a2017-03-27 15:28:35 -050047
48def do_view_event(args):
49 s = BMC(server=args.server)
50 print(s.get_event(args.event))
51
52
Patrick Williams9b05ea32017-03-27 15:22:31 -050053parser = argparse.ArgumentParser()
54parser.add_argument('--server', help='hostname or IP of BMC', type=str,
55 required=True)
56
57subparsers = parser.add_subparsers()
58list_events = subparsers.add_parser('list', help='List all events on BMC')
59list_events.set_defaults(func=do_list_events)
Patrick Williams5e98b3a2017-03-27 15:28:35 -050060view_event = subparsers.add_parser(
61 'view', help='View all data for an individual event')
62view_event.add_argument('event', help='The event to view')
63view_event.set_defaults(func=do_view_event)
Patrick Williams9b05ea32017-03-27 15:22:31 -050064
65args = parser.parse_args()
66
67if 'func' in args:
68 args.func(args)
69else:
70 parser.print_help()