def __init__(self, amqp_url, exchange_name=None, exchange_type=None, exchange_durable=False, queue_name=None, queue_durable=False, routing_key=None, confirm=False): """Create a new instance of the consumer class, passing in the AMQP URL used to connect to RabbitMQ. :param str amqp_url: The AMQP url to connect with """ self._consumer_tag = None self._connection = None self._channel = None self._url = amqp_url self._closing = False self._exchange_durable = exchange_durable self._queue_durable = queue_durable self._enable_confirmation = confirm # Read the global config file try: config = ConfigReader() config.read("OMQS.cfg") manager = OMQSLogManager(name=__name__, file_name=__name__) self._logger = manager.logger except Exception, e: logging.error('[OMQS][AsyncConsumer]: Failed to read the config or setting the logger: %s', str(e)) return None
def __init__(self, keys, amqp_url=None, queue=None, queue_durable=False, log_callback=None, name='LogMsgConsumer'): try: config = ConfigReader() config.read("OMQS.cfg") exchange = config.LogConsumer.EXCHANGE ex_durable = config.LogConsumer.EXCHANGE_DURABLE if not queue: queue = config.LogConsumer.QUEUE except Exception, e: logging.error('[%s]: Failed to read the config or setting the logger: %r', name, e) return None
def __init__(self, amqp_url=None, keys=None, queue=None, evt_callback=None, name='EventMsgConsumer'): self._logger = None try: config = ConfigReader() config.read("OMQS.cfg") exchange = config.EventConsumer.EXCHANGE ex_durable = config.EventConsumer.EXCHANGE_DURABLE if not keys: keys = config.EventConsumer.KEYS if not queue: queue = config.EventConsumer.QUEUE except Exception, e: logging.error('[%s]: Failed to read the config or setting the logger: %r', name, e)
def __init__(self, amqp_url=None, exchange_name=None, exchange_type=None, exchange_durable=False): """Setup the example publisher object, passing in the URL we will use to connect to RabbitMQ. :param str amqp_url: The URL for connecting to RabbitMQ """ self._connection = None self._channel = None self._message_number = 0 self._ready = False self._url = amqp_url self._exchange_durable = exchange_durable # Read the global config file config = ConfigReader() config.read("OMQS.cfg") if not self._url: self._url = config.Global.MQURL if not self._url: self._url = URL if exchange_name: self._exchange = exchange_name else: self._exchange = config.SyncPublisher.EXCHANGE if not self._exchange: self._exchange = EXCHANGE if exchange_type: self._exchange_type = exchange_type else: self._exchange_type = config.SyncPublisher.EXCHANGE_TYPE if not self._exchange_type: self._exchange_type = EXCHANGE_TYPE self._default_key = config.SyncPublisher.ROUTING_KEYS if not self._default_key: self._default_key = ROUTING_KEYS
def __init__(self, amqp_url=None, exchange_name=None, exchange_type=None, exchange_durable=False, queue_name=None, queue_durable=False, confirm=False): """Setup the example publisher object, passing in the URL we will use to connect to RabbitMQ. :param str amqp_url: The URL for connecting to RabbitMQ """ self._connection = None self._channel = None self._acked = 0 self._nacked = 0 self._message_number = 0 self._stopping = False self._ready = False self._url = amqp_url self._closing = False self._exchange_durable = exchange_durable self._queue_durable = queue_durable self._enable_confirmation = confirm # Read the global config file try: config = ConfigReader() config.read("OMQS.cfg") manager = OMQSLogManager(name=__name__, file_name=__name__) self._logger = manager.logger except Exception, e: logging.error('[OMQS][%s]: Failed to read the config or setting the logger: %r', __name__, e) return None
def __init__(self, config_file): self.config_file = config_file # an yml file configReader = ConfigReader() self.config = configReader.read(self.config_file) # is a dict of lists of dicts (see yml file structure) self.class_name = '' self.data_name = 'PrivateData' # Verify all names for key, value in self.config.items(): if key == 'class': #print value verifyName(value) self.class_name = value else: # methods, properties, private_data for item in value: #print item['name'] verifyName(item['name']) # TODO: check for duplicates # Retrieve private data names private_data_names = [] if 'private_data' in self.config.keys(): dictlist = self.config['private_data'] private_data_names = [dictio['name'] for dictio in dictlist] #print private_data_names # Check if a property refers to a non-existing data field if 'properties' in self.config.keys(): for item in self.config['properties']: referred_data = tryRead(item,'modifies') if referred_data and referred_data not in private_data_names: print ('%s property modifies %s private_data field. Autocreating.' % (item['name'], item['modifies'])) # Add private data field #print item if not 'private_data' in self.config.keys(): self.config['private_data'] = [] self.config['private_data'].append({'name':item['name'], 'returns':item['returns'], 'default':''}) return
def __init__(self, name='BaseSyncConsumer', amqp_url=None, exchange_name=None, exchange_type=None, exchange_durable=False, queue_name=None, queue_durable=False, routing_keys=None, no_ack=True, callback=None): """Setup the example publisher object, passing in the URL we will use to connect to RabbitMQ. :param str amqp_url: The URL for connecting to RabbitMQ """ self._name = name self._connection = None self._channel = None self._message_number = 0 self._exchange_durable = exchange_durable self._queue_durable = queue_durable self._no_ack = no_ack self._callback = callback manager = OMQSLogManager(name=name, file_name=name) self._logger = manager.logger # Read the global config file config = ConfigReader() config.read("OMQS.cfg") if amqp_url: self._url = amqp_url else: self._url = config.Global.MQURL if not self._url: self._url = URL if exchange_name: self._exchange = exchange_name else: self._exchange = config.SyncPublisher.EXCHANGE if not self._exchange: self._exchange = EXCHANGE if exchange_type: self._exchange_type = exchange_type else: self._exchange_type = config.SyncPublisher.EXCHANGE_TYPE if not self._exchange_type: self._exchange_type = EXCHANGE_TYPE if queue_name: self._queue = queue_name else: self._queue = config.SyncPublisher.QUEUE if not self._queue: self._queue = QUEUE if routing_keys: self._routing_keys = routing_keys else: self._keys = [] str_keys = config.SyncPublisher.ROUTING_KEYS if str_keys: keys = str_keys.split(',') for key in keys: self._routing_keys.append(key.strip()) else: self._routing_keys = KEYS if not self._callback: self._callback = default_callback
# if thisIPAddr in ip_addresses: # ip_addresses[thisIPAddr] += 1 # else: # ip_addresses[thisIPAddr] = 1 else: print "PARSE ERROR on line: " + line # ------------------------------------------------------------------------------- # Get the current list of denied IP addreses. We'll use that to ensure we don't # add duplicates denied_ips = [] cr = ConfigReader(hostsdenyfile) cr.read() config = cr.get_config() for line in config: parts = line.split(":") denied_ips.append(parts[1].strip()) status_update = "DEBUG: hosts.deny file currently has " + str(len(denied_ips)) + " denied IP addresses." email_msg += status_update + "\n" if verbose: print status_update # ------------------------------------------------------------------------------- # Determine if there are any new IP addresses that we should ban. new_banned_ips = []