Skip to content

Commit

Permalink
handle negative values in metrics from nagios-style plugins
Browse files Browse the repository at this point in the history
(#14)
  • Loading branch information
freddrake committed Apr 24, 2015
1 parent b08091b commit adade4b
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/zc/cimaa/nagiosperf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,28 @@
>>> ppp("| 'ha ha ha'=3has")
('\n', [{'name': "'ha ha ha'", 'units': 'has', 'value': 3.0}])
>>> ppp("| 'ha ha ha'=-3has")
('\n', [{'name': "'ha ha ha'", 'units': 'has', 'value': -3.0}])
>>> ppp("| 'ha ha ha'=+3has")
('\n', [{'name': "'ha ha ha'", 'units': 'has', 'value': 3.0}])
>>> ppp(
... "he he he; | m=2643MB;-5948;+5958;-6000;6000")
('he he he; \n',
[{'name': 'm', 'units': 'MB', 'value': 2643.0}])
See: https://nagios-plugins.org/doc/guidelines.html#AEN200
"""

import re

perf_parse = re.compile(
r"([^=' \t]+|'[^=']+')" # label
r"=" # =
r"(\d+(\.\d*)?|\.\d+)" # value
r"([^; \t]*)" # Units
r"(;(\d+(\.\d*)?|\.\d+)){0,4}" # warn, crit, min, max
r"([^=' \t]+|'[^=']+')" # label
r"=" # =
r"([-+]?\d+(\.\d*)?|[-+]?\.\d+)" # value
r"([^; \t]*)" # Units
r"(;([-+]?\d+(\.\d*)?|[-+]?\.\d+)){0,4}" # warn, crit, min, max
).findall

def parse_output(text):
Expand Down

0 comments on commit adade4b

Please sign in to comment.