Skip to content

Instantly share code, notes, and snippets.

@hartsock
Forked from complexsplit/alarms-unset-status.py
Created June 16, 2014 19:23
Show Gist options
  • Save hartsock/3cd505e2c8c4a777401b to your computer and use it in GitHub Desktop.
Save hartsock/3cd505e2c8c4a777401b to your computer and use it in GitHub Desktop.
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
# this script is intended to be run against all vcenters daily in order to
# guard against a possible vcenter crash due to alarms with an unset status.
# it prints all alarms with Trigger events w/ an "Unset" status.
# this bug is detailed at http://kb.vmware.com/kb/2062989
user = "username"
pwd = "password"
vcs = ["vcenter"]
for vc in vcs:
si = SmartConnect(host=vc, user=user, pwd=pwd)
content = si.RetrieveContent()
am = content.alarmManager
alarms = am.GetAlarm(content.rootFolder) # get all alarms
for alarm in alarms:
try:
# only alarms of type EventAlarms can be unset
if isinstance(alarm.info.expression.expression[0], vim.alarm.EventAlarmExpression):
# status can be Normal, Warning, Alert, or Unset. Unset maps to "none"
if alarm.info.expression.expression[0].status == None:
print alarm.info.name
except AttributeError, e:
None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment