Skip to content

Commit ca0e963

Browse files
author
Aakash Sabharwal
committed
use message.html and not message.txt
1 parent c5c9334 commit ca0e963

File tree

3 files changed

+20
-41
lines changed

3 files changed

+20
-41
lines changed

graphite_beacon/alerts.py

+17-39
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def __init__(self, reactor, **options):
8989

9090
LOGGER.info("Alert '%s': has inited", self)
9191

92+
93+
9294
def __hash__(self):
9395
"""Provide alert's hash."""
9496
return hash(self.name) ^ hash(self.source)
@@ -131,10 +133,6 @@ def configure(self, name=None, rules=None, query=None, **options):
131133
'request_timeout', self.reactor.options['request_timeout'])
132134
self.connect_timeout = options.get(
133135
'connect_timeout', self.reactor.options['connect_timeout'])
134-
self.url_retries = options.get(
135-
'url_retries', self.reactor.options['url_retries'])
136-
self.url_retry_delay = parse_interval(options.get(
137-
'url_retry_delay', self.reactor.options['url_retry_delay'])) / 1000
138136

139137
self.history_size = options.get('history_size', self.reactor.options['history_size'])
140138
self.history_size = parse_interval(self.history_size)
@@ -171,29 +169,22 @@ def stop(self):
171169
self.callback.stop()
172170
return self
173171

174-
def check(self, records, final=True):
175-
"""Check current value. Returns true if check succeeded."""
176-
rvalue = True
172+
def check(self, records):
173+
"""Check current value."""
177174
for value, target in records:
178175
LOGGER.info("%s [%s]: %s", self.name, target, value)
179176
if value is None:
180-
if final:
181-
self.notify(self.no_data, value, target)
182-
rvalue = False
177+
self.notify(self.no_data, value, target)
183178
continue
184179
for rule in self.rules:
185180
if self.evaluate_rule(rule, value, target):
186-
if final:
187-
self.notify(rule['level'], value, target, rule=rule)
188-
rvalue = False
181+
self.notify(rule['level'], value, target, rule=rule)
189182
break
190183
else:
191184
self.notify('normal', value, target, rule=rule)
192185

193186
self.history[target].append(value)
194187

195-
return rvalue
196-
197188
def evaluate_rule(self, rule, value, target):
198189
"""Calculate the value."""
199190
def evaluate(expr):
@@ -330,29 +321,16 @@ def load(self):
330321
self.notify('warning', 'Process takes too much time', target='waiting', ntype='common')
331322
else:
332323
self.waiting = True
333-
retries_remaining = self.url_retries
334-
while True:
335-
final = retries_remaining <= 0
336-
retries_remaining -= 1
337-
try:
338-
response = yield self.client.fetch(
339-
self.query, method=self.options.get('method', 'GET'),
340-
request_timeout=self.request_timeout,
341-
connect_timeout=self.connect_timeout,
342-
validate_cert=self.options.get('validate_cert', True))
343-
if self.check([(self.get_data(response), self.query)], final):
344-
self.notify('normal', 'Metrics are loaded', target='loading', ntype='common')
345-
break
346-
elif final:
347-
break
348-
elif self.url_retry_delay > 0:
349-
yield gen.sleep(self.url_retry_delay)
350-
351-
except Exception as e:
352-
if final:
353-
self.notify('critical', str(e), target='loading', ntype='common')
354-
break
355-
elif self.url_retry_delay > 0:
356-
yield gen.sleep(self.url_retry_delay)
324+
try:
325+
response = yield self.client.fetch(
326+
self.query, method=self.options.get('method', 'GET'),
327+
request_timeout=self.request_timeout,
328+
connect_timeout=self.connect_timeout,
329+
validate_cert=self.options.get('validate_cert', True))
330+
self.check([(self.get_data(response), self.query)])
331+
self.notify('normal', 'Metrics are loaded', target='loading', ntype='common')
332+
333+
except Exception as e:
334+
self.notify('critical', str(e), target='loading', ntype='common')
357335

358336
self.waiting = False

graphite_beacon/templates/graphite/message.html

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
{% end %}
5151
{% end %}
5252

53+
View the graphtestvar 1: {{ alert.options.get('testvar') }}
54+
View the graphtestvar 2: {{ alert.testvar }}
55+
5356
</td>
5457
</tr>
5558
<tr>

graphite_beacon/templates/graphite/message.txt

-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ History: {{ [ alert.convert(v) for v in alert.history[target][:100] ] }} {% end
2020

2121
View the graph: {{ alert.get_graph_url(alert.query) }}
2222

23-
View the graph: {{ alert.testvar }}
24-
2523
--
2624

2725
You can configure alerts for notifications in your configuration file.

0 commit comments

Comments
 (0)