2012-05-02 08:34:55 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Plugin to monitor status of Keystone
|
|
|
|
#
|
|
|
|
# Needs following minimal configuration in plugin-conf.d/keystone:
|
|
|
|
# [keystone_*]
|
|
|
|
# user keystone
|
|
|
|
#
|
|
|
|
# Magic markers
|
|
|
|
#%# capabilities=autoconf
|
2012-05-03 16:48:19 +02:00
|
|
|
#%# family=auto
|
2012-05-02 08:34:55 +02:00
|
|
|
|
|
|
|
import sys
|
2012-05-03 16:48:19 +02:00
|
|
|
import traceback
|
|
|
|
|
|
|
|
try:
|
|
|
|
from keystone.common import utils
|
|
|
|
from keystone import config
|
|
|
|
from keystone import exception
|
|
|
|
from keystone import identity
|
|
|
|
except ImportError:
|
2014-12-05 00:37:42 +01:00
|
|
|
successful_import = False
|
2012-05-03 16:48:19 +02:00
|
|
|
else:
|
2014-12-05 00:37:42 +01:00
|
|
|
successful_import = True
|
2012-05-02 08:34:55 +02:00
|
|
|
|
|
|
|
stats = ['users', 'tenants']
|
|
|
|
|
|
|
|
def print_config():
|
|
|
|
global states
|
|
|
|
print 'graph_title Keystone Stats'
|
|
|
|
print 'graph_vlabel count'
|
|
|
|
print 'graph_args --base 1000 --lower-limit 0'
|
2018-03-28 04:33:45 +02:00
|
|
|
print 'graph_category auth'
|
2012-05-02 08:34:55 +02:00
|
|
|
print 'graph_scale no'
|
|
|
|
print 'graph_info This graph shows stats about keystone: ' + (', ').join(stats)
|
|
|
|
for field in stats:
|
|
|
|
print '%s_enabled.label enabled %s' % (field, field)
|
|
|
|
print '%s_enabled.draw LINE2' % field
|
|
|
|
print '%s_enabled.info %s enabled' % (field, field)
|
|
|
|
print '%s_total.label total %s' % (field, field)
|
|
|
|
print '%s_total.draw LINE2' % field
|
|
|
|
print '%s_total.info %s total' % (field, field)
|
|
|
|
|
|
|
|
|
|
|
|
def get_status():
|
|
|
|
enabled = {}
|
|
|
|
total = {}
|
|
|
|
for k in stats:
|
|
|
|
enabled[k] = 0
|
|
|
|
total[k] = 0
|
|
|
|
|
|
|
|
identity_api = identity.Manager()
|
|
|
|
|
|
|
|
for user in identity_api.list_users(None):
|
|
|
|
total['users'] += 1
|
|
|
|
if user['enabled']:
|
|
|
|
enabled['users'] += 1
|
2018-08-02 02:03:42 +02:00
|
|
|
|
2012-05-02 08:34:55 +02:00
|
|
|
# Ldap and pam driver don't support get_all_tenants()
|
|
|
|
# kvs and sql implement get_tenants() instead of get_all_tenants()
|
|
|
|
# Whoo: None of backend implements the correct function
|
|
|
|
tenants = []
|
|
|
|
for api_func in [ 'get_all_tenants', 'get_tenants']:
|
|
|
|
try:
|
|
|
|
tenants = getattr(identity_api, api_func)(None)
|
|
|
|
except exception.NotImplemented, NotImplementedError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
for tenant in tenants:
|
|
|
|
total['tenants'] += 1
|
|
|
|
if tenant['enabled']:
|
|
|
|
enabled['tenants'] += 1
|
|
|
|
|
|
|
|
return {'enabled': enabled, 'total': total}
|
|
|
|
|
|
|
|
|
|
|
|
def print_values():
|
|
|
|
stats = get_status()
|
|
|
|
for state in stats.keys():
|
|
|
|
for (field, value) in stats[state].iteritems():
|
|
|
|
print "%s_%s.value %s" % (field, state, value)
|
|
|
|
|
2012-05-03 16:48:19 +02:00
|
|
|
def load_conf():
|
2012-05-22 11:19:19 +02:00
|
|
|
config.CONF(config_files=[utils.find_config('keystone.conf')])
|
2012-05-02 08:34:55 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
if sys.argv[1] == "config":
|
|
|
|
print_config()
|
|
|
|
elif sys.argv[1] == "autoconf":
|
2018-08-02 02:03:42 +02:00
|
|
|
if not successful_import:
|
2012-05-03 16:48:19 +02:00
|
|
|
print 'no (failed import keystone module)'
|
|
|
|
sys.exit(0)
|
|
|
|
try:
|
|
|
|
load_conf()
|
|
|
|
identity.Manager()
|
|
|
|
except:
|
|
|
|
print 'no (failed to connect keystone backend: %s'%traceback.format_exc()
|
|
|
|
sys.exit(0)
|
|
|
|
print 'yes'
|
|
|
|
|
2014-12-05 00:37:42 +01:00
|
|
|
elif successful_import:
|
2012-05-03 16:48:19 +02:00
|
|
|
load_conf()
|
2012-05-02 08:34:55 +02:00
|
|
|
print_values()
|
|
|
|
|