def __init__(self, config=None): """ @type config: configobj.ConfigObj """ Handler.__init__(self, config) # init sentry/raven self.sentry_log_handler = raven.handlers.logging.SentryHandler( self.config['dsn']) self.raven_logger = logging.getLogger(self.__class__.__name__) self.raven_logger.addHandler(self.sentry_log_handler) self.configure_sentry_errors() self.rules = self.compile_rules() self.hostname = get_hostname(self.config) if not len(self.rules): self.log.warning("No rules, this graphite handler is unused")
def __init__(self, config=None): """ Create a new instance of the MQTTHandler class """ # 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 # Initialize self.mqttc = mosquitto.Mosquitto(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 (self.cafile is None or self.certfile is None or self.keyfile is None): self.log.error("MQTTHandler: 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
def __init__(self, config=None): """ Create a new instance of the MQTTHandler class """ # 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 # Initialize self.mqttc = mqttc = mosquitto.Mosquitto(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 self.cafile is None or self.certfile is None or self.keyfile is None: self.log.error("MQTTHandler: 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