File: check_keystone

package info (click to toggle)
nagios-plugins-openstack 1.20120627-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 164 kB
  • sloc: python: 525; sh: 121; makefile: 2
file content (93 lines) | stat: -rwxr-xr-x 3,339 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Keystone monitoring script for Nagios
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import sys
import argparse
from keystoneclient.v2_0 import client
from keystoneclient import exceptions


STATE_OK = 0
STATE_WARNING = 1
STATE_CRITICAL = 2
STATE_UNKNOWN = 3


parser = argparse.ArgumentParser(description='Check an OpenStack Keystone server.')
parser.add_argument('--auth_url', metavar='URL', type=str,
                    required=True,
                    help='Keystone URL')
parser.add_argument('--username', metavar='username', type=str,
                    required=True,
                    help='username to use for authentication')
parser.add_argument('--password', metavar='password', type=str,
                    required=True,
                    help='password to use for authentication')
parser.add_argument('--tenant', metavar='tenant', type=str,
                    required=True,
                    help='tenant name to use for authentication')
parser.add_argument('--region_name', metavar='region_name', type=str,
                    help='Region to select for authentication')
parser.add_argument('--no-admin', action='store_true', default=False,
                    help='Don\'t perform admin tests, useful if user is not admin')
parser.add_argument('services', metavar='SERVICE', type=str, nargs='*',
                    help='services to check for')
args = parser.parse_args()


try:
    c = client.Client(username=args.username,
                  tenant_name=args.tenant,
                  password=args.password,
                  auth_url=args.auth_url,
                  region_name=args.region_name)
    if not c.authenticate():
        raise Exception("Authentication failed")
    if not args.no_admin:
        if not c.tenants.list():
            raise Exception("Tenant list is empty")
except Exception as e:
    print str(e)
    sys.exit(STATE_CRITICAL)

msgs = []
endpoints = c.service_catalog.get_endpoints()
services = args.services or endpoints.keys()
for service in services:
    if not service in endpoints.keys():
        msgs.append("`%s' service is missing" % service)
        continue

    if not len(endpoints[service]):
        msgs.append("`%s' service is empty" % service)
        continue

    if not any([ "publicURL" in endpoint.keys() for endpoint in endpoints[service] ]):
        msgs.append("`%s' service has no publicURL" % service)

if msgs:
    print ", ".join(msgs)
    sys.exit(STATE_WARNING)

print "Got token %s for user %s and tenant %s" % (c.auth_token, c.auth_user_id, c.auth_tenant_id)
sys.exit(STATE_OK)