Skip to content

Commit

Permalink
[elasticsearch] add tags to events
Browse files Browse the repository at this point in the history
It just adds the tags given in the YAML config to the ES events when the
cluster status changes.
  • Loading branch information
Garner Fox McCloud authored and LeoCavaille committed May 6, 2015
1 parent 3168a57 commit d8469af
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions checks.d/elastic.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,12 +439,12 @@ def _process_health_data(self, data, config):
if self.cluster_status.get(config.url) is None:
self.cluster_status[config.url] = data['status']
if data['status'] in ["yellow", "red"]:
event = self._create_event(data['status'])
event = self._create_event(data['status'], tags=config.tags)
self.event(event)

if data['status'] != self.cluster_status.get(config.url):
self.cluster_status[config.url] = data['status']
event = self._create_event(data['status'])
event = self._create_event(data['status'], tags=config.tags)
self.event(event)

for metric, desc in self.CLUSTER_HEALTH_METRICS.iteritems():
Expand Down Expand Up @@ -480,7 +480,7 @@ def _process_health_data(self, data, config):
def _metric_not_found(self, metric, path):
self.log.debug("Metric not found: %s -> %s", path, metric)

def _create_event(self, status):
def _create_event(self, status, tags=None):
hostname = self.hostname.decode('utf-8')
if status == "red":
alert_type = "error"
Expand All @@ -497,13 +497,14 @@ def _create_event(self, status):

msg = "ElasticSearch: %s just reported as %s" % (hostname, status)

return {
return {
'timestamp': int(time.time()),
'event_type': self.SOURCE_TYPE_NAME,
'event_type': 'elasticsearch',
'host': hostname,
'msg_text': msg,
'msg_title': msg_title,
'alert_type': alert_type,
'source_type_name': self.SOURCE_TYPE_NAME,
'event_object': hostname
'source_type_name': "elasticsearch",
'event_object': hostname,
'tags': tags
}

0 comments on commit d8469af

Please sign in to comment.