From c9a54e2c2dfb44cb4253093c03a76f55407bc80d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=93=D1=80=D0=B5?= =?UTF-8?q?=D0=B1=D0=B5=D0=BD=D0=BA=D0=B8=D0=BD=5F1?= Date: Fri, 27 Apr 2018 15:15:25 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BE=D0=B1=D0=BD=D0=B0=D1=80=D1=83=D0=B6=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F,=20=D0=BF=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=B0=D1=80=D0=B3=D1=83=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D1=8B.=20=D0=9A=D0=BE=D0=BD=D1=84=D0=B8=D0=B3=D1=83=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D1=82=D1=8C=20=D0=BD=D0=B5=20=D0=B1?= =?UTF-8?q?=D1=83=D0=B4=D1=83,=20=D0=BD=D0=B0=D1=85=D0=B5=D1=80.=20=D0=9E?= =?UTF-8?q?=D1=82=D0=BB=D0=B0=D0=B2=D0=B8=D0=BB=20=D0=B2=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=81=D0=B5=20=D0=BD=D0=B5=D0=BF=D1=80=D0=B8?= =?UTF-8?q?=D1=8F=D1=82=D0=BD=D1=8B=D0=B5=20=D0=B1=D0=B0=D0=B3=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- IRST_mon.py | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) 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))