Ejemplo n.º 1
0
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import logging
import re
import time

from pulseguardian import config
from pulseguardian.logs import setup_logging
from pulseguardian.management import PulseManagementAPI
from pulseguardian.model.base import init_db, db_session
from pulseguardian.model.models import PulseUser, Queue, User
from pulseguardian.sendemail import sendemail

logging.getLogger("requests").setLevel(logging.WARNING)

setup_logging(config.guardian_log_path)


class PulseGuardian(object):
    """Monitors RabbitMQ queues: assigns owners to queues, warn owners
    when a queue have a dangerously high number of unread messages, and
    deletes a queue if its unread messages exceed an even higher threshold.

    :param api: An instance of PulseManagementAPI, to communicate with rabbitmq.
    :param emails: Sends emails to queue owners if True.
    :param warn_queue_size: Warning threshold.
    :param del_queue_size: Deletion threshold.
    :param on_warn: Callback called with a queue's name when it's warned.
    :param on_delete: Callback called with a queue's name when it's deleted.
    """
Ejemplo n.º 2
0
import requests
import socket
import time
import traceback

from pulseguardian import config, management as pulse_management
from pulseguardian.logs import setup_logging
from pulseguardian.model.base import init_db, db_session
from pulseguardian.model.binding import Binding
from pulseguardian.model.user import PulseUser, User
from pulseguardian.model.queue import Queue
from pulseguardian.sendemail import sendemail

logging.getLogger("requests").setLevel(logging.WARNING)

setup_logging(config.guardian_log_path)


class PulseGuardian(object):
    """Monitors RabbitMQ queues: assigns owners to queues, warn owners
    when a queue have a dangerously high number of unread messages, and
    deletes a queue if its unread messages exceed an even higher threshold.

    :param api: An instance of PulseManagementAPI, to communicate with rabbitmq.
    :param emails: Sends emails to queue owners if True.
    :param warn_queue_size: Warning threshold.
    :param del_queue_size: Deletion threshold.
    :param on_warn: Callback called with a queue's name when it's warned.
    :param on_delete: Callback called with a queue's name when it's deleted.
    """
    def __init__(self,
Ejemplo n.º 3
0
    return cert, pkey


# This is used by werkzeug.serving.make_ssl_devcert().
werkzeug.serving.generate_adhoc_ssl_pair = generate_adhoc_ssl_pair


# Initialize the web app.
app = Flask(__name__)
app.secret_key = config.flask_secret_key

# Redirect to https if running on Heroku dyno.
if 'DYNO' in os.environ:
    sslify = SSLify(app)

app.logger.addHandler(setup_logging(config.webapp_log_path))


# Log in with a fake account if set up.  This is an easy way to test
# without requiring Persona (and thus https).
fake_account = None

if config.fake_account:
    fake_account = config.fake_account
    app.config['SESSION_COOKIE_SECURE'] = False
else:
    app.config['SESSION_COOKIE_SECURE'] = True


# Initializing the rabbitmq management API
pulse_management = PulseManagementAPI(
Ejemplo n.º 4
0
    return cert, pkey


# This is used by werkzeug.serving.make_ssl_devcert().
werkzeug.serving.generate_adhoc_ssl_pair = generate_adhoc_ssl_pair

# Initialize the web app.
app = Flask(__name__)
app.secret_key = config.flask_secret_key

# Redirect to https if running on Heroku dyno.
if 'DYNO' in os.environ:
    sslify = SSLify(app)

app.logger.addHandler(setup_logging(config.webapp_log_path))

# Log in with a fake account if set up.  This is an easy way to test
# without requiring Persona (and thus https).
fake_account = None

if config.fake_account:
    fake_account = config.fake_account
    app.config['SESSION_COOKIE_SECURE'] = False
else:
    app.config['SESSION_COOKIE_SECURE'] = True

# Initialize the database.
init_db()

# Decorators and instructions used to inject info into the context or