Ejemplo n.º 1
0
    def setUp(self):
        """Initialises the Reader object
        to be tested and Mock."""

        self.test = reader.Reader()
        self.config = configurator.Config()
        self.config.set_config()
        self.mock = mock.Mock()
Ejemplo n.º 2
0
    def connect(self):
        """Connects to the RabbitMQ queue."""

        read = reader.Reader()

        connection = pika.BlockingConnection(
            pika.ConnectionParameters(
                read.get_c_value()[1], read.get_c_value()[2]))
        self.connection = connection.channel()
        queue = strings.get_rabbit_queue()
        self.connection.queue_declare(queue=queue)
Ejemplo n.º 3
0
    def __init__(self):
        """Creates the dictionary containing the collected packet,
        unique id and the time when the object was sent.
        Uses the given port and address to connect to the rabbit queue
        and sends the packet dictionary."""

        self.reader = reader.Reader()
        id_handler = identifier.Identifier()
        self.machine_id = id_handler.get_id()

        self.connection = self.set_connection()
Ejemplo n.º 4
0
    def __init__(self, connection, machine_id):
        """Initialises the thread and packet info which
        will be sent to the RabbitMQ queue."""

        threading.Thread.__init__(self)

        self.r_handler = reader.Reader()
        self.m_handler = metrics.Metric()

        self.rabbit_connection = connection
        self.packet = {'ID': machine_id}

        send_time = int(self.r_handler.get_c_value()[0])
        time.sleep(send_time)
Ejemplo n.º 5
0
    def __init__(self, app):
        """Configures the mongodb name and uri
        using the reader in client."""

        self.app = app

        read = reader.Reader()

        self.app.config['MONGODB_NAME'] = read.get_d_value()[0]
        self.app.config['MONGO_URI'] = read.get_d_value()[1]

        try:
            self.database = flask_pymongo.PyMongo(self.app)
            self.handler = self.database.db.packets
        except (pymongo.errors.InvalidURI, pymongo.errors.InvalidName,
                pymongo.errors.ConnectionFailure):
            print("Invalid database URI or database name.")
            exit(-1)
Ejemplo n.º 6
0
def start():
    """It first validates the config.ini file.
       It sets connection to the RabbitMQ queue to send the metrics.
       Sets the machine id.
       It starts the Flask server, then the client and server thread
       on send and consume side of RabbitMQ."""

    configurator.Config()
    identifier.Identifier()
    reader.Reader()

    metrics = packets.Packet()
    machine_id = metrics.machine_id

    rabbit_connection = metrics.set_connection()

    app.start_app()

    start_threads(rabbit_connection, app.APP, machine_id)
Ejemplo n.º 7
0
    def setUp(self):
        """Creates a new connection for each test."""

        read = reader.Reader()
        self.test = rabbitmq.RabbitMQ(read.get_c_value()[1],
                                      read.get_c_value()[2])
Ejemplo n.º 8
0
    def run_app(self):
        """Starts the flask server."""

        read = reader.Reader()
        self.app.run(read.get_c_value()[1],
                     read.get_c_value()[3])
Ejemplo n.º 9
0
"""Module which uses Flask to get the packets out of the database
and make them available to web use."""
import flask
from util import configurator
from util import reader
from server import database, flask_server

APP = flask.Flask(__name__, template_folder="templates")
CONFIG = configurator.Config()
READ = reader.Reader()
DATABASE = database.Database(APP)


def start_app():
    """Starts the thread which runs Flask APP."""

    thread = flask_server.FlaskThread(APP)
    thread.setDaemon(True)
    thread.start()


@APP.route('/')
def main_page_route():
    """Displays the main page and the types of information
     you can get the server to display."""

    return flask.render_template("main_page.html")


@APP.route('/supported_metrics')
def supported_metrics_route():
Ejemplo n.º 10
0
    def __init__(self):
        """Initialises a reader to read the config.ini file."""

        self.reader = reader.Reader()