Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import os
- import re
- import sys
- binarypath = "/usr/sbin/hpacucli"
- if len(sys.argv) > 2:
- print 'Usage: hpacucli-status [-d]'
- sys.exit(1)
- printarray = True
- if len(sys.argv) > 1:
- if sys.argv[1] == '-d':
- printarray = False
- else:
- print 'Usage: hpacucli-status [-d]'
- sys.exit(1)
- # Check binary exists (and +x), if not print an error message
- if os.path.exists(binarypath) and os.access(binarypath, os.X_OK):
- pass
- else:
- sys.exit(3)
- # Get command output
- def getOutput(cmd):
- output = os.popen(cmd)
- lines = []
- for line in output:
- if not re.match(r'^$',line.strip()):
- lines.append(line.strip())
- return lines
- def returnDiskList(output):
- lines = []
- enclid=''
- slotid=''
- diskstatus=''
- realid=['','']
- # physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SATA, 160.0 GB, OK)
- for line in output:
- groups = re.match('.*?(box).*?(\d+).*?(bay).*?(\d+).*?((?:[a-z][a-z]+)).*?(\d+).*?(\d+).*?((?:[a-z][a-z]+)).*?((?:[a-z][a-z]+))', line, re.IGNORECASE)
- if groups:
- diskstatus = groups.group(9)
- enclid = groups.group(2)
- slotid = groups.group(4)
- size = groups.group(6)+"."+groups.group(7)+" "+groups.group(8)
- lines.append([enclid,slotid,size,diskstatus])
- return lines
- def returnArrayList(output):
- lines = []
- id=''
- type=''
- size=''
- status=''
- for line in output:
- groups = re.match('(logicaldrive).*?(\d+).*?([+-]?\d*\.\d+)(?![-+0-9\.]).*?((?:[a-z][a-z]+)).*?(RAID).*?(\d+).*?((?:[a-z][a-z]+))', line, re.IGNORECASE)
- if groups:
- id = groups.group(2)
- type = groups.group(5)+" "+groups.group(6)
- size = groups.group(3)+" "+groups.group(4)
- status = groups.group(7)
- lines.append([id,type,size,status])
- return lines
- cmd = binarypath+' ctrl all show config'
- output = getOutput(cmd)
- disklist = returnDiskList(output)
- arraylist = returnArrayList(output)
- if printarray:
- print '-- Arrays informations --'
- print '-- ID | Type | Size | Status'
- for array in arraylist:
- print array[0]+' | '+array[2]+' '+array[3]+' | '+array[1]+' | '+array[-1]
- print ''
- print '-- Disks informations'
- print '-- Enclosure | Slot | Size | Status'
- for disk in disklist:
- print disk[0]+' | '+disk[1]+' | '+disk[2]+' | '+disk[3]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement