Exemplo n.º 1
0
 def __init__(self, target_date):
     self.start_time = datetime.combine(target_date, time(hour=3))
     self.end_time = self.start_time + timedelta(days=1)
     self.db_session = get_db_session()
     self.log = get_log('AlertEvaluator')
     self.schedule_adherence_api = cfg.get('Evaluator',
                                           'schedule_adherence_api')
     self.api_key = cfg.get('Evaluator', 'api_key')
Exemplo n.º 2
0
 def __init__(self):
     # Load the length of time (seconds) to wait between scans
     self.scan_frequency_sec = cfg.getint("Archiver", "scan_frequency_sec")
     # How often (every n scans) should we clear the known-alerts set
     self.cull_frequency = cfg.getint("Archiver", "cull_frequency")
     # How many cycles until the next cull?
     self.next_cull = self.cull_frequency
     # Record each version of published alerts we've seen,
     # as a set of (alert_id, last_modified_dt)
     self.known_id_lastmodified_pairs = set()
     self.alerts_params = {
         'api_key': cfg.get("API", "v2_api_key"),
         'include_access_alerts': cfg.get("Archiver", "include_access_alerts"),
         'include_service_alerts': cfg.get("Archiver", "include_service_alerts"),
         'format': 'json'
     }
     self.alerts_url = cfg.get("API", "alerts_url")
     self.db_session = get_db_session()
     self.log = get_log('archiver')
Exemplo n.º 3
0
"""

import os
import time
import requests

from mbtaalerts.logging import get_log
from mbtaalerts.config import config as cfg
from mbtaalerts.database import database as db
from sqlalchemy import MetaData, Table
from sqlalchemy.exc import DBAPIError
from datetime import datetime, timezone
from mbtaalerts.database.models \
    import Alert, AlertAffectedService, AlertEffectPeriod

LOG = get_log('archiver')


def buildAlertEntry(alert):
    """Build a database insertion from alert data"""
    stamp_created = datetime.fromtimestamp(int(alert['created_dt']),
                                           timezone.utc)
    stamp_modified = datetime.fromtimestamp(int(alert['last_modified_dt']),
                                            timezone.utc)
    return Alert(alert_id=str(alert['alert_id']),
                 effect_name=str(alert['effect_name']),
                 effect=str(alert['effect']),
                 cause=str(alert['cause']),
                 header_text=str(alert['header_text']),
                 short_header_text=str(alert['short_header_text']),
                 severity=str(alert['severity']),
Exemplo n.º 4
0
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker

from mbtaalerts.config import config as cfg
from mbtaalerts.logging import get_log

LOG = get_log('database')
ENGINE = None


def setup_engine(url):
    global ENGINE
    ENGINE = create_engine(url)
    LOG.info('Creating new db engine: %s', ENGINE)


def reset_engine():
    global ENGINE
    ENGINE = None
    LOG.info('Resetting db engine: %s', ENGINE)


def get_db_session():
    if ENGINE is None:
        setup_engine(cfg.get('Database', 'database_url'))
    session = sessionmaker(autocommit=False, autoflush=False, bind=ENGINE)
    return scoped_session(session)


def init_db():
    from mbtaalerts.database.models import Base
Exemplo n.º 5
0
"""
This module contains a REST API, which makes data available
to the frontend dashboard contained in ../webapi
"""

from datetime import time, date

from flask import Flask, jsonify, request
from webargs import fields
from webargs.flaskparser import use_args

from mbtaalerts.database.database import DB_SESSION, init_db
from mbtaalerts.database.models import AlertEvent
from mbtaalerts.logging import get_log

LOG = get_log('api')
APP = Flask(__name__)
APP.config['JSONIFY_PRETTYPRINT_REGULAR'] = False


@APP.teardown_appcontext
def shutdown_session(exception=None):
    """
    This ties into sqlalchemy to make sure that each
    API session has an independent DB session.
    """
    DB_SESSION.remove()


@APP.route('/data/alert_events')
@use_args({