Skip to content

Instantly share code, notes, and snippets.

@apalii
Last active February 24, 2016 07:30
Show Gist options
  • Save apalii/cd82c6bb3e207944a1e9 to your computer and use it in GitHub Desktop.
Save apalii/cd82c6bb3e207944a1e9 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import subprocess
def output(color, message='empty message'):
colors = {
'blue' : '\033[94m',
'green' : '\033[92m',
'yellow' : '\033[93m',
'red' : '\033[91m',
'normal' : '\033[0m',
}
if color not in colors.keys():
print message
else:
print colors[color] + message + colors['normal']
battery = r'sudo megacli -AdpBbuCmd -GetBbuStatus -aALL | egrep "Remaining C|Full Charge C|Battery Rep|Battery Pack M" | tr -s " " | sed s/^[[:space:]]*//'
disks = r"sudo megacli -LDPDInfo -aALL | egrep 'Inquiry D|Slot N|Error Co|Size|RAID L|^State|Bad Blocks E|Adap' | sed -e 's/^Slot Number/\nSlot Number/' -e 's/^Adapter/\nAdapter/' | tr -s ' '"
battery_result = subprocess.Popen(battery, shell=True, stdout=subprocess.PIPE).stdout.read().rstrip()
disk_result = subprocess.Popen(disks, shell=True, stdout=subprocess.PIPE).stdout.read().rstrip()
output('green', 'Battery check :'.upper())
print "-" * 80
count = 0
for line in battery_result.split("\n"):
line_list = line.split(":")
if len(line_list) > 1:
print '{:<32} : {}'.format(line_list[0], line_list[1])
count += 1
if count == 6:
print "-" * 60
else:
print "-" * 80
for line in disk_result.split("\n"):
if line.startswith("Adapter"):
output('green', line.upper())
continue
if line.startswith("Slot Number"):
output('yellow', line)
continue
if line.startswith('Media') or line.startswith('Other'):
line_list = line.split(":")
if int(line_list[1]) > 0:
print '{:<32} : {}'.format(line_list[0], line_list[1])
continue
elif int(line_list[1]) == 0:
continue
line_list = line.split(":")
if len(line_list) > 1:
print '{:<32} : {}'.format(line_list[0], line_list[1])
else:
print "-" * 80
@apalii
Copy link
Author

apalii commented Dec 31, 2014

  • How to download script ?

    wget --no-check-certificate --content-disposition https://gist.githubusercontent.com/apalii/cd82c6bb3e207944a1e9/raw/ccb3fb110b10a12e8a93f7b41a72adefb9a0cca1/disk_checker.py
  • How to run the script ?

    $ python2.7 disk_checker.py

@apalii
Copy link
Author

apalii commented Jan 19, 2015

How to download for whole installation :

for i in `mysql -uroot porta-configurator -sse "select ip from Servers"`
do
    echo -e "\n\n---SIP server: $i---\n"
    rsh_porta.sh $i '
    wget --no-check-certificate --content-disposition https://gist.githubusercontent.com/apalii/cd82c6bb3e207944a1e9/raw/508459572cf3f5f4fa468e58588fa537a89ed71f/disk_checker.py'
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment