Ejemplo n.º 1
0
    def main(self):

        if CONF.heartbeat:
            vtag = ''.join(CONF.tags) if CONF.tags else None

            heartbeat = Heartbeat(
                origin=CONF.origin,
                version=vtag or Version,
                timeout=CONF.timeout
            )

            LOG.debug(repr(heartbeat))

            api = ApiClient()
            api.send(heartbeat)

            return heartbeat.get_id()

        else:
            exceptionAlert = Alert(
                resource=CONF.resource,
                event=CONF.event,
                correlate=CONF.correlate,
                group=CONF.group,
                value=CONF.value,
                status=CONF.status,
                severity=CONF.severity,
                environment=CONF.environment,
                service=CONF.service,
                text=CONF.text,
                event_type=CONF.event_type,
                tags=CONF.tags,
                origin=CONF.origin,
                threshold_info='n/a',   # TODO(nsatterl): make this configurable?
                summary=CONF.summary,
                timeout=CONF.timeout,
                raw_data='n/a',  # TODO(nsatterl): make this configurable?
                more_info=CONF.more_info,
                graph_urls=CONF.graph_urls,
            )

            LOG.debug(repr(exceptionAlert))

            api = ApiClient()
            api.send(exceptionAlert)

            return exceptionAlert.get_id()
Ejemplo n.º 2
0
    def main(self):

        if CONF.heartbeat:
            heartbeat = Heartbeat(origin=CONF.origin,
                                  version=CONF.tags.get('Version', Version),
                                  timeout=CONF.timeout)

            LOG.debug(heartbeat)

            api = ApiClient()
            api.send(heartbeat)

            return heartbeat.get_id()

        else:
            exceptionAlert = Alert(
                resource=CONF.resource,
                event=CONF.event,
                correlate=CONF.correlate,
                group=CONF.group,
                value=CONF.value,
                status=CONF.status,
                severity=CONF.severity,
                environment=CONF.environment,
                service=CONF.service,
                text=CONF.text,
                event_type=CONF.event_type,
                tags=CONF.tags,
                origin=CONF.origin,
                threshold_info='n/a',  # TODO(nsatterl): make this configurable?
                summary=CONF.summary,
                timeout=CONF.timeout,
                raw_data='n/a',  # TODO(nsatterl): make this configurable?
                more_info=CONF.more_info,
                graph_urls=CONF.graph_urls,
            )

            LOG.debug(repr(exceptionAlert))

            api = ApiClient()
            api.send(exceptionAlert)

            return exceptionAlert.get_id()
Ejemplo n.º 3
0
Archivo: views.py Proyecto: ob3/alerta
            origin=data.get('origin', None),
            threshold_info=data.get('thresholdInfo', None),
            timeout=data.get('timeout', None),
            alertid=data.get('id', None),
            raw_data=data.get('rawData', None),
            more_info=data.get('moreInfo', None),
            graph_urls=data.get('graphUrls', None),
        )
    except ValueError, e:
        return jsonify(response={"status": "error", "message": str(e)})

    LOG.debug('New alert %s', newAlert)
    mq.send(newAlert)

    if newAlert:
        return jsonify(response={"status": "ok", "id": newAlert.get_id()})
    else:
        return jsonify(response={"status": "error", "message": "something went wrong"})


@app.route('/alerta/api/v2/alerts/alert/<alertid>', methods=['GET', 'PUT', 'POST', 'DELETE'])
@jsonp
def modify_alert(alertid):

    error = None

    # Return a single alert
    if request.method == 'GET':
        alert = db.get_alert(alertid=alertid)
        if alert:
            return jsonify(response={"alert": alert.get_body(), "status": "ok", "total": 1})