def search_alerts(): query_time = datetime.utcnow() query = qb.from_params(request.args, customers=g.customers, query_time=query_time) show_raw_data = request.args.get( 'show-raw-data', default=False, type=lambda x: x.lower() in ['true', 't', '1', 'yes', 'y', 'on']) show_history = request.args.get( 'show-history', default=False, type=lambda x: x.lower() in ['true', 't', '1', 'yes', 'y', 'on']) severity_count = Alert.get_counts_by_severity(query) status_count = Alert.get_counts_by_status(query) total = sum(severity_count.values()) paging = Page.from_params(request.args, total) alerts = Alert.find_all(query, paging.page, paging.page_size) for alert in alerts: if not show_raw_data: alert.raw_data = None if not show_history: alert.history = [] if alerts: return jsonify( status='ok', page=paging.page, pageSize=paging.page_size, pages=paging.pages, more=paging.has_more, alerts=[alert.serialize for alert in alerts], total=total, statusCounts=status_count, severityCounts=severity_count, lastTime=max([alert.last_receive_time for alert in alerts]), autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on) else: return jsonify( status='ok', message='not found', page=paging.page, pageSize=paging.page_size, pages=0, more=False, alerts=[], total=0, severityCounts=severity_count, statusCounts=status_count, lastTime=query_time, autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on)
def get_top10_standing(): query = qb.from_params(request.args, customers=g.customers) top10 = Alert.get_top10_standing(query) if top10: return jsonify( status='ok', top10=top10, total=len(top10), autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on) else: return jsonify( status='ok', message='not found', top10=[], total=0, autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on)
def switchboard(): if request.method == 'POST': for switch in Switch.find_all(): try: value = request.form[switch.name] switch.set_state(value) except KeyError: pass return render_template('management/switchboard.html', switches=switches) else: switch = request.args.get('switch', None) if switch: return render_template('management/switchboard.html', switches=[Switch.find_by_name(switch)]) else: return render_template('management/switchboard.html', switches=switches)
def get_counts(): query = qb.from_params(request.args, customers=g.customers) severity_count = Alert.get_counts_by_severity(query) status_count = Alert.get_counts_by_status(query) return jsonify(status='ok', total=sum(severity_count.values()), severityCounts=severity_count, statusCounts=status_count, autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on)
def status(): now = int(time.time() * 1000) total_alert_gauge.set(Alert.get_count()) metrics = Gauge.find_all() metrics.extend(Counter.find_all()) metrics.extend(Timer.find_all()) metrics.extend(Switch.find_all()) return jsonify(application="alerta", version=__version__, time=now, uptime=int(now - started), metrics=[metric.serialize() for metric in metrics])
def search_alerts(): query_time = datetime.utcnow() query = qb.from_params(request.args, customers=g.customers, query_time=query_time) severity_count = Alert.get_counts_by_severity(query) status_count = Alert.get_counts_by_status(query) total = sum(severity_count.values()) paging = Page.from_params(request.args, total) alerts = Alert.find_all(query, paging.page, paging.page_size) if alerts: return jsonify( status='ok', page=paging.page, pageSize=paging.page_size, pages=paging.pages, more=paging.has_more, alerts=[alert.serialize for alert in alerts], total=total, statusCounts=status_count, severityCounts=severity_count, lastTime=max([alert.last_receive_time for alert in alerts]), autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on) else: return jsonify( status='ok', message='not found', page=paging.page, pageSize=paging.page_size, pages=0, more=False, alerts=[], total=0, severityCounts=severity_count, statusCounts=status_count, lastTime=query_time, autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on)
def search_alerts(): query_time = datetime.utcnow() query = qb.from_params(request.args, query_time) severity_count = Alert.get_counts_by_severity(query) status_count = Alert.get_counts_by_status(query) total = sum(severity_count.values()) paging = Page.from_params(request.args, total) alerts = Alert.find_all(query, paging.page, paging.page_size) if alerts: return jsonify( status="ok", page=paging.page, pageSize=paging.page_size, pages=paging.pages, more=paging.has_more, alerts=[alert.serialize for alert in alerts], total=total, statusCounts=status_count, severityCounts=severity_count, lastTime=max([alert.last_receive_time for alert in alerts]), autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on ) else: return jsonify( status="ok", message="not found", page=paging.page, pageSize=paging.page_size, pages=0, more=False, alerts=[], total=0, severityCounts=severity_count, statusCounts=status_count, lastTime=query_time, autoRefresh=Switch.find_by_name('auto-refresh-allow').is_on )
except Exception: from alerta import dev as build from alerta.app import db from alerta.auth.decorators import permission from alerta.exceptions import ApiError from alerta.models.alert import Alert from alerta.models.heartbeat import Heartbeat from alerta.models.metrics import Gauge, Counter, Timer from alerta.models.switch import Switch, SwitchState from alerta.version import __version__ from . import mgmt switches = [ Switch('auto-refresh-allow', 'Alerta console auto-refresh', 'Allow consoles to auto-refresh alerts', SwitchState.ON), Switch('sender-api-allow', 'API alert submission', 'Allow alerts to be submitted via the API', SwitchState.ON) ] total_alert_gauge = Gauge('alerts', 'total', 'Total alerts', 'Total number of alerts in the database') started = time.time() * 1000 @mgmt.route('/management', methods=['OPTIONS', 'GET']) @cross_origin() def management(): endpoints = [ url_for('mgmt.manifest'),