This information is useful to system
administrators who need to monitor system health. This example shows how to
locate system sensors, report their current states, and flag any sensors that
have abnormal states.
The example uses only
CIM_NumericSensor instances
for simplicity. You can also query discrete sensors by substituting
CIM_Sensor for
CIM_NumericSensor. Determining
which values constitute normal sensor state is hardware-dependent.
Specify the Interop namespace, supplied as a
parameter, for the connection.
use wbemlib
use sys
use connection renamed cnx
connection = Null
params = cnx.get_params()
if params is Null
sys.exit(-1)
interop_params = params
interop_params['namespace'] = 'root/interop'
connection = cnx.connect_to_host( interop_params )
if connection is Null
print 'Failed to connect to: ' + params['host'] + ' as user: ' + params['user']
sys.exit(-1)
Locate the Base Server profile Scoping
Instance of CIM_ComputerSystem.
use scoping_instance renamed si
scoping_instance_name = si.get_scoping_instance_name( connection )
if scoping_instance_name is Null
print 'Failed to find server Scoping Instance.'
sys.exit(-1)
Traverse the
CIM_SystemDevice association to reach the CIM_NumericSensor
instances on the managed server.
instances = connection.Associators( scoping_instance_name, \
AssocClass = 'CIM_SystemDevice', \
ResultClass = 'CIM_NumericSensor' )
if len( instances ) is 0
print 'Error: No sensors associated with server Scoping Instance.'
sys.exit(-1)
For each sensor instance, print the ElementName
and CurrentState
properties.
You can flag any abnormal values you find.
Abnormal values depend on the sensor type and its PossibleStates
property.
function print_info( instance, base_class )
print '\n' + base_class + ' [' + instance.classname + '] ='
if instance['CurrentState'] != 'Normal'
print '********* SENSOR STATE WARNING *********\n'
for prop in [ 'ElementName', 'CurrentState' ]
print ' %30s = %s' % ( prop, instance[prop] )
for instance in instances
print_info( instance, 'CIM_NumericSensor' )
A sample of the output looks like the
following:
CIM_NumericSensor [OMC_NumericSensor] =
ElementName = FAN 1 RPM for System Board 1
CurrentState = Normal
CIM_NumericSensor [OMC_NumericSensor] =
ElementName = Ambient Temp for System Board 1
CurrentState = Normal