Module: check_mk
Branch: master
Commit: d19d7c20831d9bfd799de10dd371321b8a183ec8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d19d7c20831d9b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 12 14:04:23 2011 +0100
Byte formating function can handle negative byte values now
---
modules/check_mk_base.py | 16 +++++++++++-----
1 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/modules/check_mk_base.py b/modules/check_mk_base.py
index 7a296a4..cb15778 100755
--- a/modules/check_mk_base.py
+++ b/modules/check_mk_base.py
@@ -1033,15 +1033,21 @@ def savefloat(f):
# Takes bytes as integer and returns a string which represents the bytes in a
# more human readable form scaled to GB/MB/KB
-def get_bytes_human_readable(b, base=1024.0):
+def get_bytes_human_readable(b, base=1024):
+ # Handle negative bytes correctly
+ prefix = ''
+ if b < 0:
+ prefix = '-'
+ b *= -1
+
if b > base * base * base:
- return '%.2fGB' % (b / base / base / base)
+ return '%s%.2fGB' % (prefix, b / base / base / base)
if b > base * base:
- return '%.2fMB' % (b / base / base)
+ return '%s%.2fMB' % (prefix, b / base / base)
elif b > base:
- return '%.2fKB' % (b / base)
+ return '%s%.2fKB' % (prefix, b / base)
else:
- return '%.2fB' % b
+ return '%s%.2fB' % (prefix, b)
def get_nic_speed_human_readable(speed):
try: