-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsvc_perf_discovery_sender.py
114 lines (94 loc) · 3.64 KB
/
svc_perf_discovery_sender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python
# -*- coding: utf-8 -*- # coding: utf-8
#
# IBM Storwize V7000 autodiscovery script for Zabbix
#
# 2013 Matvey Marinin
#
# Sends volume/mdisk/pool LLD JSON data to LLD trapper items "svc.discovery.<volume-mdisk|volume|mdisk|pool>"
# Use with "_Special_Storwize_Perf" Zabbix template
#
# See also http://www.zabbix.com/documentation/2.0/manual/discovery/low_level_discovery
#
# Usage:
# svc_perf_discovery_sender.py [--debug] --clusters <svc1>[,<svc2>...] --user <username> --password <pwd>
#
# --debug = Enable debug output
# --clusters = Comma-separated Storwize node list
# --user = Storwize V7000 user account with Administrator role (it seems that Monitor role is not enough)
# --password = User password
#
import pywbem
import getopt, sys
from zbxsend import Metric, send_to_zabbix
import logging
def usage():
print >> sys.stderr, "Usage: svc_perf_discovery_sender.py [--debug] --clusters <svc1>[,<svc2>...] --user <username> --password <pwd>"
DISCOVERY_TYPES = ['volume-mdisk','volume','mdisk','pool']
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "-h", ["help", "clusters=", "user=", "password=", "debug"])
except getopt.GetoptError, err:
print >> sys.stderr, str(err)
usage()
sys.exit(2)
debug = False
clusters = []
user = None
password = None
for o, a in opts:
if o == "--clusters" and not a.startswith('--'):
clusters.extend( a.split(','))
elif o == "--user" and not a.startswith('--'):
user = a
elif o == "--password" and not a.startswith('--'):
password = a
elif o == "--debug":
debug = True
elif o in ("-h", "--help"):
usage()
sys.exit()
if not clusters:
print >> sys.stderr, '--clusters option must be set'
usage()
sys.exit(2)
if not user or not password:
print >> sys.stderr, '--user and --password options must be set'
usage()
sys.exit(2)
def debug_print(message):
if debug:
print message
for cluster in clusters:
debug_print('Connecting to: %s' % cluster)
conn = pywbem.WBEMConnection('https://'+cluster, (user, password), 'root/ibm')
conn.debug = True
for discovery in DISCOVERY_TYPES:
output = []
if discovery == 'volume-mdisk' or discovery == 'volume':
for vol in conn.ExecQuery('WQL', 'select DeviceID, ElementName from IBMTSSVC_StorageVolume'):
output.append( '{"{#TYPE}":"%s", "{#NAME}":"%s", "{#ID}":"%s"}' % ('volume', vol.properties['ElementName'].value, vol.properties['DeviceID'].value) )
if discovery == 'volume-mdisk' or discovery == 'mdisk':
for mdisk in conn.ExecQuery('WQL', 'select DeviceID, ElementName from IBMTSSVC_BackendVolume'):
output.append( '{"{#TYPE}":"%s", "{#NAME}":"%s", "{#ID}":"%s"}' % ('mdisk', mdisk.properties['ElementName'].value, mdisk.properties['DeviceID'].value) )
if discovery == 'pool':
for pool in conn.ExecQuery('WQL', 'select PoolID, ElementName from IBMTSSVC_ConcreteStoragePool'):
output.append( '{"{#TYPE}":"%s","{#NAME}":"%s","{#ID}":"%s"}' % ('pool', pool.properties['ElementName'].value, pool.properties['PoolID'].value) )
json = []
json.append('{"data":[')
for i, v in enumerate( output ):
if i < len(output)-1:
json.append(v+',')
else:
json.append(v)
json.append(']}')
json_string = ''.join(json)
debug_print(json_string)
trapper_key = 'svc.discovery.%s' % discovery
debug_print('Sending to host=%s, key=%s' % (cluster, trapper_key))
#send json to LLD trapper item with zbxsend module
if debug:
logging.basicConfig(level=logging.INFO)
else:
logging.basicConfig(level=logging.WARNING)
send_to_zabbix([Metric(cluster, trapper_key, json_string)], 'localhost', 10051)
debug_print('')