Nagios check_esxi_snapshots

This script is using pySphere api for esxi and do loop through all vms and checks for snapshots.

#!/usr/bin/python
from pysphere import VIServer
import sys

ok = 0
warn = 1
crit = 2
status = { 'OK' : 0 , 'WARNING' : 1, 'CRITICAL' : 2 , 'UNKNOWN' : 3}

server = sys.argv[1]
user = sys.argv[2]
pwd = sys.argv[3]

s = VIServer()
s.connect(server, user, pwd)
names = ""
result = s._retrieve_properties_traversal(
property_names=['name', 'rootSnapshot'],
obj_type="VirtualMachine")
for props in result:
has_snapshots = False
name = ""
for ps in props.PropSet:
if ps.Name=='rootSnapshot' and ps.Val.ManagedObjectReference:
has_snapshots = True
if ps.Name=='name':
name = ps.Val
if has_snapshots:
names = names + name + ', '
if warn == True:

if crit == True:
print names, 'has a snapshot'
print status['CRITICAL']
sys.exit(status['CRITICAL'])
else:
print names, "are running with snapshot"
print status['WARNING']
sys.exit(status['WARNING'])

else:
print 'status OK, no snapshots'
sys.exit(status['OK'])