blob: 88c470d0c334a44da9bbdd4f85d27791a0835b6c [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
53
Patrick Williams9b05ea32017-03-27 15:22:31 -050054parser = argparse.ArgumentParser()
55parser.add_argument('--server', help='hostname or IP of BMC', type=str,
56 required=True)
57
58subparsers = parser.add_subparsers()
59list_events = subparsers.add_parser('list', help='List all events on BMC')
60list_events.set_defaults(func=do_list_events)
Patrick Williams5e98b3a2017-03-27 15:28:35 -050061view_event = subparsers.add_parser(
62 'view', help='View all data for an individual event')
63view_event.add_argument('event', help='The event to view')
64view_event.set_defaults(func=do_view_event)
Patrick Williams9b05ea32017-03-27 15:22:31 -050065
66args = parser.parse_args()
67
68if 'func' in args:
69 args.func(args)
70else:
71 parser.print_help()