Hi Everyone,
first of all I hope that I am posting in the correct forum, if not please let me know.
Anyway I want to gather all "Warning" and "Error" events from our ESXi servers which are logged in vSphere under Tasks and Events -> Events. I want to do this via vSphere API, for this I am using pyVIm and pyVmomi. Right now I have the following code in Python:
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim
import datetime
import ssl
# SSL verfification temporarily disabled for testing
connection = SmartConnect(host="server",user="user",pwd="password",port=443,sslContext=ssl._create_unverified_context())
content = connection.RetrieveContent()
eventFilterTime = vim.event.EventFilterSpec.ByTime()
eventFilterTime.endTime = datetime.datetime.now()
eventFilterTime.beginTime = datetime.datetime.now() - datetime.timedelta(hours=1)
eventFilterSpec = vim.event.EventFilterSpec(time=eventFilterTime)
eventCollector = content.eventManager.CreateCollector(eventFilterSpec)
# Writing to file for testing
file = open("C:\\vSphereAPITest\\test.txt", "a")
event = eventCollector.latestPage
while len(event) > 0:
file.write(str(event))
event = eventCollector.ReadPrev(20)
print("run")
file.close()
Disconnect(connection)
With this I receive almost all events, only the events with type warning and error are missing, so basically the events I need are missing.
For example I can see an event of type vim.event.VmMacConflictEven in vSphere (via Browser), but the python export only shows the event above and below this one. Currently I have only this error event in the console so I can´t verify if other error events are logged via script. I also tried to use the AlarmManager instead of the EventManager, but the property alarmManager was null. So I was hoping that I can receive all events via the EventManager.
So basically I have the following questions:
- Why is the EventManager not returning all events?
- Is there a different way to get Warning or Error Events?
This is my first time working with the vSphere API and I created the code via trial and error so please excuse if I missed something obvious.
Thank you in advance for your help.
regards