diff --git a/IRST_mon.py b/IRST_mon.py index 2803302..3142f16 100755 --- a/IRST_mon.py +++ b/IRST_mon.py @@ -22,7 +22,7 @@ def exec(exe): return ret -def discovery(txt): +def discovery(txt, tosend): if not txt: print(command) print('ERROR') @@ -32,6 +32,7 @@ def discovery(txt): data = {'data': []} controller = False device = 0 + controller_index = 0 for line in txt.split("\n"): if '--CONTROLLER INFORMATION--' in line: controller = True @@ -45,14 +46,14 @@ def discovery(txt): elif '--END DEVICE INFORMATION--' in line: device += 1 else: - if controller and 'Name:' in line: - data['data'].append({'#CONTROLLER': "controller-1"}) - if array and not volume and 'Name' in line: - data['data'].append({'#ARRAY': 'ARRAY-' + str(array - 1)}) - if volume and 'Name' in line: - data['data'].append({'#VOLUME': ('volume-' + str(array - 1) + '.' + str(volume - 1))}) - if device and 'ID:' in line: - data['data'].append({'#DISK': 'disk-' + str(device - 1)}) + if controller and 'Name:' in line and tosend == 'controller': + data['data'].append({"{#CONTROLLER}": "controller-{}".format(controller_index)}) + if array and not volume and 'Name' in line and tosend == 'array': + data['data'].append({'{#ARRAY}': 'ARRAY-' + str(array - 1)}) + if volume and 'Name' in line and tosend == 'volume': + data['data'].append({'{#VOLUME}': ('volume-' + str(array - 1) + '.' + str(volume - 1))}) + if device and 'ID:' in line and tosend == 'device': + data['data'].append({'{#DISK}': 'disk-' + str(device - 1)}) device += 1 return data @@ -84,7 +85,6 @@ def sender(txt): arraysec = False volsec = True elif '--END DEVICE INFORMATION--' in line: - device += 1 devicesec = True arraysec = False volsec = False @@ -136,6 +136,7 @@ def sender(txt): ) if devicesec: if 'ID:' in line: + device += 1 packet.append(ZabbixMetric(hostname, 'id[{}]'.format('disk-' + str(device - 1)), line.split(":")[1].strip())) @@ -174,9 +175,20 @@ def args(): print('too many args') return False elif len(sys.argv) == 1: - return 'discovery' - elif len(sys.argv) == 2 and sys.argv[1] == 'send': - return 'sender' + print('Too few args') + elif len(sys.argv) == 2: + if sys.argv[1] == 'send': + return 'sender' + elif sys.argv[1] == 'volume': + return 'volume' + elif sys.argv[1] == 'controller': + return 'controller' + elif sys.argv[1] == 'array': + return 'array' + elif sys.argv[1] == 'device': + return 'device' + else: + print('wrong args') else: print('wrong args') return False @@ -185,8 +197,8 @@ def args(): def main(): if not args(): exit(0) - elif args() == "discovery": - print(json.dumps(discovery(exec(command)), indent=4, sort_keys=False)) + elif args() != "sender": + print(json.dumps(discovery(exec(command),args()), indent=4, sort_keys=False)) else: sender(exec(command))