#!/usr/bin/env pythonimport subprocesstry:import simplejson as jsonexcept:import jsonmemory_status = {} p = subprocess. Popen ("dmidecode --type system | perl -alne '/manufacturer:\s (. *)/ and print $1 ' ", shell=true, stdout=subprocess. PIPE) Vender = p.stdout.readline (). Strip () if vender == ' HP ': Mem_slot = []mem _status = []p = subprocess.call ("Rpm -qa | grep hp-health", shell =true, stdout=subprocess. PIPE) If p != 0:subprocess.call ("rpm -ivh http://downloads.linux.hp.com/downloads/ managementcomponentpack/centos/6/x86_64/9.40/hp-health-9.40-1602.44.rhel6.x86_64.rpm ", shell=True, Stdout=subprocess. Pipe, stderr=subprocess. PIPE) p = subprocess. Popen ("hpasmcli -s ' Show dimm '", shell=true, stdout=subprocess. PIPE) FOR LINE IN&NBsp;p.stdout.readlines (): A = {}data = line.strip (). Split (":") If len (data) == 2:a[data[0].strip ()] = data[1].strip () if ' Status ' in a.keys (): status = a[' Status '] if status == "OK": status = 0 mem_status.append (status) Length = len ( Mem_status) If length:for i in range (0, length):slot = "slot_%d" % (i) mem_slot.append (slot) mEmory_status = dict (Zip (mem_slot, mem_status)) else:mem_slot = []mem_status = []p = subprocess. Popen ("Omreport chassis memory", shell=true, stdout=subprocess. PIPE) For line in p.stdout.readlines (): A = {}data = line.strip (). Split (":") If len (data) == 2:a[data[0].strip ()] = data[1].strip () if ' Index ' in A.keys ():slot = "slot_" + a[' Index ']if slot:mem_slot.append (slot) elif ' Status ' in a.keys (): status = a[' status ']if status != ' Unknown ' and status == "OK": status = 0mem_status.append (status) memory_status = dict (Zip (mem_ Slot, mem_status)) Print json.dumps (memory_status, indent=4)
Python gets the state of the memory