This file is indexed.

/usr/share/munin-openstack/plugins/keystone_stats is in munin-plugins-openstack 1.20120627-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env python
#
# Copyright (C) 2012 eNovance <licensing@enovance>
# 
# Authors: Mehdi Abaakouk <sileht@sileht.net>
#          Gael Lambert <gael.lambert@enovance.com>
#          Jesse Andrews <anotherjesse@rackspace.com>
#
# 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/>.
#
#
# Plugin to monitor status of Keystone
#
# Needs following minimal configuration in plugin-conf.d/keystone:
#   [keystone_*]
#   user keystone
#
# Magic markers
#%# capabilities=autoconf
#%# family=auto

import sys
import traceback

try:
    from keystone.common import utils
    from keystone import config
    from keystone import exception
    from keystone import identity
except ImportError:
    succesful_import = False
else:
    succesful_import = True

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'
    print 'graph_category keystone'
    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
    
    # 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)

def load_conf():
    config.CONF(config_files=[utils.find_config('keystone.conf')])

if __name__ == '__main__':
    if len(sys.argv) > 1:
        if sys.argv[1] == "config":
            print_config()
        elif sys.argv[1] == "autoconf":
            if not succesful_import:  
                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'

    elif succesful_import:
        load_conf()
        print_values()