Пример #1
0
    def __init__(self, config=None):
        """
        Create a new instance of the GraphiteHandler class
        """
        # Initialize Handler
        Handler.__init__(self, config)

        # Initialize Data
        self.socket = None

        # Initialize Options
        self.proto = self.config['proto'].lower().strip()
        self.host = self.config['host']
        self.port = int(self.config['port'])
        self.timeout = float(self.config['timeout'])
        self.keepalive = bool(self.config['keepalive'])
        self.keepaliveinterval = int(self.config['keepaliveinterval'])
        self.batch_size = int(self.config['batch'])
        self.max_backlog_multiplier = int(
            self.config['max_backlog_multiplier'])
        self.trim_backlog_multiplier = int(
            self.config['trim_backlog_multiplier'])
        self.flow_info = self.config['flow_info']
        self.scope_id = self.config['scope_id']
        self.metrics = []
        self.reconnect_interval = int(self.config['reconnect_interval'])
        self.last_connect_timestamp = -1

        # Connect
        self._connect()
Пример #2
0
    def __init__(self, config=None):
        """
        Create a new instance of zmqHandler class
        
        Keyword Arguments:
            config {[type]} -- [description] (default: {None})
        """

        # Initialize Handler
        Handler.__init__(self, config)

        if not zmq:
            self.log.error("zmq import failed. Handler disabled")
            self.enabled = False
            return

        # Initialize data
        self.context = None
        self.socket = None

        # Initialize options
        self.port = int(self.config['port'])

        # Create ZMQ pub socket and bind
        """try:
Пример #3
0
    def __init__(self, config):
        """
        Create a new instance of the ArchiveHandler class
        
        Arguments:
            conig {[type]} -- [description]
        """
        print("++++++++++++++++++++++++++++++++++++++++++++++++++")
        # Initialize Handler
        Handler.__init__(self, config)

        # Create Archive Logger
        self.archive = logging.getLogger('archive')
        self.archive.setLevel(logging.DEBUG)
        self.archive.propagate = self.config['propagate']

        # Create Archive Log Formatter
        formatter = logging.Formatter("%(message)s")

        # Create Archive Log Handler
        handler = logging.handlers.TimedRotatingFileHandler(
            filename = self.config['log_file'],
            when = self.config['when'],
            interval = int(self.config['rollover_interval']),
            backupCount = int(self.config['days']),
            encoding = self.config['encoding']
        )
        handler.setFormatter(formatter)
        handler.setLevel(logging.DEBUG)
        self.archive.addHandler(handler)

        self.archive.debug( "Log Messages from System and Iot Platform" )
Пример #4
0
 def __init__(self, config=None):
     Handler.__init__(self, config)
     self.metrics = []
     self.batch_size = int(self.config['batch'])
     self.url = self.config.get('url')
     self.meta = {}
     for k, v in self.config.items():
         if k.startswith('meta_'):
             self.meta[k.replace('meta_', '')] = v
Пример #5
0
    def __init__(self, config=None):
        Handler.__init__(self, config)
        logging.debug("Initialized Whale Monitoring handler.")

        if whaleapi is None:
            logging.error("Failed to load whaleapi module.")
            return

        self.api_token = self.config.get('api_token', '')
        self.api_host = self.config.get('api_host', '')
        self.queue_size = self.config.get('queue_size', 20)

        whaleapi.initialize(self.api_token, self.api_host)
        self.api = whaleapi.api
        self.queue = deque([])
    def __init__(self, config=None):
        """
        Create a new instance of rmqHandler class.
        
        Keyword Arguments:
            config {[type]} -- [description] (default: {None})
        """

        print("$$$$$$$$$$$$", config)

        # Initialize Handler
        Handler.__init__(self, config)

        if pika is None:
            self.log.error("pika import failed. Handler disabled")
            self.enabled = False
            return

        # Initialize data
        self.connections = {}
        self.channels = {}
        self.reconnect_interval = 1

        # Initialize options
        tmp_rmq_server = self.config['rmq_server']
        if type(tmp_rmq_server) is list:
            self.rmq_server = tmp_rmq_server
        else:
            self.rmq_server = [tmp_rmq_server]

        self.rmq_port = 5672
        self.rmq_exchange = self.config['rmq_exchange']
        self.rmq_user = None
        self.rmq_password = None
        self.rmq_vhost = "/"
        self.rmq_exchange_type = 'fanout'
        self.rmq_durable = True
        self.rmq_heartbeat_interval = 600
        self.blocked_connection_timeout = 300

        self.get_config()

        # Create rabbitMQ pub socket and bind
        try:
            self._bind_all()
        except pika.exceptions.AMQPConnectionError:
            self.log.error('Failed to bind to RabbitMQ pub socket')
Пример #7
0
    def __init__(self, config):
        """
        Create a new instance
        """
        # Initialize Handler
        Handler.__init__(self, config)

        self.fifo_path = self.config['fifo_path']

        if not os.path.exists(self.fifo_path):
            os.mkfifo(
                self.fifo_path, int(self.config['creation_mode'], base=8))
        elif not stat.S_ISFIFO(os.stat(self.fifo_path).st_mode):
            self.log.error('FifoHandler: %s is not FIFO file' % self.fifo_path)
            self.enabled = False

        self.open()
Пример #8
0
    def __init__(self, config=None):
        """
        Create a new instance of the MySQLHandler class
        
        Keyword Arguments:
            config {[type]} -- [description] (default: {None})
        """
        # Initialize Handler
        Handler.__init__(self, config)

        # Initialize Options
        self.hostname = self.config['hostname']
        self.port = self.config['port']
        self.username = self.config['username']
        self.password = self.config['password']
        self.database = self.config['database']
        self.table = self.config['table']
        self.col_time = self.config['col_time']
        self.col_metric = self.config['col_metric']
        self.col_value = self.config['col_value']

        # Connect
        self._connect()
    def __init__(self, config):
        """
        Create a new instance of rmqHandler class
        
        Arguments:
            config {[type]} -- [description]
        """

        # Initialize Handler
        Handler.__init__(self, config)

        # Initialize Data
        self.connection = None
        self.channel = None

        # Initialize Options
        self.server = self.config.get('server', '127.0.0.1')
        self.port = self.config.get('port', 5672)
        self.topic_exchange = self.config.get('topic_exchange', 'diamond')
        self.vhost = self.config.get('vhost', '')
        self.user = self.config.get('user', 'guest')
        self.password = self.config.get('password', 'guest')
        self.routing_key = self.config.get('routing_key', 'metric')
        self.custom_routing_key = self.config.get('custom_routing_key',
                                                  'diamond')

        if not pika:
            self.log.error('pika import failed. Handler disabled')
            self.enabled = False
            return

        # Create rabbitMQ topic exchange and bind
        try:
            self._bind()
        except pika.exceptions.AMQPConnectionError:
            self.log.error("Failed to bind to rabbitMQ topic exchange")
Пример #10
0
    def __init__(self, config=None):
        """
          Create a new instance of cloudwatchHandler class
        """

        # Initialize Handler
        Handler.__init__(self, config)

        if not boto:
            self.log.error(
                "CloudWatch: Boto is not installed, please install boto.")
            return

        # Initialize Data
        self.cloudwatch = None
        self.cached_aws_info = None

        try:
            self.cached_aws_info = self.config['awsinfo']
            self.log.debug(
                "Found cached AWS Instance details, I won't call AWS for them"
            )
        except KeyError:
            self.log.debug("Proceeding by calling AWS for instance details")

        if self.cached_aws_info:
            with open(self.config['awsinfo'], 'r') as f:
                info = load(f)
                self.instance_id = info['instance']
                self.autoscaling_group_name = info['autoscaling_group_name']
                self.region = info['region']
                self.log.debug("Grabbed AWS Info from file")
        else:
            # Initialize Options
            self.region = self.config['region']
            instances = boto.utils.get_instance_metadata()
            if 'instance-id' not in instances:
                self.log.error('CloudWatch: Failed to load instance metadata')
                return
            self.instance_id = instances['instance-id']
            self.autoscaling_group_name = None
            self.log.debug("Grabbed AWS Info from Boto")
        self.log.debug("Setting InstanceId: " + self.instance_id)

        self.valid_config = ('region',
                             'collector',
                             'metric',
                             'namespace',
                             'name',
                             'unit',
                             'autoscaling',
                             'awsinfo')

        self.rules = []
        for _, section in self.config.items():
            if section.__class__ is Section:
                keys = section.keys()
                rules = {}
                for key in keys:
                    if key not in self.valid_config:
                        self.log.warning("invalid key %s in section %s",
                                         key, section.name)
                    else:
                        rules[key] = section[key]

                self.rules.append(rules)

        # Create CloudWatch Connection
        self._bind()
Пример #11
0
    def __init__(self, config=None, queue=None, log=None):
        # Initialize Handler
        Handler.__init__(self, config=config, log=log)

        self.queue = queue
Пример #12
0
    def __init__(self, config=None):
        """
        Create a new instance of the MQTTHandler class
        
        Keyword Arguments:
            config {[type]} -- [description] (default: {None})
        """

        # Initialize Handler
        Handler.__init__(self, config)

        # Initialize Data
        self.mqttc = None
        self.hostname = get_hostname(self.config)
        self.client_id = "%s_%s" % (self.hostname, os.getpid())

        # Initialize Options
        self.host = self.config.get('host', 'localhost')
        self.port = 0
        self.qos = int(self.config.get('qos', 0))
        self.prefix = self.config.get('prefix', "")
        self.tls = self.config.get('tls', False)

        self.timestamp = 0
        try:
            self.timestamp = self.config['timestamp']
            if not self.timestamp:
                self.timestamp = 1
            else:
                self.timestamp = 0
        except:
            self.timestamp = 1

        # if not mosquitto:
        if not mqtt:
            self.log.error('mosquitto import faield. Handler disabled')
            self.enabled = False
            return

        # Initialize
        # self.mqttc = mosquitto.mosquitto(self.client_id, clean_session=True)
        self.mqttc = mqtt.Client(self.client_id, clean_session=True)

        if not self.tls:
            self.port = int(self.config.get('port', 1883))
        else:
            # Set up TLS if requested
            self.port = int(self.config.get('port', 8883))

            self.cafile = self.config.get('cafile', None)
            self.certfile = self.config.get('certfile', None)
            self.keyfile = self.config.get('keyfile', None)

            if None in [self.cafile, self.certfile, self.keyfile]:
                self.log.error("MQTT Handler: TLS configuration missing")
                return

            try:
                self.mqttc.tls_set(self.cafile,
                                   certfile=self.certfile,
                                   keyfile=self.keyfile,
                                   cert_reqs=ssl.CERT_REQUIRED,
                                   tls_version=3,
                                   ciphers=None)
            except:
                self.log.error("MQTTHandler: Cannot set up TLS " +
                               "configuration. Files missing ?")

        self.mqttc.will_set("clients/diamond/%s" % (self.hostname),
                            payload="Adios!",
                            qos=0,
                            retain=False)
        self.mqttc.connect(self.host, self.port, 60)

        self.mqttc.on_disconnect = self._disconnect