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.
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
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 )
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 )
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 )
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] )
On the log instance that represents the SEL, invoke the ClearLog() method with no parameters.