Utilities¶
Various utilities functions.
- monitoring.nagios.utilities.ip_rm_leading_zero(ip)¶
Remove leading zeros in IP address.
String like ‘010.025.036.002’ will return ‘10.25.36.2’.
Note
TODO: Write a nice example ;-)
Parameters: ip (string) – IP address. Returns: IP address with leading zeros removed as string.
- monitoring.nagios.utilities.humanize_bytes(byte, precision=2)¶
Return a humanized string representation of a number of bytes.
Example:
>>> print humanize_bytes(1024) '1 kB'
Parameters: - byte (Integer.) – Byte number.
- precision (Integer.) – Specify float precision after conversion (default 2).
Returns: Humanized string representation of a number of bytes.
- monitoring.nagios.utilities.percent_used(used, total, decimal=2)¶
Return percent used by giving total and used value.
Parameters: - used (Integer) – Used value.
- total (Integer) – Total value.
Returns: Float for percent used.
Return type: Float
- monitoring.nagios.utilities.find_key_from_value(dic, val)¶
Return the key of dictionary dic given the value
Parameters: - dic (dict) – dict to search in.
- val – the value you need the key.
- monitoring.nagios.utilities.humanize_duration(time_delta, show=None, sep=' ')¶
Humanize a timedelta object.
Parameters: - time_delta – the timedelta object to humanize.
- sep – specify a separator for days, hours, minutes and seconds in the final string.
Returns: a dict with keys: days, hours, minutes, minutes and seconds.
Return type: dict
Example:
>>> age = humanize_duration(timedelta(days=1, hours=2, minutes=34, seconds=22), sep=", ") >>> age {'timedelta': datetime.timedelta(1, 9262), 'seconds': 22, 'as_string': '1 days, 2 hours, 34 minutes, 22 seconds', 'days': 1, 'hours': 2, 'minutes': 34} >>> age_filter = humanize_duration(timedelta(days=1, hours=2, minutes=34, seconds=22), sep=", ", show=['days', 'hours']) >>> age_filter['as_string'] '1 days, 2 hours'