forked from asand3r/zbx-hpmsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzbx-hpmsa.py
973 lines (880 loc) · 49.1 KB
/
zbx-hpmsa.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
#!/usr/bin/env python3
import os
import grp
import json
import urllib3
from hashlib import md5
from socket import gethostbyname
from argparse import ArgumentParser
from xml.etree import ElementTree as eTree
from datetime import datetime, timedelta
import sqlite3
import requests
def install_script(tmp_dir, group):
"""
Function creates temp dir, init cache db and assign needed right.
:param tmp_dir: Path to temporary directory
:type: str
:param group: Group name to set chown root:group to tmp dir and cache db file
:type: str
:return: None
:rtype: None
"""
# Create config directory and assign rights
try:
if not os.path.exists(tmp_dir):
# Create directory
os.mkdir(tmp_dir)
os.chmod(tmp_dir, 0o775)
except PermissionError:
raise SystemExit('PERMISSION ERROR: You have no permissions to create "{}" directory.'.format(tmp_dir))
# Init cache db
if not os.path.exists(CACHE_DB):
sql_cmd('CREATE TABLE IF NOT EXISTS skey_cache ('
'dns_name TEXT NOT NULL, '
'ip TEXT NOT NULL, '
'proto TEXT NOT NULL, '
'expired TEXT NOT NULL, '
'skey TEXT NOT NULL DEFAULT 0, '
'PRIMARY KEY (dns_name, ip, proto))'
)
os.chmod(CACHE_DB, 0o664)
# Set owner to tmp dir
try:
os.chown(tmp_dir, 0, grp.getgrnam(group).gr_gid)
os.chown(CACHE_DB, 0, grp.getgrnam(group).gr_gid)
except KeyError:
print('WARNING: Cannot find group "{}" to set access rights. Using "root" group.'.format(group))
os.chown(tmp_dir, 0, 0)
os.chown(CACHE_DB, 0, grp.getgrnam(group).gr_gid)
def make_cred_hash(cred, isfile=False):
"""
Return md5 hash of login string.
:param cred: Login string in 'user_password' format or path to the file with credentials.
:type cred: str
:param isfile: Is the 'cred' is path to file.
:type isfile: bool
:return: md5 hash.
:rtype: str
"""
if isfile:
try:
with open(cred, 'r') as login_file:
login_data = login_file.readline().replace('\n', '').strip()
if login_data.find('_') != -1:
hashed = md5(login_data.encode()).hexdigest()
else:
hashed = login_data
except FileNotFoundError:
raise SystemExit("ERROR: File with login data doesn't exists: {}".format(cred))
else:
hashed = md5(cred.encode()).hexdigest()
return hashed
def sql_cmd(query, fetch_all=False):
"""
Check and execute SQL query.
:param query: SQL query to execute.
:type query: str
:param fetch_all: Set it True to execute fetchall().
:type fetch_all: bool
:return: Tuple with SQL query result.
:rtype: tuple
"""
try:
conn = sqlite3.connect(CACHE_DB)
cursor = conn.cursor()
try:
if not fetch_all:
data = cursor.execute(query).fetchone()
else:
data = cursor.execute(query).fetchall()
except sqlite3.OperationalError as e:
if str(e).startswith('no such table'):
raise SystemExit("Cache is empty")
else:
raise SystemExit('ERROR: {}. Query: {}'.format(e, query))
conn.commit()
conn.close()
return data
except sqlite3.OperationalError as e:
print("ERROR: {}".format(e))
def display_cache():
"""
Diplay cache data and exit.
:return: None
:rtype: None
"""
print("{:^30} {:^15} {:^7} {:^19} {:^32}".format('hostname', 'ip', 'proto', 'expired', 'sessionkey'))
print("{:-^30} {:-^15} {:-^7} {:-^19} {:-^32}".format('-', '-', '-', '-', '-'))
for cache in sql_cmd('SELECT * FROM skey_cache', fetch_all=True):
name, ip, proto, expired, sessionkey = cache
print("{:30} {:15} {:^7} {:19} {:32}".format(
name, ip, proto, datetime.fromtimestamp(float(expired)).strftime("%H:%M:%S %d.%m.%Y"), sessionkey))
def get_skey(msa, hashed_login, use_cache=True):
"""
Get session key from HP MSA API and and print it.
:param msa: MSA IP address and DNS name.
:type msa: tuple
:param hashed_login: Hashed with md5 login data.
:type hashed_login: str
:param use_cache: The function will try to save session key to disk.
:type use_cache: bool
:return: Session key or error code.
:rtype: str
"""
# Trying to use cached session key
if use_cache:
cur_timestamp = datetime.timestamp(datetime.utcnow())
if not USE_SSL: # http
cache_data = sql_cmd('SELECT expired,skey FROM skey_cache WHERE ip="{}" AND proto="http"'.format(msa[0]))
else: # https
cache_data = sql_cmd('SELECT expired,skey '
'FROM skey_cache '
'WHERE dns_name="{}" AND IP ="{}" AND proto="https"'.format(msa[1], msa[0])
)
if cache_data is not None:
cache_expired, cached_skey = cache_data
if cur_timestamp < float(cache_expired):
return cached_skey
else:
return get_skey(msa, hashed_login, use_cache=False)
else:
return get_skey(msa, hashed_login, use_cache=False)
else:
# Forming URL and trying to make GET query
msa_conn = msa[1] if VERIFY_SSL else msa[0]
url = '{}/api/login/{}'.format(msa_conn, hashed_login)
ret_code, sessionkey, xml = query_xmlapi(url=url, sessionkey=None)
# 1 - success, write sessionkey to DB and return it
if ret_code == '1':
expired = datetime.timestamp(datetime.utcnow() + timedelta(minutes=30))
if not USE_SSL:
cache_data = sql_cmd('SELECT ip FROM skey_cache WHERE ip = "{}" AND proto="http"'.format(msa[0]))
if cache_data is None:
sql_cmd('INSERT INTO skey_cache VALUES ('
'"{dns}", "{ip}", "http", "{time}", "{skey}")'.format(dns=msa[1], ip=msa[0],
time=expired, skey=sessionkey)
)
else:
sql_cmd('UPDATE skey_cache SET skey="{skey}", expired="{expired}" '
'WHERE ip="{ip}" AND proto="http"'.format(skey=sessionkey, expired=expired, ip=msa[0])
)
else:
cache_data = sql_cmd('SELECT dns_name, ip FROM skey_cache '
'WHERE dns_name="{}" AND ip="{}" AND proto="https"'.format(msa[1], msa[0]))
if cache_data is None:
sql_cmd('INSERT INTO skey_cache VALUES ('
'"{name}", "{ip}", "https", "{expired}", "{skey}")'.format(name=msa[1], ip=msa[0],
expired=expired,
skey=sessionkey
)
)
else:
sql_cmd('UPDATE skey_cache SET skey = "{skey}", expired = "{expired}" '
'WHERE dns_name="{name}" AND ip="{ip}" AND proto="https"'.format(skey=sessionkey,
expired=expired,
name=msa[1],
ip=msa[0]
)
)
return sessionkey
# 2 - Authentication Unsuccessful, return "2"
elif ret_code == '2':
return ret_code
def query_xmlapi(url, sessionkey):
"""
Making HTTP(s) request to HP MSA XML API.
:param url: URL to make GET request.
:type url: str
:param sessionkey: Session key to authorize.
:type sessionkey: Union[str, None]
:return: Tuple with return code, return description and etree object <xml.etree.ElementTree.Element>.
:rtype: tuple
"""
# Set file where we can find root CA
ca_file = '/etc/pki/tls/certs/ca-bundle.crt'
# Makes GET request to URL
try:
# Connection timeout in seconds (connection, read).
timeout = (1, 3)
full_url = 'https://' + url if USE_SSL else 'http://' + url
headers = {'sessionKey': sessionkey} if API_VERSION == 2 else {
'Cookie': "wbiusername={}; wbisessionkey={}".format(MSA_USERNAME, sessionkey)}
if USE_SSL:
if VERIFY_SSL:
response = requests.get(full_url, headers=headers, verify=ca_file, timeout=timeout)
else:
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
response = requests.get(full_url, headers=headers, verify=False, timeout=timeout)
else:
response = requests.get(full_url, headers=headers, timeout=timeout)
except requests.exceptions.SSLError:
raise SystemExit('ERROR: Cannot verify storage SSL Certificate.')
except requests.exceptions.ConnectTimeout:
raise SystemExit('ERROR: Timeout occurred!')
except requests.exceptions.ConnectionError as e:
raise SystemExit("ERROR: Cannot connect to storage {}.".format(e))
# Reading data from server XML response
try:
if SAVE_XML is not None and 'login' not in url:
try:
with open(SAVE_XML, 'w') as xml_file:
xml_file.write(response.text)
except PermissionError:
raise SystemExit('ERROR: Cannot save XML file to "{}"'.format(args.savexml))
response_xml = eTree.fromstring(response.content)
return_code = response_xml.find("./OBJECT[@name='status']/PROPERTY[@name='return-code']").text
return_response = response_xml.find("./OBJECT[@name='status']/PROPERTY[@name='response']").text
return return_code, return_response, response_xml
except (ValueError, AttributeError) as e:
raise SystemExit("ERROR: Cannot parse XML. {}".format(e))
def get_health(msa, component, item, sessionkey):
"""
Get health status of single MSA part.
:param msa: MSA DNS name and IP address.
:type msa: tuple
:param sessionkey: Session key.
:type sessionkey: str
:param component: Storage component name.
:type component: str
:param item: Component ID.
:type item: str
:return: Health status.
:rtype: str
"""
# Components ID matching dict.
id_md = {
'controllers': 'controller-id', 'enclosures': 'enclosure-id', 'power-supplies': 'durable-id',
'fans': 'durable-id', 'pools': 'name', 'disk-groups': 'name', 'ports': 'port', 'volumes': 'volume-name'
}
# Forming url
msa_conn = msa[1] if VERIFY_SSL else msa[0]
if component in ('vdisks', 'disks'):
url = '{strg}/api/show/{comp}/{item}'.format(strg=msa_conn, comp=component, item=item)
else:
url = '{strg}/api/show/{comp}'.format(strg=msa_conn, comp=component)
# Make a query to API
ret_code, descr, xml = query_xmlapi(url, sessionkey)
if ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(ret_code, descr))
# Return health status (int)
if component in ('vdisks', 'disks'):
health = xml.find("./OBJECT[@name='{}']/PROPERTY[@name='health-numeric']".format(NAMES_MATCH[component])).text
else:
# We'll make dict {ctrl_id: health} because of we cannot call API for exact of some components
health_dict = {}
for OBJ in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
comp_id = OBJ.find("./PROPERTY[@name='{}']".format(id_md[component])).text
health_dict[comp_id] = OBJ.find("./PROPERTY[@name='health-numeric']").text
# If given item presents in our dict - return status
if item in health_dict:
health = health_dict[item]
else:
raise SystemExit("ERROR: No such id: '{}'.".format(item))
return health
def make_lld(msa, component, sessionkey):
"""
Form LLD JSON for Zabbix server.
:param msa: MSA DNS name and IP address.
:type msa: tuple
:param sessionkey: Session key.
:type sessionkey: str
:param component: Name of storage component.
:type component: str
:return: JSON with discovery data.
:rtype: str
"""
# Forming URL
msa_conn = msa[1] if VERIFY_SSL else msa[0]
url = '{strg}/api/show/{comp}'.format(strg=msa_conn, comp=component)
# Making request to API
resp_return_code, resp_description, xml = query_xmlapi(url, sessionkey)
if resp_return_code != '0':
raise SystemExit('ERROR: {rc} : {rd}'.format(rc=resp_return_code, rd=resp_description))
# Eject XML from response
all_components = []
# Vdisks is deprecated in HPE MSA 1040/2040+ so it stay here for compatibilities
if component == 'disks':
for disk in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
disk_id = disk.find("./PROPERTY[@name='location']").text
disk_sn = disk.find("./PROPERTY[@name='serial-number']").text
lld_dict = {
"{#DISK.ID}": "{}".format(disk_id),
"{#DISK.SN}": "{}".format(disk_sn)
}
all_components.append(lld_dict)
elif component == 'vdisks':
for vdisk in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
vdisk_id = vdisk.find("./PROPERTY[@name='name']").text
vdisk_type = vdisk.find("./PROPERTY[@name='storage-type']").text
lld_dict = {
"{#VDISK.ID}": "{}".format(vdisk_id),
"{#VDISK.TYPE}": "{}".format(vdisk_type)
}
all_components.append(lld_dict)
elif component == 'pools':
for pool in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
pool_id = pool.find("./PROPERTY[@name='name']").text
pool_type = pool.find("./PROPERTY[@name='storage-type']").text
lld_dict = {
"{#POOL.ID}": "{}".format(pool_id),
"{#POOL.TYPE}": "{}".format(pool_type)
}
all_components.append(lld_dict)
elif component == 'disk-groups':
for pool in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
dg_id = pool.find("./PROPERTY[@name='name']").text
dg_type = pool.find("./PROPERTY[@name='storage-type']").text
lld_dict = {
"{#DG.ID}": "{}".format(dg_id),
"{#DG.TYPE}": "{}".format(dg_type)
}
all_components.append(lld_dict)
elif component == 'volumes':
for pool in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
volume_id = pool.find("./PROPERTY[@name='volume-name']").text
volume_type = pool.find("./PROPERTY[@name='volume-type']").text
lld_dict = {
"{#VOLUME.ID}": "{}".format(volume_id),
"{#VOLUME.TYPE}": "{}".format(volume_type)
}
all_components.append(lld_dict)
elif component == 'controllers':
for ctrl in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
ctrl_id = ctrl.find("./PROPERTY[@name='controller-id']").text
ctrl_sn = ctrl.find("./PROPERTY[@name='serial-number']").text
ctrl_ip = ctrl.find("./PROPERTY[@name='ip-address']").text
ctrl_wwn = ctrl.find("./PROPERTY[@name='node-wwn']").text
lld_dict = {
"{#CONTROLLER.ID}": "{}".format(ctrl_id),
"{#CONTROLLER.SN}": "{}".format(ctrl_sn),
"{#CONTROLLER.IP}": "{}".format(ctrl_ip),
"{#CONTROLLER.WWN}": "{}".format(ctrl_wwn),
}
all_components.append(lld_dict)
elif component == 'enclosures':
for encl in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
encl_id = encl.find("./PROPERTY[@name='enclosure-id']").text
encl_sn = encl.find("./PROPERTY[@name='midplane-serial-number']").text
lld_dict = {
"{#ENCLOSURE.ID}": "{}".format(encl_id),
"{#ENCLOSURE.SN}": "{}".format(encl_sn)
}
all_components.append(lld_dict)
elif component == 'power-supplies':
for PS in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
ps_id = PS.find("./PROPERTY[@name='durable-id']").text
ps_loc = PS.find("./PROPERTY[@name='location']").text
ps_name = PS.find("./PROPERTY[@name='name']").text
# Exclude voltage regulators from discovery
if ps_name.lower().find('voltage regulator') == -1:
lld_dict = {
"{#POWERSUPPLY.ID}": "{}".format(ps_id),
"{#POWERSUPPLY.LOCATION}": "{}".format(ps_loc)
}
all_components.append(lld_dict)
elif component == 'fans':
for FAN in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
fan_id = FAN.find("./PROPERTY[@name='durable-id']").text
fan_loc = FAN.find("./PROPERTY[@name='location']").text
lld_dict = {
"{#FAN.ID}": "{}".format(fan_id),
"{#FAN.LOCATION}": "{}".format(fan_loc)
}
all_components.append(lld_dict)
elif component == 'ports':
for PORT in xml.findall("./OBJECT[@name='{}']".format(NAMES_MATCH[component])):
port_id = PORT.find("./PROPERTY[@name='port']").text
port_type = PORT.find("./PROPERTY[@name='port-type']").text
port_speed = PORT.find("./PROPERTY[@name='actual-speed']").text
port_sfp = PORT.find("./OBJECT[@name='port-details']/PROPERTY[@name='sfp-present']").text
lld_dict = {
"{#PORT.ID}": "{}".format(port_id),
"{#PORT.TYPE}": "{}".format(port_type),
"{#PORT.SPEED}": "{}".format(port_speed),
"{#PORT.SFP}": "{}".format(port_sfp)
}
all_components.append(lld_dict)
# Dumps JSON and return it
return json.dumps({"data": all_components}, separators=(',', ':'))
def get_full_json(msa, component, sessionkey):
"""
Form text in JSON with storage component data.
:param msa: MSA DNS name and IP address.
:type msa: tuple
:param sessionkey: Session key.
:type sessionkey: str
:param component: Name of storage component.
:type component: str
:return: JSON with all found data.
:rtype: str
"""
# Forming URL
msa_conn = msa[1] if VERIFY_SSL else msa[0]
url = '{strg}/api/show/{comp}'.format(strg=msa_conn, comp=component)
# Making request to API
resp_return_code, resp_description, xml = query_xmlapi(url, sessionkey)
if resp_return_code != '0':
raise SystemExit('ERROR: {rc} : {rd}'.format(rc=resp_return_code, rd=resp_description))
# Processing XML
all_components = {}
if component == 'disks':
for PROP in xml.findall("./OBJECT[@name='drive']"):
# Processing main properties
disk_location = PROP.find("./PROPERTY[@name='location']").text
disk_health = PROP.find("./PROPERTY[@name='health']").text
disk_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
disk_error = PROP.find("./PROPERTY[@name='error']").text
# Get disk statistics
url = '{strg}/api/show/{comp}/{item}'.format(strg=msa_conn, comp='disk-statistics', item=disk_location)
# Making request to API
stats_ret_code, stats_descr, stats_xml = query_xmlapi(url, sessionkey)
if stats_ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(stats_ret_code, stats_descr))
# THINK: I don't know, is it good solution, but it's one more query to XML API
disk_number_of_reads = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-reads']").text
disk_number_of_writes = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-writes']").text
disk_data_read_numeric = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='data-read-numeric']").text
disk_data_written_numeric = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='data-written-numeric']").text
disk_queue_depth = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='queue-depth']").text
disk_smart_count_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='smart-count-1']").text
disk_io_timeout_count_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='io-timeout-count-1']").text
disk_no_response_count_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='no-response-count-1']").text
disk_spinup_retry_count_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='spinup-retry-count-1']").text
disk_number_of_media_errors_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-media-errors-1']").text
disk_number_of_nonmedia_errors_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-nonmedia-errors-1']").text
disk_number_of_block_reassigns_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-block-reassigns-1']").text
disk_number_of_bad_blocks_1 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-bad-blocks-1']").text
disk_smart_count_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='smart-count-2']").text
disk_io_timeout_count_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='io-timeout-count-2']").text
disk_no_response_count_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='no-response-count-2']").text
disk_spinup_retry_count_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='spinup-retry-count-2']").text
disk_number_of_media_errors_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-media-errors-2']").text
disk_number_of_nonmedia_errors_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-nonmedia-errors-2']").text
disk_number_of_block_reassigns_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-block-reassigns-2']").text
disk_number_of_bad_blocks_2 = stats_xml.find("./OBJECT[@name='disk-statistics']/PROPERTY[@name='number-of-bad-blocks-2']").text
disk_full_data = {
"health": disk_health,
"health-num": disk_health_num,
"error": disk_error,
"number-of-reads": disk_number_of_reads,
"number-of-writes": disk_number_of_writes,
"data-read-numeric": disk_data_read_numeric,
"data-written-numeric": disk_data_written_numeric,
"queue-depth": disk_queue_depth,
"smart-count-1": disk_smart_count_1,
"io-timeout-count-1": disk_io_timeout_count_1,
"no-response-count-1": disk_no_response_count_1,
"spinup-retry-count-1": disk_spinup_retry_count_1,
"number-of-media-errors-1": disk_number_of_media_errors_1,
"number-of-nonmedia-errors-1": disk_number_of_nonmedia_errors_1,
"number-of-block-reassigns-1": disk_number_of_block_reassigns_1,
"number-of-bad-blocks-1": disk_number_of_bad_blocks_1,
"smart-count-2": disk_smart_count_2,
"io-timeout-count-2": disk_io_timeout_count_2,
"no-response-count-2": disk_no_response_count_2,
"spinup-retry-count-2": disk_spinup_retry_count_2,
"number-of-media-errors-2": disk_number_of_media_errors_2,
"number-of-nonmedia-errors-2": disk_number_of_nonmedia_errors_2,
"number-of-block-reassigns-2": disk_number_of_block_reassigns_2,
"number-of-bad-blocks-2": disk_number_of_bad_blocks_2,
}
# Processing advanced properties
disk_ext = dict()
disk_ext['temperature'] = PROP.find("./PROPERTY[@name='temperature-numeric']")
disk_ext['power-on-hours'] = PROP.find("./PROPERTY[@name='power-on-hours']")
for prop, value in disk_ext.items():
if value is not None:
disk_full_data[prop] = value.text
all_components[disk_location] = disk_full_data
elif component == 'vdisks':
for PROP in xml.findall("./OBJECT[@name='virtual-disk']"):
vdisk_name = PROP.find("./PROPERTY[@name='name']").text
vdisk_health = PROP.find("./PROPERTY[@name='health']").text
vdisk_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
vdisk_status = PROP.find("./PROPERTY[@name='status']").text
vdisk_status_num = PROP.find("./PROPERTY[@name='status-numeric']").text
vdisk_owner = PROP.find("./PROPERTY[@name='owner']").text
vdisk_owner_num = PROP.find("./PROPERTY[@name='owner-numeric']").text
vdisk_owner_pref = PROP.find("./PROPERTY[@name='preferred-owner']").text
vdisk_owner_pref_num = PROP.find("./PROPERTY[@name='preferred-owner-numeric']").text
vdisk_full_data = {
"health": vdisk_health,
"health-num": vdisk_health_num,
"status": vdisk_status,
"status-num": vdisk_status_num,
"owner": vdisk_owner,
"owner-num": vdisk_owner_num,
"owner-pref": vdisk_owner_pref,
"owner-pref-num": vdisk_owner_pref_num
}
all_components[vdisk_name] = vdisk_full_data
elif component == 'pools':
for PROP in xml.findall("./OBJECT[@name='pools']"):
pool_name = PROP.find("./PROPERTY[@name='name']").text
pool_health = PROP.find("./PROPERTY[@name='health']").text
pool_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
pool_owner = PROP.find("./PROPERTY[@name='owner']").text
pool_owner_num = PROP.find("./PROPERTY[@name='owner-numeric']").text
pool_owner_pref = PROP.find("./PROPERTY[@name='preferred-owner']").text
pool_owner_pref_num = PROP.find("./PROPERTY[@name='preferred-owner-numeric']").text
# Get pool statistics
url = '{strg}/api/show/{comp}/pools/{item}'.format(strg=msa_conn, comp='pool-statistics', item=pool_name)
# Making request to API
stats_ret_code, stats_descr, stats_xml = query_xmlapi(url, sessionkey)
if stats_ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(stats_ret_code, stats_descr))
# THINK: I don't know, is it good solution, but it's one more query to XML API
pool_number_of_reads = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='number-of-reads']").text
pool_number_of_writes = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='number-of-writes']").text
pool_data_read_numeric = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='data-read-numeric']").text
pool_data_written_numeric = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='data-written-numeric']").text
pool_avg_rsp_time = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='avg-rsp-time']").text
pool_avg_read_rsp_time = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='avg-read-rsp-time']").text
pool_avg_write_rsp_time = stats_xml.find("./OBJECT[@name='pool-statistics']/OBJECT[@name='resettable-statistics']/PROPERTY[@name='avg-write-rsp-time']").text
pool_full_data = {
"health": pool_health,
"health-num": pool_health_num,
"owner": pool_owner,
"owner-num": pool_owner_num,
"owner-pref": pool_owner_pref,
"owner-pref-num": pool_owner_pref_num,
"number-of-reads": pool_number_of_reads,
"number-of-writes": pool_number_of_writes,
"data-read-numeric": pool_data_read_numeric,
"data-written-numeric": pool_data_written_numeric,
"avg-rsp-time": pool_avg_rsp_time,
"avg-read-rsp-time": pool_avg_read_rsp_time,
"avg-write-rsp-time": pool_avg_write_rsp_time,
}
all_components[pool_name] = pool_full_data
elif component == 'disk-groups':
for PROP in xml.findall("./OBJECT[@name='disk-group']"):
dg_name = PROP.find("./PROPERTY[@name='name']").text
dg_health = PROP.find("./PROPERTY[@name='health']").text
dg_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
dg_status = PROP.find("./PROPERTY[@name='status']").text
dg_status_num = PROP.find("./PROPERTY[@name='status-numeric']").text
dg_owner = PROP.find("./PROPERTY[@name='owner']").text
dg_owner_num = PROP.find("./PROPERTY[@name='owner-numeric']").text
dg_owner_pref = PROP.find("./PROPERTY[@name='preferred-owner']").text
dg_owner_pref_num = PROP.find("./PROPERTY[@name='preferred-owner-numeric']").text
# Get disk-group statistics
url = '{strg}/api/show/{comp}/disk-group/{item}'.format(strg=msa_conn, comp='disk-group-statistics', item=dg_name)
# Making request to API
stats_ret_code, stats_descr, stats_xml = query_xmlapi(url, sessionkey)
if stats_ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(stats_ret_code, stats_descr))
# THINK: I don't know, is it good solution, but it's one more query to XML API
dg_number_of_reads = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='number-of-reads']").text
dg_number_of_writes = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='number-of-writes']").text
dg_data_read_numeric = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='data-read-numeric']").text
dg_data_written_numeric = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='data-written-numeric']").text
dg_iops = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='iops']").text
dg_avg_rsp_time = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='avg-rsp-time']").text
dg_avg_read_rsp_time = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='avg-read-rsp-time']").text
dg_avg_write_rsp_time = stats_xml.find("./OBJECT[@name='disk-group-statistics']/PROPERTY[@name='avg-write-rsp-time']").text
dg_full_data = {
"health": dg_health,
"health-num": dg_health_num,
"status": dg_status,
"status-num": dg_status_num,
"owner": dg_owner,
"owner-num": dg_owner_num,
"owner-pref": dg_owner_pref,
"owner-pref-num": dg_owner_pref_num,
"number-of-reads": dg_number_of_reads,
"number-of-writes": dg_number_of_writes,
"data-read-numeric": dg_data_read_numeric,
"data-written-numeric": dg_data_written_numeric,
"iops": dg_iops,
"avg-rsp-time": dg_avg_rsp_time,
"avg-read-rsp-time": dg_avg_read_rsp_time,
"avg-write-rsp-time": dg_avg_write_rsp_time
}
all_components[dg_name] = dg_full_data
elif component == 'volumes':
for PROP in xml.findall("./OBJECT[@name='volume']"):
volume_name = PROP.find("./PROPERTY[@name='volume-name']").text
volume_health = PROP.find("./PROPERTY[@name='health']").text
volume_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
volume_owner = PROP.find("./PROPERTY[@name='owner']").text
volume_owner_num = PROP.find("./PROPERTY[@name='owner-numeric']").text
volume_owner_pref = PROP.find("./PROPERTY[@name='preferred-owner']").text
volume_owner_pref_num = PROP.find("./PROPERTY[@name='preferred-owner-numeric']").text
volume_full_data = {
"health": volume_health,
"health-num": volume_health_num,
"owner": volume_owner,
"owner-num": volume_owner_num,
"owner-pref": volume_owner_pref,
"owner-pref-num": volume_owner_pref_num
}
all_components[volume_name] = volume_full_data
elif component == 'controllers':
for PROP in xml.findall("./OBJECT[@name='controllers']"):
# Processing main controller properties
ctrl_id = PROP.find("./PROPERTY[@name='controller-id']").text
ctrl_sc_fw = PROP.find("./PROPERTY[@name='sc-fw']").text
ctrl_health = PROP.find("./PROPERTY[@name='health']").text
ctrl_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
ctrl_status = PROP.find("./PROPERTY[@name='status']").text
ctrl_status_num = PROP.find("./PROPERTY[@name='status-numeric']").text
ctrl_rd_status = PROP.find("./PROPERTY[@name='redundancy-status']").text
ctrl_rd_status_num = PROP.find("./PROPERTY[@name='redundancy-status-numeric']").text
# Get controller statistics
url = '{strg}/api/show/{comp}/{ctrl}'.format(strg=msa_conn, comp='controller-statistics', ctrl=ctrl_id)
# Making request to API
stats_ret_code, stats_descr, stats_xml = query_xmlapi(url, sessionkey)
if stats_ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(stats_ret_code, stats_descr))
# THINK: I don't know, is it good solution, but it's one more query to XML API
ctrl_cpu_load = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='cpu-load']").text
ctrl_iops = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='iops']").text
ctrl_number_of_reads = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='number-of-reads']").text
ctrl_number_of_writes = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='number-of-writes']").text
ctrl_data_read_numeric = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='data-read-numeric']").text
ctrl_data_written_numeric = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='data-written-numeric']").text
ctrl_read_cache_hits = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='read-cache-hits']").text
ctrl_read_cache_misses = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='read-cache-misses']").text
ctrl_write_cache_hits = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='write-cache-hits']").text
ctrl_write_cache_misses = stats_xml.find("./OBJECT[@name='controller-statistics']/PROPERTY[@name='write-cache-misses']").text
# Making full controller dict
ctrl_full_data = {
"health": ctrl_health,
"health-num": ctrl_health_num,
"status": ctrl_status,
"status-num": ctrl_status_num,
"redundancy": ctrl_rd_status,
"redundancy-num": ctrl_rd_status_num,
"cpu-load": ctrl_cpu_load,
"iops": ctrl_iops,
"number-of-reads": ctrl_number_of_reads,
"number-of-writes": ctrl_number_of_writes,
"data-read-numeric": ctrl_data_read_numeric,
"data-written-numeric": ctrl_data_written_numeric,
"read-cache-hits": ctrl_read_cache_hits,
"read-cache-misses": ctrl_read_cache_misses,
"write-cache-hits": ctrl_write_cache_hits,
"write-cache-misses": ctrl_write_cache_misses,
"sc-fw": ctrl_sc_fw
}
# Processing advanced controller properties
ctrl_ext = dict()
ctrl_ext['flash-health'] = PROP.find("./OBJECT[@basetype='compact-flash']/PROPERTY[@name='health']")
ctrl_ext['flash-health-num'] = PROP.find(
"./OBJECT[@basetype='compact-flash']/PROPERTY[@name='health-numeric']")
ctrl_ext['flash-status'] = PROP.find("./OBJECT[@basetype='compact-flash']/PROPERTY[@name='status']")
ctrl_ext['flash-status-num'] = PROP.find(
"./OBJECT[@basetype='compact-flash']/PROPERTY[@name='status-numeric']")
for prop, value in ctrl_ext.items():
if value is not None:
ctrl_full_data[prop] = value.text
all_components[ctrl_id] = ctrl_full_data
elif component == 'enclosures':
for PROP in xml.findall("./OBJECT[@name='enclosures']"):
# Processing main enclosure properties
encl_id = PROP.find("./PROPERTY[@name='enclosure-id']").text
encl_health = PROP.find("./PROPERTY[@name='health']").text
encl_health_num = PROP.find("./PROPERTY[@name='health-numeric']").text
encl_status = PROP.find("./PROPERTY[@name='status']").text
encl_status_num = PROP.find("./PROPERTY[@name='status-numeric']").text
# Making full enclosure dict
encl_full_data = {
"health": encl_health,
"health-num": encl_health_num,
"status": encl_status,
"status-num": encl_status_num
}
all_components[encl_id] = encl_full_data
elif component == 'power-supplies':
# Getting info about all power supplies
for PS in xml.findall("./OBJECT[@name='power-supplies']"):
# Processing main power supplies properties
ps_id = PS.find("./PROPERTY[@name='durable-id']").text
ps_name = PS.find("./PROPERTY[@name='name']").text
# Exclude voltage regulators
if ps_name.lower().find('voltage regulator') == -1:
ps_health = PS.find("./PROPERTY[@name='health']").text
ps_health_num = PS.find("./PROPERTY[@name='health-numeric']").text
ps_status = PS.find("./PROPERTY[@name='status']").text
ps_status_num = PS.find("./PROPERTY[@name='status-numeric']").text
ps_dc12v = PS.find("./PROPERTY[@name='dc12v']").text
ps_dc5v = PS.find("./PROPERTY[@name='dc5v']").text
ps_dc33v = PS.find("./PROPERTY[@name='dc33v']").text
ps_dc12i = PS.find("./PROPERTY[@name='dc12i']").text
ps_dc5i = PS.find("./PROPERTY[@name='dc5i']").text
ps_full_data = {
"health": ps_health,
"health-num": ps_health_num,
"status": ps_status,
"status-num": ps_status_num,
"power-12v": ps_dc12v,
"power-5v": ps_dc5v,
"power-33v": ps_dc33v,
"power-12i": ps_dc12i,
"power-5i": ps_dc5i
}
# Processing advanced power supplies properties
ps_ext = dict()
ps_ext['temperature'] = PS.find("./PROPERTY[@name='dctemp']")
for prop, value in ps_ext.items():
if value is not None:
ps_full_data[prop] = value.text
all_components[ps_id] = ps_full_data
elif component == 'fans':
# Getting info about all fans
for FAN in xml.findall("./OBJECT[@name='fan-details']"):
# Processing main fan properties
fan_id = FAN.find(".PROPERTY[@name='durable-id']").text
fan_health = FAN.find(".PROPERTY[@name='health']").text
fan_health_num = FAN.find(".PROPERTY[@name='health-numeric']").text
fan_status = FAN.find(".PROPERTY[@name='status']").text
fan_status_num = FAN.find(".PROPERTY[@name='status-numeric']").text
fan_speed = FAN.find(".PROPERTY[@name='speed']").text
fan_full_data = {
"health": fan_health,
"health-num": fan_health_num,
"status": fan_status,
"status-num": fan_status_num,
"speed": fan_speed
}
all_components[fan_id] = fan_full_data
elif component == 'ports':
for FC in xml.findall("./OBJECT[@name='ports']"):
# Processing main ports properties
port_name = FC.find("./PROPERTY[@name='port']").text
port_health = FC.find("./PROPERTY[@name='health']").text
port_health_num = FC.find("./PROPERTY[@name='health-numeric']").text
# Get host port statistics
url = '{strg}/api/show/{comp}/ports/{item}'.format(strg=msa_conn, comp='host-port-statistics', item=port_name)
# Making request to API
stats_ret_code, stats_descr, stats_xml = query_xmlapi(url, sessionkey)
if stats_ret_code != '0':
raise SystemExit('ERROR: {} : {}'.format(stats_ret_code, stats_descr))
# THINK: I don't know, is it good solution, but it's one more query to XML API
port_number_of_reads = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='number-of-reads']").text
port_number_of_writes = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='number-of-writes']").text
port_data_read_numeric = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='data-read-numeric']").text
port_data_written_numeric = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='data-written-numeric']").text
port_queue_depth = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='queue-depth']").text
port_avg_rsp_time = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='avg-rsp-time']").text
port_avg_read_rsp_time = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='avg-read-rsp-time']").text
port_avg_write_rsp_time = stats_xml.find("./OBJECT[@name='host-port-statistics']/PROPERTY[@name='avg-write-rsp-time']").text
if port_health_num != '4':
port_full_data = {
"health": port_health,
"health-num": port_health_num,
"number-of-reads": port_number_of_reads,
"number-of-writes": port_number_of_writes,
"data-read-numeric": port_data_read_numeric,
"data-written-numeric": port_data_written_numeric,
"queue-depth": port_queue_depth,
"avg-rsp-time": port_avg_rsp_time,
"avg-read-rsp-time": port_avg_read_rsp_time,
"avg-write-rsp-time": port_avg_write_rsp_time,
}
# Processing advanced ports properties
port_ext = dict()
port_ext['port-status'] = FC.find("./PROPERTY[@name='status']")
port_ext['port-status-num'] = FC.find("./PROPERTY[@name='status-numeric']")
port_ext['sfp-status'] = FC.find("./OBJECT[@name='port-details']/PROPERTY[@name='sfp-status']")
for prop, value in port_ext.items():
if value is not None:
port_full_data[prop] = value.text
all_components[port_name] = port_full_data
return json.dumps(all_components, separators=(',', ':'))
if __name__ == '__main__':
# Current program version
VERSION = '0.6.5'
MSA_PARTS = ('disks', 'vdisks', 'controllers', 'enclosures', 'fans',
'power-supplies', 'ports', 'pools', 'disk-groups', 'volumes')
# Main parser
main_parser = ArgumentParser(description='Zabbix script for HP MSA XML API.', add_help=True)
main_parser.add_argument('-a', '--api', type=int, default=2, choices=(1, 2), help='MSA API version (default: 2)')
main_parser.add_argument('-u', '--username', default='monitor', type=str, help='User name to login in MSA')
main_parser.add_argument('-p', '--password', default='!monitor', type=str, help='Password for your user')
main_parser.add_argument('-f', '--login-file', nargs=1, type=str, help='Path to file contains login and password')
main_parser.add_argument('-v', '--version', action='version', version=VERSION, help='Print script version and exit')
main_parser.add_argument('-s', '--save-xml', type=str, nargs=1, help='Save response from storage as XML file')
main_parser.add_argument('-t', '--tmp-dir', type=str, nargs=1, default='/dev/shm/zbx-hpmsa/',
help='Path to temp directory')
main_parser.add_argument('--ssl', type=str, choices=('direct', 'verify'), help='Use https instead http')
# Subparsers
subparsers = main_parser.add_subparsers(help='Possible options list', dest='command')
# Install script command
install_parser = subparsers.add_parser('install', help='Do preparation tasks')
# Show script cache
cache_parser = subparsers.add_parser('cache', help='Operations with cache')
cache_parser.add_argument('--show', action='store_true', help='Display cache data')
cache_parser.add_argument('--drop', action='store_true', help='Drop cache data')
# LLD script command
lld_parser = subparsers.add_parser('lld', help='Do low-level discovery task')
lld_parser.add_argument('msa', type=str, help='MSA address (DNS name or IP)')
lld_parser.add_argument('part', type=str, help='MSA part name', choices=MSA_PARTS)
# FULL script command
full_parser = subparsers.add_parser('full', help='Retrieve full data from MSA')
full_parser.add_argument('msa', type=str, help='MSA address (DNS name or IP)')
full_parser.add_argument('part', type=str, help='MSA part name', choices=MSA_PARTS)
# ?DELETE v0.7: HEALTH script command (Deprecated? Needn't anymore?)
health_parser = subparsers.add_parser('health', help='Retrieve health status for one component from MSA')
health_parser.add_argument('msa', type=str, help='MSA address (DNS name or IP)')
health_parser.add_argument('part', type=str, help='MSA part name', choices=MSA_PARTS)
health_parser.add_argument('pid', type=str, help='MSA part pid (e.g. "1.1" for disks)')
args = main_parser.parse_args()
# ?DELETE in v0.7 and correct make_lld()
# Matches between CLI 'show' command args and OBJECT 'name' attribute in XML output.
NAMES_MATCH = {
'disks': 'drive',
'vdisks': 'virtual-disk',
'controllers': 'controllers',
'enclosures': 'enclosures',
'power-supplies': 'power-supplies',
'fans': 'fan-details',
'ports': 'ports',
'pools': 'pools',
'disk-groups': 'disk-group',
'volumes': 'volume'
}
API_VERSION = args.api
TMP_DIR = args.tmp_dir
CACHE_DB = TMP_DIR.rstrip('/') + '/zbx-hpmsa.cache.db'
if args.command in ('lld', 'full', 'health'):
# Set some global variables
SAVE_XML = args.save_xml
USE_SSL = args.ssl in ('direct', 'verify')
VERIFY_SSL = args.ssl == 'verify'
MSA_USERNAME = args.username
MSA_PASSWORD = args.password
# (IP, DNS)
IS_IP = all(elem.isdigit() for elem in args.msa.split('.'))
MSA_CONNECT = args.msa if IS_IP else gethostbyname(args.msa), args.msa
# Make login hash string
if args.login_file is not None:
CRED_HASH = make_cred_hash(args.login_file, isfile=True)
else:
CRED_HASH = make_cred_hash('_'.join([MSA_USERNAME, MSA_PASSWORD]))
# Getting sessionkey
skey = get_skey(MSA_CONNECT, CRED_HASH)
# Make discovery
if args.command == 'lld':
print(make_lld(MSA_CONNECT, args.part, skey))
# ?DELETE in v0.7: Getting health of one MSA component
elif args.command == 'health':
print(get_health(MSA_CONNECT, args.part, args.pid, skey))
# Getting full components data in JSON
elif args.command == 'full':
print(get_full_json(MSA_CONNECT, args.part, skey))
# Preparations tasks
elif args.command == 'install':
install_script(TMP_DIR, 'zabbix')
# Operations with cache
elif args.command == 'cache':
if args.show:
display_cache()
elif args.drop:
sql_cmd('DELETE FROM skey_cache;')
# Default is --show
else:
display_cache()
exit(0)