Skip to content

Commit

Permalink
boundary - hipchat - wildcard metric namespaces
Browse files Browse the repository at this point in the history
Allowing for regex matching wildcard metric namespaces in the hipchat alerter if
the metric name is not declared as an absolute value
internal_ref #878
Modified:
src/boundary/alerters.py
src/settings.py.example
  • Loading branch information
earthgecko committed Dec 3, 2015
1 parent 7930e49 commit 5725e39
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/boundary/alerters.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,28 @@ def alert_hipchat(datapoint, metric_name, expiration_time, metric_trigger, algor
sender = settings.BOUNDARY_HIPCHAT_OPTS['sender']
import hipchat
hipster = hipchat.HipChat(token=settings.BOUNDARY_HIPCHAT_OPTS['auth_token'])
rooms = settings.BOUNDARY_HIPCHAT_OPTS['rooms'][metric_name]

# Allow for absolute path metric namespaces but also allow for and match
# match wildcard namepaces if there is not an absolute path metric namespace
rooms = 'unknown'
notify_rooms = []
matched_rooms = []
try:
rooms = settings.BOUNDARY_HIPCHAT_OPTS['rooms'][metric_name]
notify_rooms.append(rooms)
except:
for room in settings.BOUNDARY_HIPCHAT_OPTS['rooms']:
print(room)
CHECK_MATCH_PATTERN = room
check_match_pattern = re.compile(CHECK_MATCH_PATTERN)
pattern_match = check_match_pattern.match(metric_name)
if pattern_match:
matched_rooms.append(room)

if matched_rooms != []:
for i_metric_name in matched_rooms:
rooms = settings.BOUNDARY_HIPCHAT_OPTS['rooms'][i_metric_name]
notify_rooms.append(rooms)

alert_algo = str(algorithm)
alert_context = alert_algo.upper()
Expand All @@ -138,8 +159,9 @@ def alert_hipchat(datapoint, metric_name, expiration_time, metric_trigger, algor

embed_graph = "<a href='" + link + "'><img height='308' src='" + link + "'>" + metric_name + "</a>"

for room in rooms:
hipster.method('rooms/message', method='POST', parameters={'room_id': room, 'from': 'skyline', 'color': settings.BOUNDARY_HIPCHAT_OPTS['color'], 'message': '%s - analyzer - %s - Anomalous metric: %s (value: %s) at %s hours %s' % (sender, algorithm, metric_name, datapoint, graphite_previous_hours, embed_graph)})
for rooms in notify_rooms:
for room in rooms:
hipster.method('rooms/message', method='POST', parameters={'room_id': room, 'from': 'skyline', 'color': settings.BOUNDARY_HIPCHAT_OPTS['color'], 'message': '%s - boundary - %s - Anomalous metric: %s (value: %s) at %s hours %s' % (sender, algorithm, metric_name, datapoint, graphite_previous_hours, embed_graph)})


def alert_syslog(datapoint, metric_name, expiration_time, metric_trigger, algorithm):
Expand Down
1 change: 1 addition & 0 deletions src/settings.py.example
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ BOUNDARY_HIPCHAT_OPTS = {
'sender': 'hostname or identifier',
# list of hipchat room_ids to notify about each anomaly
# (similar to SMTP_OPTS['recipients'])
# Wildcard metric namespacing is allowed
'rooms': {
'nometrics': (12345,),
},
Expand Down

0 comments on commit 5725e39

Please sign in to comment.