Patrick Williams | b19c34c | 2017-03-27 14:52:28 -0500 | [diff] [blame] | 1 | #!/bin/env python |
| 2 | |
Patrick Williams | 9b05ea3 | 2017-03-27 15:22:31 -0500 | [diff] [blame^] | 3 | import argparse |
Patrick Williams | b19c34c | 2017-03-27 14:52:28 -0500 | [diff] [blame] | 4 | import requests |
| 5 | |
| 6 | class 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 Williams | ec472d8 | 2017-03-27 15:15:43 -0500 | [diff] [blame] | 20 | 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 Williams | b19c34c | 2017-03-27 14:52:28 -0500 | [diff] [blame] | 31 | |
| 32 | |
Patrick Williams | 9b05ea3 | 2017-03-27 15:22:31 -0500 | [diff] [blame^] | 33 | def do_list_events(args): |
| 34 | s = BMC(server=args.server) |
| 35 | for e in s.list_events(): |
| 36 | print(e) |
| 37 | |
| 38 | parser = argparse.ArgumentParser() |
| 39 | parser.add_argument('--server', help='hostname or IP of BMC', type=str, |
| 40 | required=True) |
| 41 | |
| 42 | subparsers = parser.add_subparsers() |
| 43 | list_events = subparsers.add_parser('list', help='List all events on BMC') |
| 44 | list_events.set_defaults(func=do_list_events) |
| 45 | |
| 46 | args = parser.parse_args() |
| 47 | |
| 48 | if 'func' in args: |
| 49 | args.func(args) |
| 50 | else: |
| 51 | parser.print_help() |