OpenLMI Journald usage

The OpenLMI Journald provider depends on running journald daemon. See the systemd manual for how to enable the journald service.

Listing a log

This example shows simple enumeration through available LMI_JournalLogRecord instances in classic syslog-like format:

#!/usr/bin/lmishell
c = connect("localhost", "pegasus", "test")
for rec in c.root.cimv2.LMI_JournalMessageLog.first_instance().associators():
    print "%s %s %s" % (rec.MessageTimestamp.datetime.ctime(), rec.HostName, rec.DataFormat)

Note

Only a limited number of records are being enumerated and printed out, please see the Number of LMI_JournalLogRecord instances enumerated limitation remark.

Iterating through the log

This example uses iterator methods of the LMI_JournalMessageLog class to continuously go through the whole journal:

#!/usr/bin/lmishell
c = connect("localhost", "pegasus", "test")
inst = c.root.cimv2.LMI_JournalMessageLog.first_instance()
r = inst.PositionToFirstRecord()
iter_id = r.rparams['IterationIdentifier']
while True:
    x = inst.GetRecord(IterationIdentifier=iter_id, PositionToNext=True)
    if x.rval != 0:
        break
    print "".join(map(chr, x.rparams['RecordData']))
    iter_id = x.rparams['IterationIdentifier']

Sending new message to log

Simple example that uses LMI_JournalLogRecord.create_instance() CIM method to send a new message in the log:

#!/usr/bin/lmishell
c = connect("localhost", "pegasus", "test")
c.root.cimv2.LMI_JournalLogRecord.create_instance({"CreationClassName": "LMI_JournalLogRecord",
                                                   "LogCreationClassName": "LMI_JournalMessageLog",
                                                   "LogName": "Journal",
                                                   "DataFormat": ""})

Table Of Contents

Previous topic

OpenLMI Journald Provider documentation

Next topic

Inheritance tree

This Page