Exemplo n.º 1
0
def fds_service_health_check():
    ''' do health check for fds service
        returns:
            0     - passing
            1     - warning
            other - critical
    '''
    fds = FdsService(os.path.realpath(__file__))
    return fds.service_health_check()


if __name__ == '__main__':
    ''' health script main '''
    logfile = get_notify_data_path() + "/health_check.log"
    Debug.config(logfile, log2stdout=True, logcheck=1)

    # When CONSUL_IP can't get from environ, get it from config file
    # and update to environ
    if not "CONSUL_IP" in os.environ.keys():
        reqcmd = '''
            cat /var/opt/setup/site.export | egrep '^CONSUL_IP=.*$' | \
            awk -F= '{ print $2 }'
        '''
        resp = os.popen(reqcmd, "r").read()
        if resp:
            resp = resp.strip('"\n')
            os.environ["CONSUL_IP"] = resp
        print("CONSUL_IP: %s" % str(resp))

    state = fds_service_health_check()