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

[collector] Only add service check fields if non-null #3487

Merged
merged 1 commit into from
Aug 22, 2017
Merged
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
13 changes: 9 additions & 4 deletions checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,12 +963,17 @@ def create_service_check(check_name, status, tags=None, timestamp=None,
"""
if check_run_id is None:
check_run_id = get_next_id('service_check')
return {
service_check = {
'id': check_run_id,
'check': check_name,
'status': status,
'host_name': hostname,
'tags': tags,
'timestamp': float(timestamp or time.time()),
'message': message
}
if hostname is not None:
service_check['host_name'] = hostname
if tags is not None:
service_check['tags'] = tags
if message is not None:
service_check["message"] = message

return service_check
22 changes: 20 additions & 2 deletions tests/core/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,24 @@ def test_service_check(self):
timestamp = time.time()

check = AgentCheck('test', {}, {'checksd_hostname':'foo'})
check.service_check(check_name, status, tags, timestamp, host_name)
# No "message"/"tags" field
check.service_check(check_name, status, timestamp=timestamp, hostname=host_name)
self.assertEquals(len(check.service_checks), 1, check.service_checks)
val = check.get_service_checks()
self.assertEquals(len(val), 1)
check_run_id = val[0].get('id', None)
self.assertNotEquals(check_run_id, None)
self.assertEquals([{
'id': check_run_id,
'check': check_name,
'status': status,
'host_name': host_name,
'timestamp': timestamp,
}], val)
self.assertEquals(len(check.service_checks), 0, check.service_checks)

# With "message" field
check.service_check(check_name, status, tags, timestamp, host_name, message='foomessage')
self.assertEquals(len(check.service_checks), 1, check.service_checks)
val = check.get_service_checks()
self.assertEquals(len(val), 1)
Expand All @@ -139,10 +156,11 @@ def test_service_check(self):
'host_name': host_name,
'tags': tags,
'timestamp': timestamp,
'message': None,
'message': 'foomessage',
}], val)
self.assertEquals(len(check.service_checks), 0, check.service_checks)


def test_no_proxy(self):
""" Starting with Agent 5.0.0, there should always be a local forwarder
running and all payloads should go through it. So we should make sure
Expand Down