Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enh: Also use the check command_name in the serie name #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions module/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ def init(self):
)

@staticmethod
def get_check_result_perfdata_points(perf_data, timestamp, tags={}):
def get_check_result_perfdata_points(command_name, perf_data,
timestamp, tags={}):
"""
:param perf_data: Perf data of the brok
:param timestamp: Timestamp of the check result
Expand All @@ -102,7 +103,7 @@ def get_check_result_perfdata_points(perf_data, timestamp, tags={}):
fields[field_name] = value

point = {
"name": 'metric_%s' % e.name,
"name": 'metric_%s_%s' % (command_name, e.name),
"timestamp": timestamp,
"fields": fields,
"tags": tags,
Expand Down Expand Up @@ -151,6 +152,7 @@ def manage_service_check_result_brok(self, b):

post_data.extend(
self.get_check_result_perfdata_points(
b.data['check_command'].command,
b.data['perf_data'],
b.data['last_chk'],
tags=tags
Expand Down Expand Up @@ -180,6 +182,7 @@ def manage_host_check_result_brok(self, b):

post_data.extend(
self.get_check_result_perfdata_points(
b.data['check_command'].command,
b.data['perf_data'],
b.data['last_chk'],
tags=tags
Expand Down Expand Up @@ -211,6 +214,7 @@ def manage_unknown_host_check_result_brok(self, b):

post_data.extend(
self.get_check_result_perfdata_points(
b.data['check_command'].command,
b.data['perf_data'],
b.data['time_stamp'],
tags=tags
Expand All @@ -236,6 +240,7 @@ def manage_unknown_service_check_result_brok(self, b):

post_data.extend(
self.get_check_result_perfdata_points(
b.data['check_command'].command,
b.data['perf_data'],
b.data['time_stamp'],
tags=tags
Expand Down
34 changes: 24 additions & 10 deletions test/test_InfluxdbBroker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@
)


class CheckCommand(object):
def __init__(self, command):
self.command = command

def __getstate__(self):
return {'command': self.command}

def __setstate__(self, data):
self.command = data['command']


class TestInfluxdbBroker(unittest.TestCase):

def setUp(self):
Expand All @@ -34,19 +45,20 @@ def test_get_unknown_check_result_perfdata_points(self):
expected = [
{'timestamp': 1403618279,
'tags': {'host_name': 'testhello'},
'name': 'metric_ramused',
'name': 'metric_memory_check_ramused',
'fields': {'max': 1982, 'value': 1009, 'min': 0}},
{'timestamp': 1403618279,
'tags': {'host_name': 'testhello'},
'name': 'metric_memused',
'name': 'metric_memory_check_memused',
'fields': {'max': 5810, 'warning': 2973,
'critical': 3964, 'value': 1550, 'min': 0}},
{'timestamp': 1403618279,
'tags': {'host_name': 'testhello'},
'name': 'metric_swapused',
'name': 'metric_memory_check_swapused',
'fields': {'max': 3827, 'value': 540, 'min': 0}}]

result = InfluxdbBroker.get_check_result_perfdata_points(
'memory_check',
data['perf_data'],
data['time_stamp'],
tags
Expand All @@ -61,21 +73,22 @@ def test_get_check_result_perfdata_points(self):
}

expected = [
{'timestamp': 1403618279, 'name': 'metric_ramused',
{'timestamp': 1403618279, 'name': 'metric_memory_check_ramused',
'tags': {'host_name': 'testname'},
'fields': {'max': 1982, 'value': 1009, 'min': 0}},

{'timestamp': 1403618279, 'name': 'metric_memused',
{'timestamp': 1403618279, 'name': 'metric_memory_check_memused',
'tags': {'host_name': 'testname'},
'fields': {'max': 5810, 'warning': 2973,
'critical': 3964, 'value': 1550, 'min': 0}},

{'timestamp': 1403618279, 'name': 'metric_swapused',
{'timestamp': 1403618279, 'name': 'metric_memory_check_swapused',
'tags': {'host_name': 'testname'},
'fields': {'max': 3827, 'value': 540, 'min': 0}}
]

result = InfluxdbBroker.get_check_result_perfdata_points(
'memory_check',
data['perf_data'],
data['last_chk'],
tags
Expand Down Expand Up @@ -265,7 +278,7 @@ def test_manage_unknown_host_check_result_brok(self):
data = {
'time_stamp': 1234567890, 'return_code': '2',
'host_name': 'test_host_0', 'output': 'Bob is not happy',
'perf_data': 'rtt=9999'
'perf_data': 'rtt=9999', 'check_command': CheckCommand('fake_check'),
}
brok = Brok('unknown_host_check_result', data)
brok.prepare()
Expand All @@ -278,7 +291,7 @@ def test_manage_unknown_host_check_result_brok(self):
broker.buffer[0],
{'timestamp': 1234567890,
'tags': {'host_name': 'test_host_0'},
'name': 'metric_rtt',
'name': 'metric_fake_check_rtt',
'fields': {'value': 9999}}
)

Expand All @@ -288,7 +301,8 @@ def test_manage_unknown_service_check_result_brok(self):
'host_name': 'test_host_0', 'time_stamp': 1234567890,
'service_description': 'test_ok_0', 'return_code': '1',
'output': 'Bobby is not happy',
'perf_data': 'rtt=9999;5;10;0;10000'
'perf_data': 'rtt=9999;5;10;0;10000',
'check_command': CheckCommand('fake_check'),
}
brok = Brok('unknown_service_check_result', data)
brok.prepare()
Expand All @@ -301,7 +315,7 @@ def test_manage_unknown_service_check_result_brok(self):
{'timestamp': 1234567890,
'tags': {'service_description': 'test_ok_0',
'host_name': 'test_host_0'},
'name': 'metric_rtt', 'fields': {'max': 10000, 'warning': 5,
'name': 'metric_fake_check_rtt', 'fields': {'max': 10000, 'warning': 5,
'critical': 10, 'value': 9999,
'min': 0}}
)