Skip to content

Commit

Permalink
[core] cast service_checks message to string
Browse files Browse the repository at this point in the history
As it might break the emitter if the message is not a string.
We cannot enforce a good use of service_checks in custom checks (and
also sometimes in our own checks,
see a874802)
  • Loading branch information
degemer committed May 13, 2015
1 parent a911a35 commit cd26634
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def count(self, metric, value=0, tags=None, hostname=None, device_name=None):
self.aggregator.submit_count(metric, value, tags, hostname, device_name)

def monotonic_count(self, metric, value=0, tags=None,
hostname=None, device_name=None):
hostname=None, device_name=None):
"""
Submits a raw count with optional tags, hostname and device name
based on increasing counter values. E.g. 1, 3, 5, 7 will submit
Expand Down Expand Up @@ -454,8 +454,12 @@ def service_check(self, check_name, status, tags=None, timestamp=None,
"""
if hostname is None:
hostname = self.hostname
self.service_checks.append(create_service_check(check_name, status,
tags, timestamp, hostname, check_run_id, message))
if message is not None:
message = str(message)
self.service_checks.append(
create_service_check(check_name, status, tags, timestamp,
hostname, check_run_id, message)
)

def has_events(self):
"""
Expand Down Expand Up @@ -635,7 +639,6 @@ def normalize(self, metric, prefix=None, fix_case = False):
METRIC_REPLACEMENT = re.compile(r'([^a-zA-Z0-9_.]+)|(^[^a-zA-Z]+)')
DOT_UNDERSCORE_CLEANUP = re.compile(r'_*\._*')


def convert_to_underscore_separated(self, name):
"""
Convert from CamelCase to camel_case
Expand All @@ -658,6 +661,7 @@ def read_config(instance, key, message=None, cast=None):
else:
return cast(val)


def agent_formatter(metric, value, timestamp, tags, hostname, device_name=None,
metric_type=None, interval=None):
""" Formats metrics coming from the MetricsAggregator. Will look like:
Expand All @@ -683,7 +687,7 @@ def agent_formatter(metric, value, timestamp, tags, hostname, device_name=None,


def create_service_check(check_name, status, tags=None, timestamp=None,
hostname=None, check_run_id=None, message=None):
hostname=None, check_run_id=None, message=None):
""" Create a service_check dict. See AgentCheck.service_check() for
docs on the parameters.
"""
Expand Down

0 comments on commit cd26634

Please sign in to comment.