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
|
#!/usr/bin/python3
from __future__ import unicode_literals
from builtins import str
import os
import pwd
import hashlib
import platform
import crm_script
import crmsh.log
crmsh.log.setup_logging()
from crmsh.report import utils
import crmsh.utils
data = crm_script.get_input()
PACKAGES = ['booth', 'corosync', 'crmsh', 'csync2', 'drbd',
'fence-agents', 'gfs2', 'gfs2-utils', 'ha-cluster-bootstrap',
'haproxy', 'hawk', 'libdlm', 'libqb', 'ocfs2', 'ocfs2-tools',
'pacemaker', 'resource-agents', 'sbd']
def rpm_info():
return crm_script.rpmcheck(PACKAGES)
def logrotate_info():
return {}
def get_user():
return pwd.getpwuid(os.getuid()).pw_name
def sys_info():
with open('/proc/uptime') as f:
uptime = f.read().split()
if crmsh.utils.ansible_installed():
facts = crmsh.utils.ansible_facts('setup')
return {'system': facts.get("ansible_system"),
'node': facts.get("ansible_hostname"),
'release': facts.get("ansible_kernel"),
'version': facts.get("ansible_kernel_version"),
'machine': facts.get("ansible_machine"),
'processor': facts.get("ansible_architecture"),
'distname': facts.get("ansible_distribution"),
'user': facts.get("ansible_user_id"),
'hostname': facts.get("ansible_nodename"),
'uptime': facts.get("ansible_uptime_seconds"),
'idletime': uptime[1], # :( not in ansible setup module
'loadavg': facts.get("ansible_loadavg").get("15m") # 15 minute average
}
# if ansible is not installed, do it like before
sysname, nodename, release, version, machine = os.uname()
# The first three columns measure CPU and IO utilization of the
# last one, five, and 15 minute periods. The fourth column shows
# the number of currently running processes and the total number of
# processes. The last column displays the last process ID used.
system, node, release, version, machine, processor = platform.uname()
distname = utils.get_distro_info()
hostname = os.uname()[1]
with open('/proc/loadavg') as f:
loadavg = f.read().split()
return {'system': system,
'node': node,
'release': release,
'version': version,
'machine': machine,
'processor': processor,
'distname': distname,
'user': get_user(),
'hostname': hostname,
'uptime': uptime[0],
'idletime': uptime[1],
'loadavg': loadavg[2] # 15 minute average
}
def disk_info():
rc, out, err = crm_script.call(['df'], shell=False)
if rc == 0:
disk_use = []
for line in out.split('\n')[1:]:
line = line.strip()
if line:
data = line.split()
if len(data) >= 6:
disk_use.append((data[5], data[4]))
return disk_use
return []
# configurations out of sync
FILES = [
'/etc/csync2/key_hagroup',
'/etc/csync2/csync2.cfg',
'/etc/corosync/corosync.conf',
'/etc/default/sbd'
]
def files_info():
ret = {}
for f in FILES:
if os.path.isfile(f):
try:
ret[f] = hashlib.sha1(open(f).read().encode('utf-8')).hexdigest()
except IOError as e:
ret[f] = "error: %s" % (e)
else:
ret[f] = ""
return ret
try:
data = {
'rpm': rpm_info(),
'logrotate': logrotate_info(),
'system': sys_info(),
'disk': disk_info(),
'files': files_info()
}
crm_script.exit_ok(data)
except Exception as e:
crm_script.exit_fail(str(e))
|