Skip to content

Commit

Permalink
Add a function for calculating a custom datastore property
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaeon committed Jul 3, 2013
1 parent 73f1971 commit 2cc4daa
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions poller/vm-poller.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,12 @@ def get_host_property(self, name, prop):

# return the property if found and break
if d['name'] == name:
if prop not in d:
return 0 # Return zero here and not None, so that Zabbix can understand the value

if custom_property_requested:
return custom_zabbix_host_properties[prop]['function'](d)
else:
elif prop in d and not custom_property_requested:
return zabbix_host_properties[prop](d[prop])
else:
return 0 # Return zero here and not None, so that Zabbix can understand the value

return 0

Expand Down Expand Up @@ -226,13 +225,13 @@ def get_datastore_property(self, name, url, prop):

# return the result back to Zabbix if we have a match
if d['info.name'] == name and d['info.url'] == url:
if prop not in d:
return 0 # Return zero here and not None so that Zabbix understands the value

if custom_property_requested:
return custom_zabbix_datastore_properties[prop]['function'](d)
else:
elif prop in d and not custom_property_requested:
return zabbix_datastore_properties[prop](d[prop])
else:
return 0

return 0

Expand Down Expand Up @@ -272,14 +271,25 @@ def return_as_hz(val):
return val * 1048576

def parse_config(conf):
"""
Parse the provided configuration file and return a ConfigParser object
"""
if not os.path.exists(conf):
raise IOError, 'Config file %s does not exists' % conf

config = ConfigParser.ConfigParser()
config.read(conf)

return config


def datastore_used_space_percentage(d):
"""
Calculate the used datastore space in percentage
"""
return round(100 - (float(d['summary.freeSpace']) / float(d['summary.capacity']) * 100), 2)

def main():

if len(sys.argv) != 10:
Expand Down

0 comments on commit 2cc4daa

Please sign in to comment.