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 with 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.

This example shows how to get the sensor states from the Implementation namespace, assuming you already know its name. For information about getting sensor state by using the standard Interop namespace, seeMonitor State of All Sensors.

This pseudocode depends on the pseudocode in Make a Connection to the CIMOM.

To report state of all sensors by using only the Implementation namespace

Procedure

  1. Connect to the server URL.

    Specify the Implementation namespace, supplied as a parameter, for the connection.

    The actual namespace you will use depends on your installation.

    use wbemlib
    use sys
    use connection renamed cnx
    connection = Null
    
    params = cnx.get_params()
    if params is Null
       sys.exit(-1)
    connection = cnx.connect_to_host( params )
    if connection is Null
       print 'Failed to connect to: ' + params['host'] + ' as user: ' + params['user']
       sys.exit(-1)
  2. Enumerate instances of CIM_NumericSensor.
    instances = connection.EnumerateInstances( ’CIM_NumericSensor’ )
    if len( instances ) is 0
       print 'Error:  No sensors found on managed server.'
       sys.exit(-1)
  3. Iterate over the sensor instances, printing the properties ElementName and CurrentState.
    function print_info( instance ) 
       print '\n' + 'CIM_NumericSensor [' + 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 )
    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