Update: Trigger a User event from the VCSA command line
Disclaimer: This is not officially supported by VMware, please use at your own risk.
Recently I faced the challenge with a script running on a VCSA which executes some checks and in case something gets detected it has to trigger a vCenter alarm.
My solution is to log a user event which will be captured by an vCenter alert definition.
1. vCenter alert definition
as trigger manually enter (type): vim.event.GeneralUserEvent
2. The script which will log the user event
#!/usr/bin/python
#!/usr/bin/python
import sys
sys.path.insert(0, '/usr/lib/vmware/site-packages/')
from pyVim.connect import SmartConnect
from pyVmomi import vim
import ssl
import atexit
username = 'administrator@vsphere.local'
password = 'VMware1!'
v = sys.version_info
try:
if sys.version_info[1] <7 or v.minor < 7:
si = SmartConnect(host="localhost", user=username, pwd=password)
content = si.RetrieveContent()
ds = content.rootFolder
log = si.content.eventManager.LogUserEvent(entity=ds, msg="Postgres Corruption detected")
else:
s = ssl.SSLContext(ssl.PROTOCOL_TLS)
s.verify_mode = ssl.CERT_NONE
si = SmartConnect(host="localhost", user=username, pwd=password, sslContext=s)
content = si.RetrieveContent()
ds = content.rootFolder
log = si.content.eventManager.LogUserEvent(entity=ds, msg="Postgres Corruption detected")
except:
print("Unexpected error:", sys.exc_info()[0])
Result:
The resulting alert can be catched by vROPs and trigger further events/ tickets.