mp/naf: Allow units for warn/crit thresholds and ranges
Signed-off-by: Sven Velt <sven@velt.de>
This commit is contained in:
parent
2a9c069e9d
commit
2ee9428885
|
@ -633,8 +633,8 @@ class CheckNAF(SNMPMonitoringPlugin):
|
||||||
|
|
||||||
fs_pctused = float(fs_used) / float(fs_total) * 100.0
|
fs_pctused = float(fs_used) / float(fs_total) * 100.0
|
||||||
|
|
||||||
warn = self.range_dehumanize(warn, fs_total)
|
warn = self.range_dehumanize(warn, fs_total, unit=['b',])
|
||||||
crit = self.range_dehumanize(crit, fs_total)
|
crit = self.range_dehumanize(crit, fs_total, unit=['b',])
|
||||||
|
|
||||||
returncode = self.value_wc_to_returncode(fs_used, warn, crit)
|
returncode = self.value_wc_to_returncode(fs_used, warn, crit)
|
||||||
output = volume + ': Used ' + self.value_to_human_binary(fs_used, 'B')
|
output = volume + ': Used ' + self.value_to_human_binary(fs_used, 'B')
|
||||||
|
@ -662,8 +662,8 @@ class CheckNAF(SNMPMonitoringPlugin):
|
||||||
sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
|
sn_used = long(self.SNMPGET(self.OID['df_FS_kBUsed'], sn_idx)) * 1024L
|
||||||
# sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
|
# sn_avail = long(self.SNMPGET(self.OID['df_FS_kBAvail'], sn_idx)) * 1024L
|
||||||
|
|
||||||
warn = self.range_dehumanize(warn, sn_total)
|
warn = self.range_dehumanize(warn, sn_total, unit=['b',])
|
||||||
crit = self.range_dehumanize(crit, sn_total)
|
crit = self.range_dehumanize(crit, sn_total, unit=['b',])
|
||||||
if sn_total != 0:
|
if sn_total != 0:
|
||||||
# Snap reserve
|
# Snap reserve
|
||||||
sn_pctused = float(sn_used) / float(sn_total) * 100.0
|
sn_pctused = float(sn_used) / float(sn_total) * 100.0
|
||||||
|
|
|
@ -300,10 +300,20 @@ class MonitoringPlugin(object):
|
||||||
return datetime.timedelta(seconds=long(seconds))
|
return datetime.timedelta(seconds=long(seconds))
|
||||||
|
|
||||||
|
|
||||||
def human_to_number(self, value, total=None):
|
def human_to_number(self, value, total=None, unit=['',]):
|
||||||
if total:
|
if total:
|
||||||
if not self.is_float(total):
|
if not self.is_float(total):
|
||||||
total = self.human_to_number(total)
|
total = self.human_to_number(total, unit=unit)
|
||||||
|
|
||||||
|
if type(unit) == list:
|
||||||
|
unit = [u.lower() for u in unit]
|
||||||
|
elif type(unit) == str:
|
||||||
|
unit = [unit.lower(),]
|
||||||
|
else:
|
||||||
|
unit = ['',]
|
||||||
|
|
||||||
|
if value.lower()[-1] in unit:
|
||||||
|
value = value[0:-1]
|
||||||
|
|
||||||
if self.is_float(value):
|
if self.is_float(value):
|
||||||
return float(value)
|
return float(value)
|
||||||
|
@ -323,7 +333,7 @@ class MonitoringPlugin(object):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
def range_dehumanize(self, range, total=None):
|
def range_dehumanize(self, range, total=None, unit=['',]):
|
||||||
newrange = ''
|
newrange = ''
|
||||||
|
|
||||||
if len(range):
|
if len(range):
|
||||||
|
@ -332,10 +342,10 @@ class MonitoringPlugin(object):
|
||||||
range = range[1:]
|
range = range[1:]
|
||||||
|
|
||||||
parts = range.split(':')
|
parts = range.split(':')
|
||||||
newrange += ('%f' % self.human_to_number(parts[0], total)).rstrip('0').rstrip('.')
|
newrange += ('%s' % self.human_to_number(parts[0], total, unit)).rstrip('0').rstrip('.')
|
||||||
|
|
||||||
if len(parts) > 1:
|
if len(parts) > 1:
|
||||||
newrange += ':' + ('%f' % self.human_to_number(parts[1], total)).rstrip('0').rstrip('.')
|
newrange += ':' + ('%s' % self.human_to_number(parts[1], total, unit)).rstrip('0').rstrip('.')
|
||||||
|
|
||||||
if range != newrange:
|
if range != newrange:
|
||||||
self.verbose(3, 'Changed range/thresold from "' + range + '" to "' + newrange + '"')
|
self.verbose(3, 'Changed range/thresold from "' + range + '" to "' + newrange + '"')
|
||||||
|
|
Loading…
Reference in a new issue