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
|
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Keystone monitoring script for Nagios
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Florian Lambert <florian.lambert@enovance.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/>.
#
#needed python-novaclient
#https://github.com/openstack/python-novaclient
import sys
import argparse
from novaclient.v1_1 import client
STATE_OK = 0
STATE_WARNING = 1
STATE_CRITICAL = 2
STATE_UNKNOWN = 3
#2 Warn = 1 Critical
def return_state(state):
global RETURN_STATE
global STATE_MESSAGE
RETURN_STATE += state
if RETURN_STATE > 1:
STATE_MESSAGE +=" does not work"
print STATE_MESSAGE
sys.exit(STATE_CRITICAL)
def collect_args():
parser = argparse.ArgumentParser(description='Check an OpenStack glance 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')
return parser
def check_novaapi(nt):
global RETURN_STATE
global STATE_MESSAGE
RETURN_STATE = STATE_OK
STATE_MESSAGE = "Failed -"
#flavors
if not len(nt.flavors.list(detailed=False)) >= 1:
STATE_MESSAGE +=" flavors.list >=1"
return_state(STATE_WARNING)
#servers
if not nt.servers.list():
STATE_MESSAGE +=" servers.list==false"
return_state(STATE_WARNING)
#images
if not len(nt.images.list(detailed=False)) >= 1:
STATE_MESSAGE +=" images.list >=1"
return_state(STATE_WARNING)
#security_groups
if not len(nt.security_groups.list()) >= 1:
STATE_MESSAGE +=" security_groups >=1"
return_state(STATE_WARNING)
if RETURN_STATE == STATE_WARNING:
STATE_MESSAGE +=" does not work"
print STATE_MESSAGE
else:
print "OK - Nova-api Connection established"
return RETURN_STATE
if __name__ == '__main__':
args = collect_args().parse_args()
try:
nt = client.Client(args.username,
args.password,
args.tenant,
args.auth_url,
service_type="compute")
sys.exit(check_novaapi(nt))
except Exception as e:
print str(e)
sys.exit(STATE_CRITICAL)
|