Skip to content
This repository has been archived by the owner on Oct 5, 2022. It is now read-only.

Commit

Permalink
Parse raw_values more carefully
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-soltesz committed Jun 5, 2018
1 parent b974321 commit e38554b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nagios_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,11 @@ def parse_perf_data_fields(raw_perf_data):
"""
fields = {}
for raw_value in raw_perf_data:
name, values = raw_value.split('=')
values = values.split(';')
values = raw_value.split('=')
if len(values) <= 1:
continue
name = values[0]
values = values[1].split(';')
fields[name] = values
return fields

Expand Down
7 changes: 7 additions & 0 deletions nagios_exporter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,13 @@ def test_get_perf_data(self):

self.assertItemsEqual(actual, expected)

def test_parse_perf_data_fields_with_good_values(self):
self.assertItemsEqual(
{'/': ['2400MB', '48356', '54400', '0', '60445']},
nagios_exporter.parse_perf_data_fields(
['/=2400MB;48356;54400;0;60445']))
def test_parse_perf_data_fields_with_bad_values(self):
self.assertItemsEqual({}, nagios_exporter.parse_perf_data_fields(['-6]']))

if __name__ == "__main__": # pragma: no cover
unittest.main()

0 comments on commit e38554b

Please sign in to comment.