import time import datetime from flask import request, Response, url_for, jsonify, render_template from alerta.api.v2 import app, db, mq from alerta.api.v2.switch import Switch, SwitchState from alerta import get_version from alerta.common import log as logging LOG = logging.getLogger(__name__) switches = [ Switch('auto-refresh-allow', 'Allow consoles to auto-refresh alerts', SwitchState.ON), # Switch('console-api-allow', 'Allow consoles to use the alert API', SwitchState.ON), # TODO(nsatterl) # Switch('sender-api-allow', 'Allow alerts to be submitted via the API', SwitchState.ON), # TODO(nsatterl) ] @app.route('/alerta/management') def management(): endpoints = [ url_for('manifest'), url_for('properties'), url_for('switchboard'), url_for('health_check'), url_for('status') ]
import json import stomp from stomp import exception, ConnectionListener from alerta.common import log as logging from alerta.common import config from alerta.common.utils import DateEncoder LOG = logging.getLogger('stomp.py') CONF = config.CONF _RECONNECT_SLEEP_INITIAL = 2 # seconds _RECONNECT_SLEEP_INCREASE = 2 _RECONNECT_SLEEP_MAX = 300 # seconds _RECONNECT_ATTEMPTS_MAX = 20 class Messaging(object): mq_opts = { 'stomp_host': 'localhost', 'stomp_port': 61613, 'inbound_queue': '/exchange/alerts', 'outbound_queue': '/queue/logger', 'outbound_topic': '/topic/notify', 'rabbit_host': 'localhost', 'rabbit_port': 5672, 'rabbit_use_ssl': False,
import sys import json import requests import requests.exceptions from alerta.common import config from alerta.common import log as logging LOG = logging.getLogger(__name__) CONF = config.CONF class PagerDutyClient(object): def __init__(self): if not CONF.pagerduty_subdomain: LOG.error('Must specify PagerDuty subdomain') sys.exit(1) self.REST_API = 'https://%s.pagerduty.com/api/v1' % CONF.pagerduty_subdomain self.INCIDENT_API = 'https://events.pagerduty.com/generic/2010-04-15/create_event.json' self.services = dict() self.get_services() def get_services(self): response = self._query('/services') services = response['services'] self.services = dict([(s['name'], { 'id': s['id'],
import json # If ../nova/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) if os.path.exists(os.path.join(possible_topdir, 'alerta', '__init__.py')): sys.path.insert(0, possible_topdir) from alerta.common import log as logging from alerta.common import config from alerta.server.database import Mongo from alerta.alert import Alert, severity LOG = logging.getLogger('alerta') LOG = logging.getLogger(__name__) CONF = config.CONF print CONF config.parse_args(['--use-stderr', '--debug']) logging.setup('alerta') db = Mongo() #print db.save_alert({''}) alert3 = Alert('router55', 'Node_Down', severity=severity.INDETERMINATE, value='FAILED', timeout=600, environment=['PROD'], receive_time="2013-02-23T09:18:05.303Z", last_receive_time="2013-02-23T09:18:05.303Z", service=['Network', 'Common'], tags=['london', 'location:london', 'dc:location=london'], text="Node is not responding via ping.", origin="test3", correlate=['Node_Up', 'Node_Down'], event_type='myAlert', trend_indication='moreSevere')
import os import sys from logging import getLogger, basicConfig # If ../nova/__init__.py exists, add ../ to Python search path, so that # it will override what happens to be installed in /usr/(local/)lib/python... possible_topdir = os.path.normpath(os.path.join(os.path.abspath(sys.argv[0]), os.pardir, os.pardir)) if os.path.exists(os.path.join(possible_topdir, 'alerta', '__init__.py')): sys.path.insert(0, possible_topdir) from alerta.common import log as logging from alerta.common import config from alerta.common.daemon import Daemon __program__ = 'test-daemon' if __name__ == '__main__': config.parse_args(sys.argv, version='1.1') logging.setup('alert-syslog') LOG = logging.getLogger('alert-syslog') daemon = Daemon(__program__, pidfile='/tmp/pidfile') daemon.start() daemon.stop()
import json import stomp from stomp import exception, ConnectionListener from alerta.common import log as logging from alerta.common import config from alerta.common.utils import DateEncoder LOG = logging.getLogger('stomp.py') CONF = config.CONF _RECONNECT_SLEEP_INITIAL = 2 # seconds _RECONNECT_SLEEP_INCREASE = 2 _RECONNECT_SLEEP_MAX = 300 # seconds _RECONNECT_ATTEMPTS_MAX = 20 class Messaging(object): mq_opts = { 'stomp_host': 'localhost', 'stomp_port': 61613, 'inbound_queue': '/exchange/alerts', 'outbound_queue': '/queue/logger', 'outbound_topic': '/topic/notify', 'rabbit_host': 'localhost', 'rabbit_port': 5672, 'rabbit_use_ssl': False, 'rabbit_userid': 'guest', 'rabbit_password': '******', 'rabbit_virtual_host': '/',
import yaml from alerta.common import log as logging from alerta.common import config from alerta.common.alert import Alert from alerta.common.heartbeat import Heartbeat from alerta.common import severity_code from alerta.common.api import ApiClient from alerta.common.daemon import Daemon from alerta.common.transform import Transformers from alerta.common.dedup import DeDup from alerta.common.graphite import Carbon __version__ = '3.2.0' LOG = logging.getLogger('alerta.pinger') CONF = config.CONF _PING_ALERTS = [ 'PingFailed', 'PingSlow', 'PingOK', 'PingError', ] PING_OK = 0 # all ping replies received within timeout PING_FAILED = 1 # some or all ping replies not received or did not respond within timeout PING_ERROR = 2 # unspecified error with ping # Initialise Rules
import yaml from alerta.common import log as logging from alerta.common import config from alerta.common.alert import Alert from alerta.common.heartbeat import Heartbeat from alerta.common import severity_code from alerta.common.api import ApiClient from alerta.common.daemon import Daemon from alerta.common.transform import Transformers from alerta.common.dedup import DeDup from alerta.common.graphite import Carbon __version__ = '3.2.0' LOG = logging.getLogger('alerta.pinger') CONF = config.CONF _PING_ALERTS = [ 'PingFailed', 'PingSlow', 'PingOK', 'PingError', ] PING_OK = 0 # all ping replies received within timeout PING_FAILED = 1 # some or all ping replies not received or did not respond within timeout PING_ERROR = 2 # unspecified error with ping