blob: 2278458416d96d0b6154e2ec8b9d379da03ee86e [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
32
Patrick Williams9b05ea32017-03-27 15:22:31 -050033def do_list_events(args):
34 s = BMC(server=args.server)
35 for e in s.list_events():
36 print(e)
37
38parser = argparse.ArgumentParser()
39parser.add_argument('--server', help='hostname or IP of BMC', type=str,
40 required=True)
41
42subparsers = parser.add_subparsers()
43list_events = subparsers.add_parser('list', help='List all events on BMC')
44list_events.set_defaults(func=do_list_events)
45
46args = parser.parse_args()
47
48if 'func' in args:
49 args.func(args)
50else:
51 parser.print_help()