diff --git a/ilorest.py b/ilorest.py new file mode 100644 index 0000000..5003d44 --- /dev/null +++ b/ilorest.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +import subprocess +import json +import argparse + +def run_ilorest_command(ilorest_command, url, username, password): + command = f'ilorest {ilorest_command} --url {url} -u {username} -p {password} --json'.split() + try: + result = subprocess.run(command, stdout=subprocess.PIPE, check=True) + return json.loads(''.join(result.stdout.decode('utf-8').split('\n')[1:])) + except Exception as e: + print(f'Error running iLO REST command: {e}') + exit(1) + +def get_memory_health(url, username, password, debug): + ilorest_command = 'serverinfo --memory' + status = 0 + memory_info = run_ilorest_command(ilorest_command, url, username, password) + if debug: + print(json.dumps(memory_info)) + exit(status) + for stick_attr in memory_info['memory'].values(): + if stick_attr.get('Health', 'OK') != 'OK': + print(f"Status: {stick_attr['Status']} Location: {stick_attr['Location']}") + status = 1 + exit(status) +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Get health details from HPE iLO REST API') + parser.add_argument('-H', '--url', required=True, help='iLO URL') + parser.add_argument('-u', '--username', required=True, help='iLO username') + parser.add_argument('-p', '--password', required=True, help='iLO password') + parser.add_argument('--debug', action='store_true') + args = parser.parse_args() + get_memory_health(**vars(args))