Show Table of Contents
2.22. Example: Checking System Events using Python
Red Hat Enterprise Virtualization Manager records and logs many system events. These event logs are accessible through the user interface, the system log files, and using the API. The ovirtsdk library exposes events using the
events collection.
Example 2.23. Checking System Events using Python
In this example the
events collection is listed. Note that:
- The
queryparameter of thelistmethod is used to ensure that all available pages of results are returned. By default thelistmethod will only return the first page of results which defaults to a maximum of100records in length. - The resultant list is reversed to ensure that events are included in the output in the order that they occurred.
from ovirtsdk.api import API
from ovirtsdk.xml import params
try:
api = API (url="https://HOST",
username="USER@DOMAIN",
password="PASS",
ca_file="ca.crt")
event_list = []
event_page_index = 1
event_page_current = api.events.list(query="page %s" % event_page_index)
while(len(event_page_current) != 0):
event_list = event_list + event_page_current
event_page_index = event_page_index + 1
try:
event_page_current = api.events.list(query="page %s" % event_page_index)
except Exception as ex:
print "Error retrieving page %s of list: %s" % (event_page_index, ex)
event_list.reverse()
for event in event_list:
print "%s %s CODE %s - %s" % (event.get_time(),
event.get_severity().upper(),
event.get_code(),
event.get_description())
except Exception as ex:
print "Unexpected error: %s" % ex
Output from this script will look like this - albeit with different events depending on the state of the environment:
2012-09-25T18:40:10.065-04:00 NORMAL CODE 30 - User admin@internal logged in. 2012-09-25T18:40:10.368-04:00 NORMAL CODE 153 - VM vm1 was started by admin@internal (Host: Atlantic). 2012-09-25T18:40:10.470-04:00 NORMAL CODE 30 - User admin@internal logged in.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.