Category Archives: nagios

Nagios check_datastore

Check esxi datastore free space

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

ok = 160000
warn_value = 150000
crit_value = 100000
status = { 'OK' : 0 , 'WARNING' : 1, 'CRITICAL' : 2 , 'UNKNOWN' : 3}

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

warn = False
crit = False
lowestFreeSpace = None

s = VIServer()
s.connect(server, user, pwd)
for ds, name in s.get_datastores().items():
props = VIProperty(s, ds)
freeSpace = props.summary.freeSpace / 1024**2
if lowestFreeSpace == None or freeSpace < lowestFreeSpace: lowestFreeSpace = freeSpace lowestDatastoreName = name s.disconnect() if lowestFreeSpace < crit_value: crit = True if lowestFreeSpace < warn_value: warn = True if crit_value >= warn_value:
crit = True

if warn == True:
if crit == True:
print lowestDatastoreName, "Critical space, less than 100G"
sys.exit(status['CRITICAL'])
else:
print lowestDatastoreName, "Running low on space, less than 150G"
sys.exit(status['WARNING'])

else:
print 'status OK, datastore has enough space'
sys.exit(status['OK'])

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'])