def test_metrics(self): test_gauge = Gauge(group='test', name='gauge', title='Test gauge', description='total time to process timed events') test_gauge.set(500) gauge = [g for g in Gauge.get_gauges() if g.title == 'Test gauge'][0] self.assertGreaterEqual(gauge.value, 500) test_timer = Timer(group='test', name='timer', title='Test timer', description='total time to process timed events') recv_started = test_timer.start_timer() time.sleep(1) test_timer.stop_timer(recv_started) timer = [t for t in Timer.get_timers() if t.title == 'Test timer'][0] self.assertGreaterEqual(timer.count, 1) self.assertGreaterEqual(timer.total_time, 999)
for alert in alerts: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url.replace('alerts', 'alert'), alert.id) found += 1 severity_count[body['severity']] += 1 status_count[body['status']] += 1 if not last_time: last_time = body['lastReceiveTime'] elif body['lastReceiveTime'] > last_time: last_time = body['lastReceiveTime'] alert_response.append(body) gets_timer.stop_timer(gets_started) return jsonify( status="ok", total=found, more=total > limit, alerts=alert_response, severityCounts=severity_count, statusCounts=status_count, lastTime=last_time, autoRefresh=Switch.get('auto-refresh-allow').is_on(), ) else: gets_timer.stop_timer(gets_started) return jsonify( status="ok", message="not found",
@app.route('/webhooks/cloudwatch', methods=['OPTIONS', 'POST']) @crossdomain(origin='*', headers=['Origin', 'X-Requested-With', 'Content-Type', 'Accept']) @jsonp def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError, e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, {'Location': '%s/%s' % (request.base_url, alert.id)} else: return jsonify(status="error", message="insert or update of cloudwatch alarm failed"), 500
@crossdomain(origin='*', headers=['Origin', 'X-Requested-With', 'Content-Type', 'Accept']) @jsonp def cloudwatch(): hook_started = webhook_timer.start_timer() try: incomingAlert = parse_notification(request.data) except ValueError, e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 400 try: alert = process_alert(incomingAlert) except RejectException as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 403 except Exception as e: webhook_timer.stop_timer(hook_started) return jsonify(status="error", message=str(e)), 500 webhook_timer.stop_timer(hook_started) if alert: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url, alert.id) return jsonify(status="ok", id=alert.id, alert=body), 201, { 'Location': '%s/%s' % (request.base_url, alert.id) } else: return jsonify(
for alert in alerts: body = alert.get_body() body['href'] = "%s/%s" % (request.base_url.replace( 'alerts', 'alert'), alert.id) found += 1 severity_count[body['severity']] += 1 status_count[body['status']] += 1 if not last_time: last_time = body['lastReceiveTime'] elif body['lastReceiveTime'] > last_time: last_time = body['lastReceiveTime'] alert_response.append(body) gets_timer.stop_timer(gets_started) return jsonify( status="ok", total=found, more=total > limit, alerts=alert_response, severityCounts=severity_count, statusCounts=status_count, lastTime=last_time, autoRefresh=Switch.get('auto-refresh-allow').is_on(), ) else: gets_timer.stop_timer(gets_started) return jsonify(status="ok", message="not found", total=0,