def main(skip_rabbit=False): ''' main function ''' pmain = Monitor(skip_rabbit=skip_rabbit) if not skip_rabbit: rabbit = Rabbit_Base() host = pmain.mod_configuration['rabbit_server'] port = int(pmain.mod_configuration['rabbit_port']) exchange = 'topic-poseidon-internal' queue_name = 'poseidon_main' binding_key = ['poseidon.algos.#', 'poseidon.action.#'] retval = rabbit.make_rabbit_connection(host, port, exchange, queue_name, binding_key) pmain.rabbit_channel_local = retval[0] pmain.rabbit_channel_connection_local = retval[1] pmain.rabbit_thread = rabbit.start_channel(pmain.rabbit_channel_local, rabbit_callback, 'poseidon_main', pmain.m_queue) # def start_channel(self, channel, callback, queue): pmain.schedule_thread.start() # loop here until told not to pmain.process() pmain.logger.debug('SHUTTING DOWN') # pmain.rabbit_channel_connection_local.close() # pmain.rabbit_channel_local.close() pmain.logger.debug('EXITING') sys.exit(0)
def main(skip_rabbit=False): # pragma: no cover ''' main function ''' pmain = Monitor(skip_rabbit=skip_rabbit) # declare prometheus variables pmain.prom_metrics['inactive'] = Gauge( 'poseidon_endpoint_inactive', 'Number of endpoints that are inactive') pmain.prom_metrics['active'] = Gauge( 'poseidon_endpoint_active', 'Number of endpoints that are active') pmain.prom_metrics['behavior'] = Gauge( 'poseidon_endpoint_behavior', 'Behavior of an endpoint, 0 is normal, 1 is abnormal', [ 'ip', 'mac', 'tenant', 'segment', 'port', 'role', 'os', 'record_source' ]) pmain.prom_metrics['ip_table'] = Gauge( 'poseidon_endpoint_ip_table', 'IP Table', [ 'mac', 'tenant', 'segment', 'port', 'role', 'os', 'hash_id', 'record_source' ]) pmain.prom_metrics['roles'] = Gauge('poseidon_endpoint_roles', 'Number of endpoints by role', ['record_source', 'role']) pmain.prom_metrics['oses'] = Gauge('poseidon_endpoint_oses', 'Number of endpoints by OS', ['record_source', 'os']) pmain.prom_metrics['current_states'] = Gauge( 'poseidon_endpoint_current_states', 'Number of endpoints by current state', ['record_source', 'current_state']) pmain.prom_metrics['vlans'] = Gauge('poseidon_endpoint_vlans', 'Number of endpoints by VLAN', ['record_source', 'tenant']) pmain.prom_metrics['record_sources'] = Gauge( 'poseidon_endpoint_record_sources', 'Number of endpoints by record source', ['record_source']) pmain.prom_metrics['port_tenants'] = Gauge( 'poseidon_endpoint_port_tenants', 'Number of tenants by port', ['port', 'tenant']) pmain.prom_metrics['port_hosts'] = Gauge('poseidon_endpoint_port_hosts', 'Number of hosts by port', ['port']) # start prometheus start_http_server(9304) if not skip_rabbit: rabbit = Rabbit_Base() host = pmain.mod_configuration['rabbit_server'] port = int(pmain.mod_configuration['rabbit_port']) exchange = 'topic-poseidon-internal' queue_name = 'poseidon_main' binding_key = ['poseidon.algos.#', 'poseidon.action.#'] retval = rabbit.make_rabbit_connection(host, port, exchange, queue_name, binding_key) pmain.rabbit_channel_local = retval[0] pmain.rabbit_channel_connection_local = retval[1] pmain.rabbit_thread = rabbit.start_channel(pmain.rabbit_channel_local, rabbit_callback, queue_name, pmain.m_queue) # def start_channel(self, channel, callback, queue): if pmain.fa_rabbit_enabled: rabbit = Rabbit_Base() host = pmain.fa_rabbit_host port = pmain.fa_rabbit_port exchange = pmain.fa_rabbit_exchange queue_name = 'poseidon_main' binding_key = [pmain.fa_rabbit_routing_key + '.#'] retval = rabbit.make_rabbit_connection(host, port, exchange, queue_name, binding_key) pmain.rabbit_channel_local = retval[0] pmain.rabbit_channel_connection_local = retval[1] pmain.rabbit_thread = rabbit.start_channel(pmain.rabbit_channel_local, rabbit_callback, queue_name, pmain.m_queue) pmain.schedule_thread.start() # loop here until told not to pmain.process() pmain.logger.debug('SHUTTING DOWN') # pmain.rabbit_channel_connection_local.close() # pmain.rabbit_channel_local.close() pmain.logger.debug('EXITING') sys.exit(0)