Esempio n. 1
0
def main():  # pragma: no cover
    logging.getLogger('pika').setLevel(logging.WARNING)
    Logger()
    logger = logging.getLogger('main')
    pmain = Monitor(logger, CTRL_C)
    host = pmain.controller['FA_RABBIT_HOST']
    port = int(pmain.controller['FA_RABBIT_PORT'])

    rabbit = Rabbit()
    exchange = 'topic-poseidon-internal'
    binding_key = ['poseidon.algos.#', 'poseidon.action.#']
    rabbit.make_rabbit_connection(host, port, exchange, binding_key)
    rabbit.start_channel(pmain.rabbit_callback, pmain.m_queue)
    pmain.rabbits.append(rabbit)

    rabbit = Rabbit()
    exchange = pmain.controller['FA_RABBIT_EXCHANGE']
    binding_key = [pmain.controller['FA_RABBIT_ROUTING_KEY'] + '.#']
    rabbit.make_rabbit_connection(host, port, exchange, binding_key)
    rabbit.start_channel(pmain.rabbit_callback, pmain.m_queue)
    pmain.rabbits.append(rabbit)

    pmain.schedule_thread.start()

    # loop here until told not to
    try:
        pmain.process()
    except Exception as e:
        logger.error('process() exception: {0}'.format(str(e)))

    pmain.shutdown()
Esempio n. 2
0
from poseidon.helpers.config import Config
from poseidon.helpers.endpoint import Endpoint, EndpointDecoder, endpoint_factory
from poseidon.helpers.endpoint import MACHINE_IP_FIELDS, MACHINE_IP_PREFIXES
from poseidon.helpers.endpoint import HistoryTypes
from poseidon.helpers.log import Logger
from poseidon.helpers.metadata import get_ether_vendor
from poseidon.helpers.metadata import get_rdns_lookup
from poseidon.helpers.prometheus import Prometheus
from poseidon.helpers.rabbit import Rabbit

requests.packages.urllib3.disable_warnings()
logging.getLogger('pika').setLevel(logging.WARNING)

CTRL_C = dict()
CTRL_C['STOP'] = False
Logger()
logger = logging.getLogger('main')


def rabbit_callback(ch, method, properties, body, q=None):
    ''' callback, places rabbit data into internal queue'''
    logger.debug('got a message: {0}:{1}:{2}'.format(method.routing_key, body,
                                                     type(body)))
    if q is not None:
        q.put((method.routing_key, body))
    else:
        logger.debug('poseidonMain workQueue is None')


def schedule_job_kickurl(schedule_func):
    global CTRL_C