Esempio n. 1
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()
            con = servo.ws.connect_elb(
                host_name=elb_host,
                aws_access_key_id=aws_access_key_id,
                aws_secret_access_key=aws_secret_access_key,
                security_token=security_token)

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' %
                                    self.instance_id)
                    try:
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' %
                                        err)
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
                    elapsed = dt.now() - last_inservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug('%s: InService status reported' %
                                            self.instance_id)
                            last_inservice_reported = dt.now()
                            last_outofservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)
                    elapsed = dt.now() - last_outofservice_reported
                    if self.report_elb and elapsed.seconds > config.PUT_BACKEND_INSTANCE_HEALTH_PERIOD_SEC:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token)
                            con.put_instance_health(servo_instance_id,
                                                    [instance])
                            servo.log.debug(
                                '%s: OutOfService status reported' %
                                self.instance_id)
                            last_outofservice_reported = dt.now()
                            last_inservice_reported = dt.min
                        except Exception, err:
                            servo.log.error('failed to post servo states: %s' %
                                            err)
    def run(self):
        if health_check_config is None:
            servo.log.error("health check config is not set")
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        while self.running:
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error("could not find the ipaddress of the instance %s" % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith("HTTPS"):
                result = self.check_https(target)
            elif target.upper().startswith("TCP"):
                result = self.check_tcp(target)
            elif target.upper().startswith("HTTP"):
                result = self.check_http(target)
            elif target.upper().startswith("SSL"):
                result = self.check_ssl(target)
            else:
                servo.log.error("unknown target: %s" % target)
            # print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, "InService")
                    self.inst_status = "InService"
                    servo.log.debug("%s: InService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: InService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, "OutOfService")
                    self.inst_status = "OutOfService"
                    servo.log.debug("%s: OutOfService" % self.instance_id)
                    if self.report_elb:
                        try:
                            con = servo.ws.connect_elb(
                                aws_access_key_id=aws_access_key_id,
                                aws_secret_access_key=aws_secret_access_key,
                                security_token=security_token,
                            )
                            con.put_instance_health(servo_instance_id, [instance])
                            servo.log.debug("%s: OutOfService status reported" % self.instance_id)
                        except Exception, err:
                            servo.log.error("failed to post servo states: %s" % err)
Esempio n. 4
0
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error(
                    'could not find the ipaddress of the instance %s' %
                    self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:  # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id,
                                                'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        last_inservice_reported = dt.min
        last_outofservice_reported = dt.min
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)

            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result: # passed one check
                healthy_count += 1
                unhealthy_count = 0
                if not self.initially_reported or healthy_count >= health_check_config.healthy_threshold:
                    self.initially_reported = True
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('%s: InService' % self.instance_id)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    self.initially_reported = True
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('%s: OutOfService' % self.instance_id)

            if healthy_count > health_check_config.healthy_threshold:
                healthy_count = 0
            if unhealthy_count > health_check_config.unhealthy_threshold:
                unhealthy_count = 0
            health_check_delay = health_check_config.interval
            while health_check_delay > 0 and self.running:
                time.sleep(1)
                health_check_delay -= 1
    def run(self):
        if health_check_config is None:
            servo.log.error('health check config is not set')
            return

        elb_host = config.get_clc_host()
        servo_instance_id = config.get_servo_id()
        healthy = None 
        healthy_count = 0
        unhealthy_count = 0
        while (self.running):
            self.ip_addr = hostname_cache.get_hostname(self.instance_id)
            if self.ip_addr is None:
                servo.log.error('could not find the ipaddress of the instance %s' % self.instance_id)
                return
            aws_access_key_id = config.get_access_key_id()
            aws_secret_access_key = config.get_secret_access_key()
            security_token = config.get_security_token()

            target = health_check_config.target
            result = None
            if target.upper().startswith('HTTPS'):
                result = self.check_https(target)
            elif target.upper().startswith('TCP'):
                result = self.check_tcp(target)
            elif target.upper().startswith('HTTP'):
                result = self.check_http(target)
            elif target.upper().startswith('SSL'):
                result = self.check_ssl(target)
            else:
                servo.log.error('unknown target: %s' % target)
            #print 'healthy? : %s, healthy_count: %d, unhealthy_count: %d, result: %s' % (healthy, healthy_count, unhealthy_count, result)
            if result is None:
                pass
            elif result:
                healthy_count += 1
                unhealthy_count = 0
                if healthy_count >= health_check_config.healthy_threshold:
                    healthy = True
                    healthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'InService')
                    self.inst_status = 'InService'
                    servo.log.debug('Reported %s InService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)
            else:
                unhealthy_count += 1
                healthy_count = 0
                if unhealthy_count >= health_check_config.unhealthy_threshold:
                    healthy = False
                    unhealthy_count = 0
                    instance = StatefulInstance(self.instance_id, 'OutOfService')
                    self.inst_status = 'OutOfService'
                    servo.log.debug('Reported %s OutOfService' % self.instance_id)
                    try:
                        con = servo.ws.connect_elb(aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, security_token=security_token)
                        con.put_instance_health(servo_instance_id, [instance])
                    except Exception, err:
                        servo.log.error('failed to post servo states: %s' % err)