Convert glance checks in python
This commit is contained in:
parent
6c53a8fbeb
commit
de102596c9
|
@ -0,0 +1 @@
|
|||
oschecks/amqp.py
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Openstack Monitoring script for Sensu / Nagios
|
||||
#
|
||||
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author:Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oschecks import utils
|
||||
|
||||
|
||||
def check_glance_api():
|
||||
glance = utils.Glance()
|
||||
glance.add_argument('-w', dest='warning', type=int, default=5,
|
||||
help='Warning timeout for Glance APIs calls')
|
||||
glance.add_argument('-c', dest='critical', type=int, default=10,
|
||||
help='Critical timeout for Glance APIs calls')
|
||||
options, args, client = glance.setup()
|
||||
|
||||
def images_list():
|
||||
return list(client.images.list())
|
||||
|
||||
elapsed, images = utils.timeit(images_list)
|
||||
if not images:
|
||||
utils.critical("Unable to contact Glance API.")
|
||||
|
||||
if elapsed > options.critical:
|
||||
utils.critical("Get images took more than %d seconds, "
|
||||
"it's too long.|response_time=%d" %
|
||||
(options.critical, elapsed))
|
||||
elif elapsed > options.warning:
|
||||
utils.warning("Get images took more than %d seconds, "
|
||||
"it's too long.|response_time=%d" %
|
||||
(options.warning, elapsed))
|
||||
else:
|
||||
utils.ok("Get images, Glance API is working: "
|
||||
"list %d images in %d seconds.|response_time=%d" %
|
||||
(len(images), elapsed, elapsed))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.safe_run(check_glance_api)
|
|
@ -0,0 +1,72 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Openstack Monitoring script for Sensu / Nagios
|
||||
#
|
||||
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author:Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oschecks import utils
|
||||
|
||||
|
||||
def check_glance():
|
||||
glance = utils.Glance()
|
||||
glance.add_argument('--req_count', dest='req_count', type=str,
|
||||
required=False,
|
||||
help='minimum number of images in glance')
|
||||
glance.add_argument('--req_images', metavar='req_images', type=str,
|
||||
nargs='+', required=False,
|
||||
help='name of images who must be available')
|
||||
options, args, client = glance.setup()
|
||||
|
||||
#Flags resultat
|
||||
valid_image = 0
|
||||
count = 0
|
||||
if options.req_count:
|
||||
required_count = int(options.req_count)
|
||||
if (len(client.get_images(**{"limit": required_count}))
|
||||
>= required_count):
|
||||
count = 1
|
||||
|
||||
if options.req_images:
|
||||
required_images = options.req_images
|
||||
for image in required_images:
|
||||
try:
|
||||
if len(client.get_images(**{"filters": {"name": image}})) == 1:
|
||||
valid_image = valid_image + 1
|
||||
except:
|
||||
pass
|
||||
|
||||
if options.req_count and count == 0:
|
||||
utils.critical("Failed - less than %d images found" % (required_count))
|
||||
|
||||
if options.req_images and valid_image < len(required_images):
|
||||
utils.critical("Failed - '%s' %d/%d images found " %
|
||||
(", ".join(required_images), valid_image,
|
||||
len(required_images)))
|
||||
|
||||
if options.req_images and options.req_count:
|
||||
utils.ok("image %s found and enough images >=%d" %
|
||||
(", ".join(required_images), required_count))
|
||||
elif options.req_images:
|
||||
utils.ok("image %s found" % (", ".join(required_images)))
|
||||
elif options.req_count:
|
||||
utils.ok("more than %d images found" % (count))
|
||||
else:
|
||||
utils.ok("Connection glance established")
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.safe_run(check_glance)
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Openstack Monitoring script for Sensu / Nagios
|
||||
#
|
||||
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
|
||||
#
|
||||
# Author:Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from oschecks import utils
|
||||
|
||||
|
||||
def check_glance_upload():
|
||||
glance = utils.Glance()
|
||||
glance.add_argument('--monitoring-image', dest='image_name', type=str,
|
||||
default="openstack-monitoring-test-image",
|
||||
help='Name of the monitoring image')
|
||||
options, args, client = glance.setup()
|
||||
|
||||
data_raw = "X" * 1024 * 1024
|
||||
elapsed, res = utils.timeit(client.images.create,
|
||||
data=data_raw,
|
||||
disk_format='raw',
|
||||
container_format='bare',
|
||||
name=options.image_name)
|
||||
if not res or not res.id or res.status != 'active':
|
||||
utils.critical("Unable to upload image in Glance")
|
||||
|
||||
res.delete()
|
||||
|
||||
if elapsed > 20:
|
||||
utils.warning("Upload image in 20 seconds, it's too long")
|
||||
else:
|
||||
utils.ok("OK - Glance image uploaded in %s seconds" % elapsed)
|
||||
|
||||
if __name__ == '__main__':
|
||||
utils.safe_run(check_glance_upload)
|
|
@ -1,118 +0,0 @@
|
|||
#!/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/>.
|
||||
#
|
||||
|
||||
|
||||
import sys
|
||||
import os
|
||||
import argparse
|
||||
from glanceclient import client as gclient
|
||||
|
||||
STATE_OK = 0
|
||||
STATE_WARNING = 1
|
||||
STATE_CRITICAL = 2
|
||||
STATE_UNKNOWN = 3
|
||||
|
||||
def collect_args():
|
||||
|
||||
parser = argparse.ArgumentParser(description='Check an OpenStack glance server.')
|
||||
parser.add_argument('--auth_url', metavar='URL', type=str,
|
||||
default=os.getenv('OS_AUTH_URL'),
|
||||
help='Keystone URL')
|
||||
parser.add_argument('--username', metavar='username', type=str,
|
||||
default=os.getenv('OS_USERNAME'),
|
||||
help='username to use for authentication')
|
||||
parser.add_argument('--password', metavar='password', type=str,
|
||||
default=os.getenv('OS_PASSWORD'),
|
||||
help='password to use for authentication')
|
||||
parser.add_argument('--tenant', metavar='tenant', type=str,
|
||||
default=os.getenv('OS_TENANT_NAME'),
|
||||
help='tenant name to use for authentication')
|
||||
parser.add_argument('--req_count', metavar='numberImages', type=str,
|
||||
required=False,
|
||||
help='minimum number of images in glance')
|
||||
parser.add_argument('--req_images', metavar='imagesName', type=str, nargs='+',
|
||||
required=False,
|
||||
help='name of images who must be available')
|
||||
parser.add_argument('--region_name', metavar='region_name', type=str,
|
||||
help='Region to select for authentication')
|
||||
return parser
|
||||
|
||||
|
||||
|
||||
def check_glance(c,args):
|
||||
#Flags resultat
|
||||
valid_image = 0
|
||||
count = 0
|
||||
|
||||
|
||||
if args.req_count :
|
||||
required_count = int(args.req_count)
|
||||
if len(c.get_images(**{"limit": required_count})) >= required_count:
|
||||
count = 1
|
||||
|
||||
#filters = {}
|
||||
#filters['name'] = "Debian GNU/Linux 6.0.4 amd64"
|
||||
#filters['container_format'] = "ami"
|
||||
|
||||
if args.req_images :
|
||||
required_images = args.req_images
|
||||
|
||||
for image in required_images:
|
||||
try:
|
||||
if len(c.get_images(**{"filters": {"name": image}})) == 1:
|
||||
valid_image = valid_image + 1
|
||||
except :
|
||||
pass
|
||||
|
||||
#parameters = {"filters": filters, "limit": limit}
|
||||
#images = c.get_images(**parameters)
|
||||
|
||||
|
||||
if args.req_count and count == 0:
|
||||
print "Failed - less than %d images found" % (required_count)
|
||||
sys.exit(STATE_CRITICAL)
|
||||
|
||||
|
||||
if args.req_images and valid_image < len(required_images):
|
||||
print "Failed - '%s' %d/%d images found " % (required_images,valid_image,len(required_images))
|
||||
sys.exit(STATE_WARNING)
|
||||
|
||||
|
||||
if args.req_images and args.req_count:
|
||||
print "OK - image %s found and enough images >=%d" % (required_images,required_count)
|
||||
elif args.req_images:
|
||||
print "OK - image %s found" % (required_images)
|
||||
elif args.req_count:
|
||||
print "OK - more than %d images found" % (count)
|
||||
else :
|
||||
print "OK - Connection glance established"
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
args = collect_args().parse_args()
|
||||
try:
|
||||
c = gclient.Client('1','')
|
||||
sys.exit(check_glance(c,args))
|
||||
except Exception as e:
|
||||
print str(e)
|
||||
sys.exit(STATE_CRITICAL)
|
|
@ -0,0 +1 @@
|
|||
../oschecks
|
Loading…
Reference in New Issue