From 46d0a8d22276efdd16a02df0371e4cb75e9c5380 Mon Sep 17 00:00:00 2001 From: Tinashe Date: Fri, 20 Jan 2023 10:09:52 -0500 Subject: [PATCH 1/2] nodeeventlog: return last n entries --- confluent_client/bin/nodeeventlog | 33 +++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index d3fa3ad1..16a45893 100755 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -41,7 +41,11 @@ argparser = optparse.OptionParser( argparser.add_option('-m', '--maxnodes', type='int', help='Specify a maximum number of ' 'nodes to clear if clearing log, ' - 'prompting if over the threshold') + 'prompting if over the threshold') +argparser.add_option('-l', '--lines', type='int', + help='return the last entries ' + 'for each node in the eventlog. ' + ) (options, args) = argparser.parse_args() try: noderange = args[0] @@ -95,6 +99,14 @@ if deletemode: session.stop_if_noderange_over(noderange, options.maxnodes) else: func = session.read + +event_dict = {} +nodes = [] +for res in session.read('/noderange/{0}/nodes/'.format(args[0])): + node = res.get('item', {}).get('href', '/').replace('/', '') + nodes.append(node) + event_dict[node] = [] + for rsp in func('/noderange/{0}/events/hardware/log'.format(noderange)): if 'error' in rsp: sys.stderr.write(rsp['error'] + '\n') @@ -107,6 +119,19 @@ for rsp in func('/noderange/{0}/events/hardware/log'.format(noderange)): sys.stderr.write('{0}: {1}\n'.format(node, thisdata['error'])) exitcode |= 1 if 'events' in thisdata: - evtdata = thisdata['events'] - for evt in evtdata: - print('{0}: {1}'.format(node, format_event(evt))) + evtdata = thisdata['events'] + if options.lines: + event_dict[node].append(evtdata) + else: + for evt in evtdata: + print('{0}: {1}'.format(node, format_event(evt))) + +if options.lines: + for node in nodes: + evtdata_list = event_dict[node] + if len(evtdata_list) != 0: + evtdata = evtdata_list[-1] + if len(evtdata) > options.lines: + evtdata = evtdata[-abs(options.lines):] + for evt in evtdata: + print('{0}: {1}'.format(node, format_event(evt))) \ No newline at end of file From c3d0d255d351f95c8bebd75470454c5158842e11 Mon Sep 17 00:00:00 2001 From: Tinashe Date: Fri, 20 Jan 2023 12:13:15 -0500 Subject: [PATCH 2/2] nodeeventlog: -l return last n lines for each node --- confluent_client/bin/nodeeventlog | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/confluent_client/bin/nodeeventlog b/confluent_client/bin/nodeeventlog index 16a45893..afe2a2fe 100755 --- a/confluent_client/bin/nodeeventlog +++ b/confluent_client/bin/nodeeventlog @@ -121,7 +121,7 @@ for rsp in func('/noderange/{0}/events/hardware/log'.format(noderange)): if 'events' in thisdata: evtdata = thisdata['events'] if options.lines: - event_dict[node].append(evtdata) + event_dict[node].extend(evtdata) else: for evt in evtdata: print('{0}: {1}'.format(node, format_event(evt))) @@ -130,8 +130,8 @@ if options.lines: for node in nodes: evtdata_list = event_dict[node] if len(evtdata_list) != 0: - evtdata = evtdata_list[-1] - if len(evtdata) > options.lines: - evtdata = evtdata[-abs(options.lines):] - for evt in evtdata: - print('{0}: {1}'.format(node, format_event(evt))) \ No newline at end of file + if len(evtdata_list) > options.lines: + evtdata_list = evtdata_list[-abs(options.lines):] + for evt in evtdata_list: + print('{0}: {1}'.format(node, format_event(evt))) + \ No newline at end of file