コード例 #1
0
def configure_callback(conf):
    """Receive configuration block"""
    ip = None
    interval = 10
    graphite_host = None
    graphite_port = None

    for node in conf.children:
        key = node.key
        val = node.values[0]

        if key == 'ip':
            ip = val
        elif key == 'interval':
            interval = val
        elif key == 'graphite_host':
            graphite_host = val
        elif key == 'graphite_port':
            graphite_port = val
        else:
            collectd.warning(
                'keystone_api_local_check: Unknown config key: {}'.format(key))
            continue

    auth_details = get_auth_details()
    CONFIGS['ip'] = ip
    CONFIGS['auth_details'] = auth_details
    CONFIGS['interval'] = interval
    CONFIGS['graphite_host'] = graphite_host
    CONFIGS['graphite_port'] = graphite_port
コード例 #2
0
def check(args):
    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    HORIZON_URL = 'https://{ip}'.format(ip=args.ip)
    HORIZON_PORT = '443'

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=10)
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
        status_err(str(e))

    if not (r.ok
            and re.search('openstack dashboard', r.content, re.IGNORECASE)):
        status_err('could not load login page')

    splash_status_code = r.status_code
    splash_milliseconds = r.elapsed.total_seconds() * 1000

    csrf_token = html.fromstring(
        r.content).xpath('//input[@name="csrfmiddlewaretoken"]/@value')[0]
    region = html.fromstring(
        r.content).xpath('//input[@name="region"]/@value')[0]
    s.headers.update({
        'Content-type': 'application/x-www-form-urlencoded',
        'Referer': HORIZON_URL
    })
    payload = {
        'username': OS_USERNAME,
        'password': OS_PASSWORD,
        'csrfmiddlewaretoken': csrf_token,
        'region': region
    }
    try:
        l = s.post(('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT),
                   data=payload,
                   verify=False)
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
        status_err('While logging in: %s' % e)

    if not (l.ok and re.search('overview', l.content, re.IGNORECASE)):
        status_err('could not log in')

    login_status_code = l.status_code
    login_milliseconds = l.elapsed.total_seconds() * 1000

    status_ok()
    metric('splash_status_code', 'uint32', splash_status_code)
    metric('splash_milliseconds', 'double', splash_milliseconds, 'ms')
    metric('login_status_code', 'uint32', login_status_code)
    metric('login_milliseconds', 'double', login_milliseconds, 'ms')
コード例 #3
0
def check(args):

    # Admin Endpoint
    #IDENTITY_ENDPOINT = 'http://{ip}:35357/v2.0/'.format(ip=args.ip)
    # Public Endpoint
    IDENTITY_ENDPOINT = 'http://{ip}:5000/v2.0/'.format(ip=args.ip)

    AUTH_DETAILS = {
        'OS_USERNAME': None,
        'OS_PASSWORD': None,
        'OS_TENANT_NAME': None,
        'OS_AUTH_URL': None
    }

    try:
        #keystone = get_keystone_client(endpoint=IDENTITY_ENDPOINT)
        auth_details = get_auth_details()
        keystone = k_client.Client(username=auth_details['OS_USERNAME'],
                                   password=auth_details['OS_PASSWORD'],
                                   tenant_name=auth_details['OS_TENANT_NAME'],
                                   auth_url=IDENTITY_ENDPOINT)
        #auth_url=auth_details['OS_AUTH_URL'])
        is_up = True
    except (exc.HttpServerError, exc.ClientException):
        is_up = False
    # Any other exception presumably isn't an API error
    except Exception as e:
        status_err(str(e))
    else:
        # time something arbitrary
        start = time()
        keystone.services.list()
        end = time()
        milliseconds = (end - start) * 1000

        # gather some vaguely interesting metrics to return
        tenant_count = len(keystone.tenants.list())
        user_count = len(keystone.users.list())
        service_count = len(keystone.services.list())
        endpoint_count = len(keystone.endpoints.list())

    status_ok()
    metric_bool('keystone_api_local_status', is_up)
    # only want to send other metrics if api is up
    if is_up:
        metric('keystone_api_local_response_time', 'double',
               '%.3f' % milliseconds, 'ms')
        metric('keystone_user_count', 'uint32', user_count, 'users')
        metric('keystone_tenant_count', 'uint32', tenant_count, 'tenants')
        metric('keystone_service_count', 'uint32', service_count, 'services')
        metric('keystone_endpoint_count', 'uint32', endpoint_count,
               'endpoints')
コード例 #4
0
def check(args):

    # Admin Endpoint
    #IDENTITY_ENDPOINT = 'http://{ip}:35357/v2.0/'.format(ip=args.ip)
    # Public Endpoint
    IDENTITY_ENDPOINT = 'http://{ip}:5000/v2.0/'.format(ip=args.ip)

    AUTH_DETAILS = {'OS_USERNAME': None,
                    'OS_PASSWORD': None,
                    'OS_TENANT_NAME': None,
                    'OS_AUTH_URL': None}

    try:
        #keystone = get_keystone_client(endpoint=IDENTITY_ENDPOINT)
        auth_details = get_auth_details()
        keystone = k_client.Client(username=auth_details['OS_USERNAME'],
                                   password=auth_details['OS_PASSWORD'],
                                   tenant_name=auth_details['OS_TENANT_NAME'],
                                   auth_url=IDENTITY_ENDPOINT)
                                   #auth_url=auth_details['OS_AUTH_URL'])
        is_up = True
    except (exc.HttpServerError, exc.ClientException):
        is_up = False
    # Any other exception presumably isn't an API error
    except Exception as e:
        status_err(str(e))
    else:
        # time something arbitrary
        start = time()
        keystone.services.list()
        end = time()
        milliseconds = (end - start) * 1000

        # gather some vaguely interesting metrics to return
        tenant_count = len(keystone.tenants.list())
        user_count = len(keystone.users.list())
        service_count = len(keystone.services.list())
        endpoint_count = len(keystone.endpoints.list())

    status_ok()
    metric_bool('keystone_api_local_status', is_up)
    # only want to send other metrics if api is up
    if is_up:
        metric('keystone_api_local_response_time',
               'double',
               '%.3f' % milliseconds,
               'ms')
        metric('keystone_user_count', 'uint32', user_count, 'users')
        metric('keystone_tenant_count', 'uint32', tenant_count, 'tenants')
        metric('keystone_service_count', 'uint32', service_count, 'services')
        metric('keystone_endpoint_count', 'uint32', endpoint_count, 'endpoints')
コード例 #5
0
def check(args):
    # disable warning for insecure cert on horizon
    if requests.__build__ >= 0x020400:
        requests.packages.urllib3.disable_warnings()

    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    is_up = True

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    OS_USER_DOMAIN_NAME = auth_details['OS_USER_DOMAIN_NAME']
    HORIZON_URL = 'https://{ip}'.format(ip=args.ip)
    HORIZON_PORT = '443'

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=10)
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
        is_up = False
    else:
        if not (r.ok and re.search(args.site_name_regexp, r.content,
                                   re.IGNORECASE)):
            status_err('could not load login page')

        splash_status_code = r.status_code
        splash_milliseconds = r.elapsed.total_seconds() * 1000

        parsed_html = html.fromstring(r.content)
        csrf_token = parsed_html.xpath(
            '//input[@name="csrfmiddlewaretoken"]/@value')[0]
        region = parsed_html.xpath('//input[@name="region"]/@value')[0]
        domain = parsed_html.xpath('//input[@name="domain"]')
        s.headers.update({
            'Content-type': 'application/x-www-form-urlencoded',
            'Referer': HORIZON_URL
        })
        payload = {
            'username': OS_USERNAME,
            'password': OS_PASSWORD,
            'csrfmiddlewaretoken': csrf_token,
            'region': region
        }
        if domain:
            payload['domain'] = OS_USER_DOMAIN_NAME
        try:
            l = s.post(('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT),
                       data=payload,
                       verify=False)
        except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
            status_err('While logging in: %s' % e)

        if not (l.ok and re.search('overview', l.content, re.IGNORECASE)):
            status_err('could not log in')

        login_status_code = l.status_code
        login_milliseconds = l.elapsed.total_seconds() * 1000

    metric('horizon', 'horizon_local_status', str(int(is_up)))

    if is_up:
        metric('horizon', 'splash_status_http_code', splash_status_code)
        metric('horizon', 'splash_milliseconds', splash_milliseconds)
        metric('horizon', 'login_status_http_code', login_status_code)
        metric('horizon', 'login_milliseconds', login_milliseconds)
コード例 #6
0
def check(args):
    # disable warning for insecure cert on horizon
    requests.packages.urllib3.disable_warnings()

    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    is_up = True

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    HORIZON_URL = 'https://{ip}'.format(ip=args.ip)
    HORIZON_PORT = '443'

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=10)
    except (exc.ConnectionError,
            exc.HTTPError,
            exc.Timeout) as e:
        is_up = False
    else:
        if not (r.ok and
                re.search('openstack dashboard', r.content, re.IGNORECASE)):
            status_err('could not load login page')

        splash_status_code = r.status_code
        splash_milliseconds = r.elapsed.total_seconds() * 1000

        csrf_token = html.fromstring(r.content).xpath(
            '//input[@name="csrfmiddlewaretoken"]/@value')[0]
        region = html.fromstring(r.content).xpath(
            '//input[@name="region"]/@value')[0]
        s.headers.update(
            {'Content-type': 'application/x-www-form-urlencoded',
                'Referer': HORIZON_URL})
        payload = {'username': OS_USERNAME,
                   'password': OS_PASSWORD,
                   'csrfmiddlewaretoken': csrf_token,
                   'region': region}
        try:
            l = s.post(
                ('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT),
                data=payload,
                verify=False)
        except (exc.ConnectionError,
                exc.HTTPError,
                exc.Timeout) as e:
            status_err('While logging in: %s' % e)

        if not (l.ok and re.search('overview', l.content, re.IGNORECASE)):
            status_err('could not log in')

        login_status_code = l.status_code
        login_milliseconds = l.elapsed.total_seconds() * 1000

    status_ok()
    metric_bool('horizon_local_status', is_up)

    if is_up:
        metric('splash_status_code', 'uint32', splash_status_code, 'http_code')
        metric('splash_milliseconds', 'double', splash_milliseconds, 'ms')
        metric('login_status_code', 'uint32', login_status_code, 'http_code')
        metric('login_milliseconds', 'double', login_milliseconds, 'ms')
コード例 #7
0
def main(args):
    auth_details = get_auth_details()
    check(args, auth_details)
コード例 #8
0
def main(args):
    auth_details = get_auth_details()
    check(args, auth_details)
コード例 #9
0
def check(args):
    # disable warning for insecure cert on horizon
    if requests.__build__ >= 0x020400:
        requests.packages.urllib3.disable_warnings()

    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    is_up = True

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    OS_USER_DOMAIN_NAME = auth_details['OS_USER_DOMAIN_NAME']
    HORIZON_URL = '{protocol}://{ip}'.format(
        protocol=args.protocol,
        ip=args.ip,
    )
    HORIZON_PORT = args.port

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=180)
    except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
        is_up = False
        metric_bool('client_success', False, m_name='maas_horizon')
    else:
        if not (r.ok and re.search(args.site_name_regexp, r.content.decode(),
                                   re.IGNORECASE)):
            metric_bool('client_success', False, m_name='maas_horizon')
            status_err('could not load login page', m_name='maas_horizon')
        else:
            metric_bool('client_success', True, m_name='maas_horizon')
        splash_status_code = r.status_code
        splash_milliseconds = r.elapsed.total_seconds() * 1000

        parsed_html = html.fromstring(r.content)
        csrf_token = parsed_html.xpath(
            '//input[@name="csrfmiddlewaretoken"]/@value')[0]
        region = parsed_html.xpath('//input[@name="region"]/@value')[0]
        domain = parsed_html.xpath('//input[@name="domain"]')
        s.headers.update({
            'Content-type': 'application/x-www-form-urlencoded',
            'Referer': HORIZON_URL
        })
        payload = {
            'username': OS_USERNAME,
            'password': OS_PASSWORD,
            'csrfmiddlewaretoken': csrf_token,
            'region': region
        }
        if domain:
            payload['domain'] = OS_USER_DOMAIN_NAME
        try:
            login_url = ('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT)
            if args.deploy_osp:
                login_url = ('%s:%s/dashboard/auth/login/') % (HORIZON_URL,
                                                               HORIZON_PORT)
            login_resp = s.post(login_url, data=payload, verify=False)
        except (exc.ConnectionError, exc.HTTPError, exc.Timeout) as e:
            status_err('While logging in: %s' % e, m_name='maas_horizon')

        search_phrase = 'overview'
        if args.deploy_osp:
            search_phrase = 'project'
        if not (login_resp.ok and re.search(
                search_phrase, login_resp.content.decode(), re.IGNORECASE)):
            status_err('could not log in', m_name='maas_horizon')

        login_status_code = login_resp.status_code
        login_milliseconds = login_resp.elapsed.total_seconds() * 1000

    status_ok(m_name='maas_horizon')
    metric_bool('horizon_local_status', is_up, m_name='maas_horizon')

    if is_up:
        metric('splash_status_code', 'uint32', splash_status_code, 'http_code')
        metric('splash_milliseconds', 'double', splash_milliseconds, 'ms')
        metric('login_status_code', 'uint32', login_status_code, 'http_code')
        metric('login_milliseconds', 'double', login_milliseconds, 'ms')
コード例 #10
0
ファイル: horizon_check.py プロジェクト: rcbops/rpc-maas
def check(args):
    # disable warning for insecure cert on horizon
    if requests.__build__ >= 0x020400:
        requests.packages.urllib3.disable_warnings()

    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    is_up = True

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    OS_USER_DOMAIN_NAME = auth_details['OS_USER_DOMAIN_NAME']
    HORIZON_URL = '{protocol}://{ip}'.format(
        protocol=args.protocol,
        ip=args.ip,
    )
    HORIZON_PORT = args.port

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=180)
    except (exc.ConnectionError,
            exc.HTTPError,
            exc.Timeout) as e:
        is_up = False
        metric_bool('client_success', False, m_name='maas_horizon')
    else:
        if not (r.ok and
                re.search(args.site_name_regexp, r.content, re.IGNORECASE)):
            metric_bool('client_success', False, m_name='maas_horizon')
            status_err('could not load login page', m_name='maas_horizon')
        else:
            metric_bool('client_success', True, m_name='maas_horizon')
        splash_status_code = r.status_code
        splash_milliseconds = r.elapsed.total_seconds() * 1000

        parsed_html = html.fromstring(r.content)
        csrf_token = parsed_html.xpath(
            '//input[@name="csrfmiddlewaretoken"]/@value')[0]
        region = parsed_html.xpath(
            '//input[@name="region"]/@value')[0]
        domain = parsed_html.xpath('//input[@name="domain"]')
        s.headers.update(
            {'Content-type': 'application/x-www-form-urlencoded',
                'Referer': HORIZON_URL})
        payload = {'username': OS_USERNAME,
                   'password': OS_PASSWORD,
                   'csrfmiddlewaretoken': csrf_token,
                   'region': region}
        if domain:
            payload['domain'] = OS_USER_DOMAIN_NAME
        try:
            login_url = ('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT)
            if args.deploy_osp:
                login_url = ('%s:%s/dashboard/auth/login/') % (HORIZON_URL,
                                                               HORIZON_PORT)
            login_resp = s.post(login_url, data=payload, verify=False)
        except (exc.ConnectionError,
                exc.HTTPError,
                exc.Timeout) as e:
            status_err('While logging in: %s' % e, m_name='maas_horizon')

        search_phrase = 'overview'
        if args.deploy_osp:
            search_phrase = 'project'
        if not (login_resp.ok and re.search(search_phrase,
                                            login_resp.content,
                                            re.IGNORECASE)):
            status_err('could not log in', m_name='maas_horizon')

        login_status_code = login_resp.status_code
        login_milliseconds = login_resp.elapsed.total_seconds() * 1000

    status_ok(m_name='maas_horizon')
    metric_bool('horizon_local_status', is_up, m_name='maas_horizon')

    if is_up:
        metric('splash_status_code', 'uint32', splash_status_code, 'http_code')
        metric('splash_milliseconds', 'double', splash_milliseconds, 'ms')
        metric('login_status_code', 'uint32', login_status_code, 'http_code')
        metric('login_milliseconds', 'double', login_milliseconds, 'ms')
コード例 #11
0
def check(args):
    # disable warning for insecure cert on horizon
    if requests.__build__ >= 0x020400:
        requests.packages.urllib3.disable_warnings()

    splash_status_code = 0
    splash_milliseconds = 0.0
    login_status_code = 0
    login_milliseconds = 0.0

    is_up = True

    auth_details = get_auth_details()
    OS_USERNAME = auth_details['OS_USERNAME']
    OS_PASSWORD = auth_details['OS_PASSWORD']
    HORIZON_URL = 'https://{ip}'.format(ip=args.ip)
    HORIZON_PORT = '443'

    s = requests.Session()

    try:
        r = s.get('%s:%s' % (HORIZON_URL, HORIZON_PORT),
                  verify=False,
                  timeout=10)
    except (exc.ConnectionError,
            exc.HTTPError,
            exc.Timeout) as e:
        is_up = False
    else:
        if not (r.ok and
                re.search('openstack dashboard', r.content, re.IGNORECASE)):
            status_err('could not load login page')

        splash_status_code = r.status_code
        splash_milliseconds = r.elapsed.total_seconds() * 1000

        csrf_token = html.fromstring(r.content).xpath(
            '//input[@name="csrfmiddlewaretoken"]/@value')[0]
        region = html.fromstring(r.content).xpath(
            '//input[@name="region"]/@value')[0]
        s.headers.update(
            {'Content-type': 'application/x-www-form-urlencoded',
                'Referer': HORIZON_URL})
        payload = {'username': OS_USERNAME,
                   'password': OS_PASSWORD,
                   'csrfmiddlewaretoken': csrf_token,
                   'region': region}
        try:
            l = s.post(
                ('%s:%s/auth/login/') % (HORIZON_URL, HORIZON_PORT),
                data=payload,
                verify=False)
        except (exc.ConnectionError,
                exc.HTTPError,
                exc.Timeout) as e:
            status_err('While logging in: %s' % e)

        if not (l.ok and re.search('overview', l.content, re.IGNORECASE)):
            status_err('could not log in')

        login_status_code = l.status_code
        login_milliseconds = l.elapsed.total_seconds() * 1000

    metric_values = dict()

    status_ok()
    metric_bool('horizon_local_status', is_up)

    if is_up:

        metric('splash_status_code', 'uint32', splash_status_code, 'http_code')
        metric('splash_milliseconds', 'double', splash_milliseconds, 'ms')
        metric('login_status_code', 'uint32', login_status_code, 'http_code')
        metric('login_milliseconds', 'double', login_milliseconds, 'ms')

        metric_values['splash_status_code'] = splash_status_code
        metric_values['splash_milliseconds'] = splash_milliseconds
        metric_values['login_status_code'] = login_status_code
        metric_values['login_milliseconds'] = login_milliseconds
        metric_influx(INFLUX_MEASUREMENT_NAME, metric_values)