This example shows how to list the records in the system event log (SEL) of a managed server. This example also shows how to clear the records from the SEL. Clearing the log entries can save on disk space and reduce clutter from old records in the SEL.

You can locate the instance of CIM_RecordLog that represents the SEL by enumerating all instances of CIM_RecordLog and filtering out other logs by name. The log records are associated to the CIM_RecordLog instance. Listing Records of the System Event Log shows the relationships of the CIM objects involved.

Note:

This discussion assumes that the managed server is a single-node system.

Figure 1. Listing Records of the System Event Log
Diagram shows classes used to access System Event Log.

This example shows how to get the log entries from the Implementation namespace, assuming you already know its name. The pseudocode in this topic depends on the pseudocode in Make a Connection to the CIMOM.

To list and clear the System Event Log

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 instance names of CIM_RecordLog.
    instance_names = connection.EnumerateInstanceNames( ’CIM_RecordLog’ )
    if len( instance_names ) is 0
       print 'Error:  No logs found on managed server.'
       sys.exit( -1 )
  3. Iterate over the log instances, rejecting all log instances that are not named "IPMI SEL".
    for instance_name in instance_names
       instance = connection.GetInstance( instance_name )
       if instance[’ElementName’] is ’IPMI SEL’
          print_log_entries( instance_name )
          clear_log_entries( instance_name )
  4. From the log instance that represents the SEL, traverse the CIM_LogManagesRecord association to reach the entries that belong to the log.
    function print_log_entries( instance_name )
       instances = connection.Associators( instance_name,
                                           AssocClass = ’CIM_LogManagesRecord’ )
       for instance in instances
          for prop in [ ’MessageTimestamp’, ’RecordData’ ]
             print ’ %28s %s’ % ( prop, instance[prop] )
  5. On the log instance that represents the SEL, invoke the ClearLog() method with no parameters.
    function clear_log_entries( instance_name )
       method_params = { }
       ( error_return, output ) = connection.InvokeMethod( 'ClearLog', \
                                                           instance_name, \
                                                           **method_params )
       if error_return is 0
          print ’Log entries cleared.’
       else
          print ’Failed to clear log entries; error = %s’ % error_return
    A sample of the output looks like the following:
    Log contains 5 entries:
      MessageTimestamp 20090408014645.000000+000
        RecordData *81.0.32*1 0*2*5 2 220 73*32 0*4*16*81*false*111*2*255*255*1*
      MessageTimestamp 20090408014807.000000+000
        RecordData *3.0.32*2 0*2*87 2 220 73*32 0*4*1*3*false*1*87*149*129*1*
      MessageTimestamp 20090408015617.000000+000
        RecordData *3.0.32*3 0*2*65 4 220 73*32 0*4*1*3*false*1*89*149*129*1*
      MessageTimestamp 20090408020052.000000+000
        RecordData *3.0.32*4 0*2*84 5 220 73*32 0*4*1*3*false*1*89*149*129*1*
      MessageTimestamp 20090408020807.000000+000
        RecordData *3.0.32*5 0*2*7 7 220 73*32 0*4*1*3*false*1*89*150*129*1*
    Log entries cleared.