def _heartbeat(self): packets = Packet.create('HB', PacketType.PA_HEARTBEAT) self.router.got_data(packets) # Set TTL Check Status check_string = self._agent + 'check/pass/service:' for port_id in [self.data_port_id, self.command_port_id, self.sniffer_port_id]: d = get(check_string + port_id) d.addCallback(self.done, caller='TTL check status: %s' % port_id) d.addErrback(log.msg, 'Error sending check: %s' % port_id) reactor.callLater(HEARTBEAT_INTERVAL, self._heartbeat)
def _heartbeat(self): """ Send a heartbeat packet and set our Consul status to PASS :return: """ packets = Packet.create('HB', PacketType.PA_HEARTBEAT) self.router.got_data(packets) # Set TTL Check Status check_string = self._agent + 'check/pass/service:' for service in self.config['ports']: name, service_id = self.get_service_name_id(service) yield get(check_string + service_id)
def get_consul_host(self): """ Fetch our host information from Consul :return: """ url = self._agent + 'self' try: response = yield get(url) body = yield readBody(response) data = json.loads(body) host = data['Member']['Addr'] self.config['host'] = host except (ConnectionRefusedError, KeyError) as e: log.msg('Unable to retrieve host address from consul: ', e) reactor.callLater(CONSUL_RETRY_INTERVAL, self.get_consul_host)
def _heartbeat(self): packets = Packet.create('HB', PacketType.PA_HEARTBEAT) self.router.got_data(packets) # Set TTL Check Status check_string = self._agent + 'check/pass/service:' get(check_string + self.data_port_id).addCallback( self.done, caller='%s TTL check status: ' % self.data_port_id) get(check_string + self.command_port_id).addCallback( self.done, caller='%s TTL check status: ' % self.command_port_id) get(check_string + self.sniffer_port_id).addCallback( self.done, caller='%s TTL check status: ' % self.sniffer_port_id) reactor.callLater(HEARTBEAT_INTERVAL, self._heartbeat)