Browse Source

Запилил навроде

master
Mikhail Grebenkin 7 years ago
parent
commit
c92254998e
3 changed files with 287 additions and 0 deletions
  1. +6
    -0
      .idea/vcs.xml
  2. +177
    -0
      IRST_mon.py
  3. +104
    -0
      irst.txt

+ 6
- 0
.idea/vcs.xml View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 177
- 0
IRST_mon.py View File

@ -0,0 +1,177 @@
#! /usr/bin/python3
# coding=utf-8
import subprocess
import json
import sys
from pyzabbix import ZabbixMetric, ZabbixSender
command = 'cat irst.txt'
hostname = 'testhost'
server = '192.168.1.56'
def exec(exe):
result = subprocess.Popen(exe, stdout=subprocess.PIPE, shell=True)
return result.communicate()[0].decode('utf-8')
def discovery(txt):
array = 0
volume = 0
data = {'data': []}
controller = False
device = 0
for line in txt.split("\n"):
if '--CONTROLLER INFORMATION--' in line:
controller = True
if controller and 'Dynamic Storage Accelerator:' in line:
controller = False
elif '--ARRAY INFORMATION--' in line:
array += 1
volume = 0
elif '--VOLUME INFORMATION--' in line:
volume += 1
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)})
device += 1
return data
def sender(txt):
array = 0
arraysec = False
volume = 0
volsec = False
packet = []
controller = False
device = 0
devicesec = False
for line in txt.split("\n"):
if '--CONTROLLER INFORMATION--' in line:
controller = True
if controller and 'Dynamic Storage Accelerator:' in line:
controller = False
elif '--ARRAY INFORMATION--' in line:
array += 1
volume = 0
arraysec = True
volsec = False
elif '--VOLUME INFORMATION--' in line:
volume += 1
arraysec = False
volsec = True
elif '--END DEVICE INFORMATION--' in line:
device += 1
devicesec = True
arraysec = False
volsec = False
else:
if controller:
if 'Name:' in line:
packet.append(ZabbixMetric(hostname, 'name[controller-1]', line.split(":")[1].strip()))
elif 'Type:' in line:
packet.append(ZabbixMetric(hostname, 'type[controller-1]', line.split(":")[1].strip()))
if arraysec:
if 'Name:' in line:
packet.append(ZabbixMetric(hostname, 'name[{}]'.format('ARRAY-' + str(array - 1)),
line.split(":")[1].strip()))
elif 'Size:' in line:
packet.append(ZabbixMetric(hostname, 'size[{}]'.format('ARRAY-' + str(array - 1)),
line.split(":")[1].strip().split()[0]))
elif 'Free:' in line:
packet.append(ZabbixMetric(hostname, 'free[{}]'.format('ARRAY-' + str(array - 1)),
line.split(":")[1].strip().split()[0]))
elif 'Num Disks:' in line:
packet.append(ZabbixMetric(hostname, 'numdisks[{}]'.format('ARRAY-' + str(array - 1)),
line.split(":")[1].strip()))
elif 'Num Vols:' in line:
packet.append(ZabbixMetric(hostname, 'numvols[{}]'.format('ARRAY-' + str(array - 1)),
line.split(":")[1].strip()))
if volsec:
if 'Name:' in line:
packet.append(ZabbixMetric(hostname,
'name[{}]'.format('volume-' + str(array - 1) + '.' + str(volume - 1)),
line.split(":")[1].strip()))
elif 'Raid Level:' in line:
packet.append(ZabbixMetric(hostname,
'raidlvl[{}]'.format('volume-' + str(array - 1) + '.' + str(volume - 1)),
line.split(":")[1].strip()
)
)
elif 'Size:' in line and not "StripeSize" in line:
packet.append(ZabbixMetric(hostname,
'size[{}]'.format('volume-' + str(array - 1) + '.' + str(volume - 1)),
line.split(":")[1].strip().split()[0]
)
)
elif 'State:' in line:
packet.append(ZabbixMetric(hostname,
'state[{}]'.format('volume-' + str(array - 1) + '.' + str(volume - 1)),
line.split(":")[1].strip()
)
)
if devicesec:
if 'ID:' in line:
packet.append(ZabbixMetric(hostname,
'id[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip()))
elif 'Disk Type:' in line:
packet.append(ZabbixMetric(hostname,
'disktype[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip()))
elif 'State:' in line:
packet.append(ZabbixMetric(hostname,
'state[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip()))
elif 'Size:' in line:
packet.append(ZabbixMetric(hostname,
'size[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip().split()[0]))
elif 'Serial Number:' in line:
packet.append(ZabbixMetric(hostname,
'serial[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip()))
elif 'Model:' in line:
packet.append(ZabbixMetric(hostname,
'model[{}]'.format('disk-' + str(device - 1)),
line.split(":")[1].strip()))
for val in packet:
print(val)
zbx = ZabbixSender(server)
zbx.send(packet)
def args():
if len(sys.argv) > 2:
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'
else:
print('wrong args')
return False
def main():
if not args():
exit(0)
elif args() == "discovery":
print(json.dumps(discovery(exec(command)), indent=4, sort_keys=False))
else:
sender(exec(command))
if __name__ == '__main__':
main()

+ 104
- 0
irst.txt View File

@ -0,0 +1,104 @@
--CONTROLLER INFORMATION--
Name: Intel(R) Desktop/Workstation/Server Express Chipset SATA RAID Controller
Type: AHCI
Supported RAID: 0,1,5,10
Max Disks/Array: 6
HW Information:
Vendor ID: 0x8086
Device ID: 0x2822
HW Revision: 0
Dynamic Storage Accelerator: Disabled
--ARRAY INFORMATION--
Name: SATA_Array_0000
Size: 466 GB
Free: 0 GB
Num Disks: 2
Num Vols: 1
Write Cache: On
--VOLUME INFORMATION--
Name: System
Raid Level: 1
Size: 233 GB
StripeSize: 64 KB
Num Disks: 2
State: Normal
System: True
Initialized: True
Cache Policy: Off
--ARRAY INFORMATION--
Name: SATA_Array_0001
Size: 954 GB
Free: 0 GB
Num Disks: 2
Num Vols: 1
Write Cache: On
--VOLUME INFORMATION--
Name: Data
Raid Level: 1
Size: 477 GB
StripeSize: 64 KB
Num Disks: 2
State: Normal
System: False
Initialized: True
Cache Policy: Off
--END DEVICE INFORMATION--
ID: 0-0-0-0
Type: Disk
Disk Type: SATA SSD
State: Normal
Size: 233 GB
Free Size: 0 GB
System Disk: False
Usage: Array member
Serial Number: S2R4NX0JC08736Y
Model: Samsung SSD 850 EVO 250GB
ID: 0-0-1-0
Type: Disk
Disk Type: Unknown disk type SSD
State: Normal
Size: 0 GB
Free Size: 0 GB
System Disk: False
Usage: Array member
Serial Number: S2R4NX0JC08724K
Model:
ID: 0-0-2-0
Type: Disk
Disk Type: Unknown disk type SSD
State: Normal
Size: 0 GB
Free Size: 0 GB
System Disk: False
Usage: Array member
Serial Number: S39FNX0JA04860V
Model:
ID: 0-0-3-0
Type: Disk
Disk Type: Unknown disk type SSD
State: Normal
Size: 0 GB
Free Size: 0 GB
System Disk: False
Usage: Array member
Serial Number: S39FNX0JB12076E
Model:
0

Loading…
Cancel
Save

Powered by TurnKey Linux.