Cleanup all scripts

This commit is contained in:
Mehdi Abaakouk 2014-09-29 15:52:17 +02:00
parent 32356f36be
commit 667fe4ae23
29 changed files with 0 additions and 2142 deletions

View File

@ -1,29 +0,0 @@
#!/bin/bash
#
# Ceilometer Central Agent monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
. `dirname $0`/functions.sh
DAEMON='ceilometer-agent-central'
check_usage
check_running_and_amqp_connected $DAEMON

View File

@ -1,29 +0,0 @@
#!/bin/bash
#
# Ceilometer Compute Agent monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
. `dirname $0`/functions.sh
DAEMON='ceilometer-agent-compute'
check_usage
check_running_and_amqp_connected $DAEMON

View File

@ -1,62 +0,0 @@
#!/bin/bash
#
# Ceilometer API monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
. `dirname $0`/functions.sh
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which ceilometer >/dev/null 2>&1
then
echo "python-ceilometerclient is not installed."
exit $STATE_UNKNOWN
fi
if ! KEY=$(ceilometer meter-list 2>/dev/null)
then
echo "Unable to list meters"
exit $STATE_CRITICAL
fi
count=$(($(ceilometer meter-list 2>/dev/null | wc -l)-4))
echo "Ceilometer API is working with $count meters."

View File

@ -1,29 +0,0 @@
#!/bin/bash
#
# Ceilometer Collector monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
set -e
. `dirname $0`/functions.sh
DAEMON='ceilometer-collector'
check_usage
check_running_and_amqp_connected $DAEMON

View File

@ -1,95 +0,0 @@
#!/bin/bash
# Ceilometer API monitoring script for Sensu / Nagios
#
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Guillaume Abrioux <guillaume.abrioux@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl
#
set -e
. `dirname $0`/functions.sh
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -E <Endpoint URL> URL for ceilometer API. Ex: http://localhost:8777/v1"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use ro get an auth token"
}
while getopts 'hH:U:T:P:E:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service metering|grep publicURL|cut -d'|' -f3)"}
if ! which curl >/dev/null 2>&1
then
echo "curl is not installed."
exit $STATE_UNKNOWN
fi
TOKEN=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'" ,"tenant":"'$OS_TENANT_NAME'"}}}' -H 'Content-type: application/json' |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["access"]["token"]["id"]')
TENANT_ID=$(curl -s -H "X-Auth-Token: $TOKEN" ${OS_AUTH_URL}/tenants |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["tenants"][0]["id"]')
TOKEN2=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"} ,"tenantId":"'$TENANT_ID'"}}' -H 'Content-type: application/json' |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["access"]["token"]["id"]')
if [ -z "$TOKEN2" ]; then
echo "Unable to get a token from Keystone API"
exit $STATE_CRITICAL
fi
RES=$(curl -s -H "X-Auth-Token: $TOKEN2" -H 'Content-Type: application/json' ${ENDPOINT_URL}/projects | grep -o project -c)
if [ -z "$RES" ]; then
echo "Unable to get projects"
exit $STATE_CRITICAL
else
echo "Ceilometer API is working."
fi

View File

@ -1,64 +0,0 @@
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
check_running () {
PID=`pidof -x "$1" || true`
if [ -z "$PID" ]; then
echo "$DAEMON is not running."
exit $STATE_CRITICAL
fi
echo $PID
}
check_running_and_amqp_connected () {
if [ "$(id -u)" != "0" ]; then
echo "$DAEMON is running but the script must be run as root"
exit $STATE_WARNING
fi
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
# check_running can return multiple PIDs
for PID in `check_running $1`
do
# Need root to "run netstat -p"
KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}")
if ! test -z "$KEY"
then
echo "$DAEMON is working."
exit $STATE_OK
fi
done
echo "$DAEMON is not connected to AMQP"
exit $STATE_CRITICAL
}
show_usage () {
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
check_usage () {
while getopts 'h' OPTION
do
case $OPTION in
h)
show_usage
exit 0
;;
*)
show_usage
exit 1
;;
esac
done
}

View File

@ -1,69 +0,0 @@
#!/usr/bin/env ruby
#
# Simple ceph df check (using ceph commands)
#
# Copyright (C) 2013-2014 eNovance SAS <licensing@enovance.com>
#
# Author: Sebastien Badia <sebastien.badia@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.
#
require 'rubygems' if RUBY_VERSION < '1.9.0'
require 'json'
# Monitoring return codes
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
DEPENDENT = 4
warn_percent = ARGV[0] || 85
crit_percent = ARGV[1] || 98
begin
data = JSON.load(`ceph df --format=json`)
rescue
puts '[WARN] ceph not found ?'
exit WARNING
end
total = data['stats']['total_space']
used = data['stats']['total_used']
avail = data['stats']['total_avail']
def per(percent,value)
return (percent.to_f / 100) * value
end # def:: per(percent,value)
def remaning(avail,total)
return "(#{avail/1024}MB/#{total/1024}MB)"
end # def:: avail
# Test correctness of values
if ( used + avail ) != total
puts '[ERR] Used + Avail. != Total space'
exit WARNING
end
if (avail < per(crit_percent,total))
puts "[ERR] Ceph df avail. critical #{remaning(avail,total)}"
exit CRITICAL
elsif (avail < per(warn_percent,total))
puts "[WARN] Ceph df avail. warning #{remaning(avail,total)}"
exit WARNING
else
puts "[OK] Ceph df avail. seems good #{remaning(avail,total)}"
exit OK
end

View File

@ -1,107 +0,0 @@
#!/bin/bash
# Cinder API monitoring script
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -E <Endpoint URL> URL for cinder API. Ex: http://localhost:8776/v1/"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use ro get an auth token"
}
while getopts 'h:H:E:U:T:P:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service volume|grep publicURL|cut -d'|' -f3|sed 's/\s*//g')"}
if ! which curl >/dev/null 2>&1
then
echo "curl is not installed."
exit $STATE_UNKNOWN
fi
# Get a token from Keystone
TOKEN=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}, "tenantName":"'$OS_TENANT_NAME'"}}' -H 'Content-type: application/json' |sed -e 's/[{}]/''/g' | awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}'|awk 'NR==3'|awk '{print $2}'|sed -n 's/.*"\([^"]*\)".*/\1/p')
if [ -z "$TOKEN" ]; then
echo "Unable to get a token from Keystone API"
exit $STATE_CRITICAL
fi
START=`date +%s`
QUOTAS=$(curl -s -H "X-Auth-Token: $TOKEN" "${ENDPOINT_URL}/os-quota-sets/${OS_TENANT_NAME}/defaults" | grep "gigabytes")
END=`date +%s`
TIME=$((END-START))
if [ -z "$QUOTAS" ]; then
echo "Unable to list quotas"
exit $STATE_CRITICAL
else
if [ "$TIME" -gt "10" ]; then
echo "Get quotas after 10 seconds, it's too long."
exit $STATE_WARNING
else
echo "Get quotas, Cinder API is working: list quotas in $TIME seconds."
exit $STATE_OK
fi
fi

View File

@ -1,79 +0,0 @@
#!/bin/bash
#
# Cinder Scheduler monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='cinder-scheduler'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,81 +0,0 @@
#!/bin/bash
#
# Cinder Volume monitoring script
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='cinder-volume'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
PID=$(ps -f --ppid ${PID} | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,170 +0,0 @@
#!/bin/bash
# Glance API monitoring script for Sensu / Nagios
#
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
# Nicolas Auvray <nicolas.auvray@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl, bc, awk
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -E <Endpoint URL> URL for glance API. Ex: http://localhost:9292/v1"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use to get an auth token"
echo " -k <timeout> Timeout for Keystone APIs calls. Default to 5 seconds"
echo " -w <warning> Warning timeout for Glance APIs calls. Default to 5 seconds"
echo " -c <critical> Critical timeout for Glance APIs calls. Default to 10 seconds"
}
while getopts 'hH:U:T:P:E:k:w:c:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
k)
[[ $OPTARG =~ ^[0-9]+$ ]] && export KS_TIMEOUT=$OPTARG || (echo "Timeout must be an entire numeric value"; usage)
;;
w)
[[ $OPTARG =~ ^[0-9]+$ ]] && export W_TIMEOUT=$OPTARG || (echo "Timeout must be an entire numeric value"; usage)
;;
c)
[[ $OPTARG =~ ^[0-9]+$ ]] && export C_TIMEOUT=$OPTARG || (echo "Timeout must be an entire numeric value"; usage)
;;
*)
usage
exit 1
;;
esac
done
# User must provide at least non-empty parameters
[[ -z "${OS_TENANT_NAME}" || -z "${OS_USERNAME}" || -z "${OS_PASSWORD}" ]] && (usage; exit 1)
# If no timeout is specified
[[ -z $KS_TIMEOUT ]] && export KS_TIMEOUT=5
[[ -z $W_TIMEOUT ]] && export W_TIMEOUT=5
[[ -z $C_TIMEOUT ]] && export C_TIMEOUT=10
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service image|grep publicURL|cut -d'|' -f3)"}
# return a json value (key=value, num=position)
function getJson() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p | sed 's/^ //'
}
# Requirements
[ ! which curl >/dev/null 2>&1 ] && (echo "curl is not installed.";exit $STATE_UNKNOWN)
[ ! which bc >/dev/null 2>&1 ] && (echo "bc is not installed.";exit $STATE_UNKNOWN)
[ ! which awk >/dev/null 2>&1 ] && (echo "awk is not installed.";exit $STATE_UNKNOWN)
# Get a token from Keystone
KS_RESP=$(curl -s -m $KS_TIMEOUT -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'" ,"tenant":"'$OS_TENANT_NAME'"}}}' -H 'Content-type: application/json' || true)
if [ ! -z "${KS_RESP}" ]; then
# We take the first ID value as it represents the keystone token
TOKEN=$(echo ${KS_RESP} | getJson id 1)
if [ -z "${TOKEN}" ]; then
echo "CRITICAL: Unable to get token #1 from Keystone API"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL: Unable to reach Keystone API"
exit $STATE_CRITICAL
fi
# Use the token to get a tenant ID. By default, it takes the second tenant
unset KS_RESP
KS_RESP=$(curl -s -m $KS_TIMEOUT -H "X-Auth-Token: $TOKEN" ${OS_AUTH_URL}/tenants || true)
if [ ! -z "${KS_RESP}" ]; then
TENANT_ID=$(echo ${KS_RESP} | getJson id 1)
if [ -z "$TENANT_ID" ]; then
echo "CRITICAL: Unable to get my tenant ID from Keystone API"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL: Unable to reach Keystone API"
exit $STATE_CRITICAL
fi
# Once we have the tenant ID, we can request a token that will have access to the Glance API
unset KS_RESP
KS_RESP=$(curl -s -m $KS_TIMEOUT -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"} ,"tenantId":"'$TENANT_ID'"}}' -H 'Content-type: application/json' || true)
if [ ! -z "${KS_RESP}" ]; then
TOKEN2=$(echo ${KS_RESP} | getJson id 1)
if [ -z "$TOKEN2" ]; then
echo "CRITICAL: Unable to get token #2 from Keystone API"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL: Unable to reach Keystone API"
exit $STATE_CRITICAL
fi
START=$(date +%s.%N)
IMAGES=$(curl -s -m $C_TIMEOUT -H "X-Auth-Token: $TOKEN2" -H 'Content-Type: application/json' -H 'User-Agent: python-glanceclient' ${ENDPOINT_URL}/images/detail?sort_key=name&sort_dir=asc&limit=10 || true)
N_IMAGES=$(echo $IMAGES | grep -Po '"name":.*?[^\\]",'| wc -l)
END=$(date +%s.%N)
TIME=$(echo ${END} - ${START} | bc)
if [[ -z $IMAGES ]]; then
echo "CRITICAL: Unable to contact Glance API. Either Glance service is not running or timeout of ${C_TIMEOUT}s has been reached."
exit $STATE_CRITICAL
elif [[ ! "$IMAGES" == *status* ]]; then
echo "CRITICAL: Unable to list images from Glance API"
exit $STATE_CRITICAL
else
if [ $(echo ${TIME}'>'$W_TIMEOUT | bc -l) -gt 0 ]; then
echo "WARNING: Get images took more than $W_TIMEOUT seconds, it's too long.|response_time=${TIME}"
exit $STATE_WARNING
else
echo "OK: Get images, Glance API is working: list $N_IMAGES images in $TIME seconds.|response_time=${TIME}"
exit $STATE_OK
fi
fi

View File

@ -1,139 +0,0 @@
#!/bin/bash
#
# Glance Image Upload monitoring script for Sensu / Nagios
#
# Copyright © 2014 eNovance <licensing@enovance.com>
#
# Author: Gaëtan Trellu <gaetan.trellu@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl python
#
# Nagios/Sensu return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
# Random string with 5 chars
RANDOM_STRING=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 5 | head -n 1)
# Script options
TOKEN_FILE="/tmp/token_check_glance_$RANDOM_STRING"
TENANT_ID_FILE="/tmp/tenant_id_check_glance_$RANDOM_STRING"
IMAGE_ID_FILE="/tmp/image_id_check_glance_$RANDOM_STRING"
GLANCE_API_VERSION="v1"
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -E <Endpoint URL> URL for glance API. Ex: http://localhost:9292/v1"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use to get an auth token"
echo " -N <name> Name of the monitoring image"
}
output_result () {
# Output check result & refresh cache if requested
MSG="$1"
RETCODE=$2
echo "$MSG"
exit $RETCODE
}
while getopts 'hH:U:T:P:N:E:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
N)
export IMAGE_NAME=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service image|grep publicURL|cut -d'|' -f3|sed 's/\s*//g')"}
if ! which curl >/dev/null 2>&1
then
output_result "UNKNOWN - curl is not installed." $STATE_UNKNOWN
fi
# Get a token from Keystone
TOKEN=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}, "tenantName":"'$OS_TENANT_NAME'"}}' -H 'Content-type: application/json' |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["access"]["token"]["id"]')
# Use the token to get a tenant ID. By default, it takes the second tenant
TENANT_ID=$(curl -s -H "X-Auth-Token: $TOKEN" ${OS_AUTH_URL}/tenants |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["tenants"][0]["id"]')
START=`date +%s`
# Generate an image file (1MB)
( dd if=/dev/zero of=/tmp/"$IMAGE_NAME".img bs=1M count=1 ) > /dev/null 2>&1
# Upload the image
curl -s -d "<open file /tmp/"$IMAGE_NAME".img, mode 'r' at 0x7fc48f5b4151>" -X POST -H "X-Auth-Token: $TOKEN" -H "x-image-meta-container_format: bare" -H "Transfer-Encoding: chunked" -H "User-Agent: python-glanceclient" -H "Content-Type: application/octet-stream" -H "x-image-meta-disk_format: qcow2" -H "x-image-meta-name: $IMAGE_NAME" "$ENDPOINT_URL"/"$GLANCE_API_VERSION"/images | python -mjson.tool | awk -v var="\"id\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $IMAGE_ID_FILE
if [ -s $IMAGE_ID_FILE ]
then
IMAGE_ID=$(cat $IMAGE_ID_FILE)
else
output_result "CRITICAL - Unable to upload image in Glance" $STATE_CRITICAL
fi
rm -f /tmp/"$IMAGE_NAME".img
# Delete the image
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$GLANCE_API_VERSION"/images/"$IMAGE_ID" -X DELETE > /dev/null 2>&1
END=`date +%s`
TIME=$((END-START))
if [ $TIME -gt 60 ]; then
output_result "CRITICAL - Unable to upload image in Glance" $STATE_CRITICAL
else
if [ "$TIME" -gt "20" ]; then
output_result "WARNING - Upload image in 20 seconds, it's too long" $STATE_WARNING
else
output_result "OK - Glance image uploaded in $TIME seconds" $STATE_OK
fi
fi

View File

@ -1,80 +0,0 @@
#!/bin/bash
#
# Glance Registry monitoring script for Sensu / Nagios
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Gaëtan Trellu <gaetan.trellu@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement:netstat
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='glance-registry'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(pgrep $DEAMON | head -1)
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,79 +0,0 @@
#!/bin/bash
#
# Heat engine monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='heat-engine'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h:H:U:T:P:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+$DEAMON/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,95 +0,0 @@
#!/bin/bash
#
# Keystone API monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl, bc
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -H <Auth URL> URL for obtaining an auth token. Ex : http://localhost:5000/v2.0"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use ro get an auth token"
}
while getopts 'hH:U:P:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
if ! which curl >/dev/null 2>&1
then
echo "curl is not installed."
exit $STATE_UNKNOWN
fi
if ! which bc >/dev/null 2>&1
then
echo "bc is not installed."
exit $STATE_UNKNOWN
fi
START=`date +%s.%N`
TOKEN=$(curl -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}}}' -H 'Content-type: application/json' 2>&1 | grep token|awk '{print $6}'|grep -o '".*"' | sed -n 's/.*"\([^"]*\)".*/\1/p')
END=`date +%s.%N`
TIME=`echo ${END} - ${START} | bc`
if [ -z "$TOKEN" ]; then
echo "Unable to get a token"
exit $STATE_CRITICAL
else
if [ `echo ${TIME}'>'10 | bc -l` -gt 0 ]; then
echo "Got a token after 10 seconds, it's too long.|response_time=${TIME}"
exit $STATE_WARNING
else
echo "Got a token, Keystone API is working.|response_time=${TIME}"
exit $STATE_OK
fi
fi

View File

@ -1,173 +0,0 @@
#!/bin/bash
#
# Neutron server monitoring script
#
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
# Nicolas Auvray <nicolas.auvray@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl, netstat, awk, bc
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='neutron-server'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo ""
echo "Required parameters :"
echo " -T <tenant name> Tenant name to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use to get an auth token"
echo ""
echo "Optional parameters :"
echo " -H <Auth URL> URL for obtaining an auth token. Default: http://localhost:5000/v2.0"
echo " -E <Endpoint URL> URL for neutron API. Default is to get endpoint URL from keystone catalog. Example: http://localhost:9696"
echo " -m <AMQP port> Port on which your AMQP server is listening. Default: 5672"
echo " -k <timeout> Timeout for Keystone APIs calls. Default to 5 seconds"
echo " -w <warning> Warning timeout for Neutron API calls. Default to 5 seconds"
echo " -c <critical> Critical timeout for Neutron API calls. Default to 10 seconds"
}
while getopts 'hH:U:T:P:E:m:k:w:c:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
m)
[[ $OPTARG =~ ^[0-9]+$ ]] && export AMQP_PORT=$OPTARG || (echo "AMQP port must be an entire numeric value"; usage)
;;
k)
[[ $OPTARG =~ ^[0-9]+$ ]] && export KS_TIMEOUT=$OPTARG || (echo "Keystone timeout must be an entire numeric value"; usage)
;;
w)
[[ $OPTARG =~ ^[0-9]+$ ]] && export W_TIMEOUT=$OPTARG || (echo "Warning timeout must be an entire numeric value"; usage)
;;
c)
[[ $OPTARG =~ ^[0-9]+$ ]] && export C_TIMEOUT=$OPTARG || (echo "Critical timeout must be an entire numeric value"; usage)
;;
*)
usage
exit 1
;;
esac
done
# User must provide at least non-empty parameters
[[ -z "${OS_TENANT_NAME}" || -z "${OS_USERNAME}" || -z "${OS_PASSWORD}" ]] && (usage; exit 1)
# If not timeout is specified
[[ -z $KS_TIMEOUT ]] && export KS_TIMEOUT=5
[[ -z $W_TIMEOUT ]] && export W_TIMEOUT=5
[[ -z $C_TIMEOUT ]] && export C_TIMEOUT=10
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service network|grep publicURL|cut -d'|' -f3|sed 's/\s*//g')"}
AMQP_PORT=${AMQP_PORT:-5672}
# Requirements
[ ! which curl >/dev/null 2>&1 ] && (echo "curl is not installed.";exit $STATE_UNKNOWN)
[ ! which bc >/dev/null 2>&1 ] && (echo "bc is not installed.";exit $STATE_UNKNOWN)
[ ! which awk >/dev/null 2>&1 ] && (echo "awk is not installed.";exit $STATE_UNKNOWN)
[ ! which netstat >/dev/null 2>&1 ] && (echo "netstat is not installed.";exit $STATE_UNKNOWN)
# return a json value (key=value, num=position)
function getJson() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p | sed 's/^ //'
}
# Try to get an auth token from keystone API
KS_RESP=$(curl -s -m $KS_TIMEOUT -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}, "tenantName":"'$OS_TENANT_NAME'"}}' -H 'Content-type: application/json' || :)
if [ ! -z "${KS_RESP}" ]; then
# We take the 1st ID value as it represents the token ID
TOKEN=$(echo ${KS_RESP} | getJson id 1)
if [ -z "${TOKEN}" ]; then
echo "CRITICAL: Unable to get a token from Keystone API"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL: Unable to reach Keystone API"
exit $STATE_CRITICAL
fi
# Check Neutron API and calculate the time
START=$(date +%s.%N)
API_RESP=$(curl -s -m $C_TIMEOUT -H "X-Auth-Token: $TOKEN" -H "Content-type: application/json" ${ENDPOINT_URL}/v2.0/networks.json || :)
END=$(date +%s.%N)
if [ ! -z "${API_RESP}" ]; then
# We take the name of the first network found
NETWORKS=$(echo ${API_RESP} | getJson name 1)
if [ -z "${NETWORKS}" ]; then
echo "CRITICAL: Unable to retrieve a network for tenant ${OS_TENANT_NAME} from Neutron API"
exit $STATE_CRITICAL
fi
else
echo "CRITICAL: Unable to contact Neutron API. Either Neutron service is not running or timeout of ${C_TIMEOUT}s has been reached."
exit $STATE_CRITICAL
fi
TIME=$(echo ${END} - ${START} | bc)
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z "${PID}" ]; then
echo "CRITICAL: $DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ $(id -u) -ne 0 ]; then
echo "WARNING: $DEAMON is running but the script must be run as root|response_time=${TIME}"
exit $STATE_WARNING
else
# Need root to run "netstat -p"
if ! KEY=$(netstat -eptan 2>/dev/null | egrep ":${AMQP_PORT}\ .*.${PID}\/python(2.7)?" 2>/dev/null) || test -z "${KEY}" || test -z "${NETWORKS}"
then
echo "CRITICAL: Neutron server is down or does not seem connected to your AMQP server."
exit $STATE_CRITICAL
else
if [ $(echo ${TIME}'>'$W_TIMEOUT | bc -l) -gt 0 ]; then
echo "WARNING: GET /v2.0/networks.json from Neutron API took more than $W_TIMEOUT seconds, it's too long.|response_time=${TIME}"
exit $STATE_WARNING
else
echo "OK: Neutron server is up and running (PID ${PID})|reponse_time=${TIME}"
exit $STATE_OK
fi
fi
fi

View File

@ -1,114 +0,0 @@
#!/bin/bash
# Nova API monitoring script for Sensu / Nagios
#
# Copyright © 2013-2014 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl, bc
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -E <Endpoint URL> URL for nova API. Ex: http://localhost:8774/v2"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use ro get an auth token"
}
while getopts 'hH:U:T:P:E:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service compute|grep publicURL|cut -d'|' -f3|sed 's/\s*//g')"}
if ! which curl >/dev/null 2>&1
then
echo "curl is not installed."
exit $STATE_UNKNOWN
fi
if ! which bc >/dev/null 2>&1
then
echo "bc is not installed."
exit $STATE_UNKNOWN
fi
# Get a token from Keystone
TOKEN=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}, "tenantName":"'$OS_TENANT_NAME'"}}' -H 'Content-type: application/json' |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["access"]["token"]["id"]')
if [ -z "$TOKEN" ]; then
echo "Unable to get a token from Keystone API"
exit $STATE_CRITICAL
fi
START=`date +%s.%N`
FLAVORS=$(curl -s -H "X-Auth-Token: $TOKEN" ${ENDPOINT_URL}/flavors)
N_FLAVORS=$(echo $FLAVORS | grep -Po '"name":.*?[^\\]"[,}]'| wc -l)
END=`date +%s.%N`
TIME=`echo ${END} - ${START} | bc`
if [[ ! "$FLAVORS" == *flavors* ]]; then
echo "Unable to list flavors"
exit $STATE_CRITICAL
else
if [ `echo ${TIME}'>'10 | bc -l` -gt 0 ]; then
echo "Got flavors after 10 seconds, it's too long.|response_time=${TIME}"
exit $STATE_WARNING
else
echo "Get flavors, Nova API is working: list $N_FLAVORS flavors in $TIME seconds.|response_time=${TIME}"
exit $STATE_OK
fi
fi

View File

@ -1,80 +0,0 @@
#!/bin/bash
#
# Nova Compute monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl
#
set -e
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='nova-compute'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,80 +0,0 @@
#!/bin/bash
#
# Nova Conductor monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='nova-conductor'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
#Grep the newest nova-conductor proc
PID=$(pgrep -u nova ${DEAMON} -n)
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,79 +0,0 @@
#!/bin/bash
#
# Nova Scheduler monitoring script
#
# Copyright © 2013 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='nova-consoleauth'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,251 +0,0 @@
#!/bin/bash
#
# Nova create instance monitoring script for Sensu / Nagios
#
# Copyright © 2014 eNovance <licensing@enovance.com>
#
# Author: Gaëtan Trellu <gaetan.trellu@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: curl python
#
# Nagios/Sensu return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4
# Script options
REFRESH=0
MAX_AGE=1800
CACHEFILE="/tmp/check_nova-instance.tmp"
TOKEN_FILE="/tmp/token"
TENANT_ID_FILE="/tmp/tenant_id"
IMAGE_ID_FILE="/tmp/image_id"
FLAVOR_ID_FILE="/tmp/flavor_id"
NOVA_ID_FILE="/tmp/nova_id"
INSTANCE_STATUS_FILE="/tmp/instance_status"
EXISTING_INSTANCE_ID_FILE="/tmp/instance_id"
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo " -H <Auth URL> URL for obtaining an auth token. Ex: http://localhost:5000/v2.0"
echo " -E <Endpoint URL> URL for nova API. Ex: http://localhost:8774/v2"
echo " -T <tenant> Tenant to use to get an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -P <password> Password to use ro get an auth token"
echo " -N <server name> Name of the monitoring instance"
echo " -I <image name> Name of the Glance image"
echo " -F <flavor name> Name of the Nova flavor"
echo " -r Refresh the cache"
}
output_result () {
# Output check result & refresh cache if requested
MSG="$1"
RETCODE=$2
if [ $REFRESH -gt 0 ]
then
echo "$MSG" > $CACHEFILE
echo $RETCODE >> $CACHEFILE
fi
echo "$MSG"
exit $RETCODE
}
while getopts 'hH:U:T:P:N:I:F:E:r' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
H)
export OS_AUTH_URL=$OPTARG
;;
E)
export ENDPOINT_URL=$OPTARG
;;
T)
export OS_TENANT_NAME=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
P)
export OS_PASSWORD=$OPTARG
;;
N)
export SERVER_NAME=$OPTARG
;;
I)
export IMAGE_NAME=$OPTARG
;;
F)
export FLAVOR_NAME=$OPTARG
;;
r)
export REFRESH=1
;;
*)
usage
exit 1
;;
esac
done
if [ -z "$SERVER_NAME" ]
then
echo "SERVER_NAME not set."
exit 1
fi
# Read results from cache unless refresh requested
if [ $REFRESH -eq 0 ]
then
if [ -f $CACHEFILE ]
then
FILEAGE=$(($(date +%s) - $(stat -c '%Y' "$CACHEFILE")))
if [ $FILEAGE -gt $MAX_AGE ]; then
output_result "UNKNOWN - Cachefile is older than $MAX_AGE seconds!" $STATE_UNKNOWN
else
ARRAY=()
while read -r LINE; do
ARRAY+=("$LINE")
done < $CACHEFILE
output_result "${ARRAY[0]}" ${ARRAY[1]}
fi
else
output_result "UNKNOWN - Unable to open cachefile !" $STATE_UNKNOWN
fi
fi
# Set default values
OS_AUTH_URL=${OS_AUTH_URL:-"http://localhost:5000/v2.0"}
ENDPOINT_URL=${ENDPOINT_URL:-"$(keystone catalog --service compute|grep publicURL|cut -d'|' -f3)"}
if ! which curl > /dev/null 2>&1
then
output_result "UNKNOWN - curl is not installed." $STATE_UNKNOWN
fi
# Get the token
TOKEN=$(curl -s -X 'POST' ${OS_AUTH_URL}/tokens -d '{"auth":{"passwordCredentials":{"username": "'$OS_USERNAME'", "password":"'$OS_PASSWORD'"}, "tenantName":"'$OS_TENANT_NAME'"}}' -H 'Content-type: application/json' |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["access"]["token"]["id"]')
if [ -z $TOKEN ]
then
output_result "CRITICAL - Unable to get a token from Keystone API" $STATE_CRITICAL
fi
# Get the tenant ID
TENANT_ID=$(curl -s -H "X-Auth-Token: $TOKEN" ${OS_AUTH_URL}/tenants |python -c 'import sys; import json; data = json.loads(sys.stdin.readline()); print data["tenants"][0]["id"]')
if [ -z $TENANT_ID ]
then
output_result "CRITICAL - Unable to get tenant ID from Keystone API" $STATE_CRITICAL
fi
# Check if an instance with the same name already exist
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/servers | python -mjson.tool | grep -B11 "\"name\": \"SERVER_NAME\"" | awk -v var="\"id\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $EXISTING_INSTANCE_ID_FILE
if [ -s $EXISTING_INSTANCE_ID_FILE ]
then
EXISTING_INSTANCE_ID=$(cat $EXISTING_INSTANCE_ID_FILE)
for TO_DELETE in $EXISTING_INSTANCE_ID
do
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/servers/"$TO_DELETE" -X DELETE
done
fi
START=`date +%s`
# Get image ID
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/images | python -mjson.tool | grep -B16 "$IMAGE_NAME" | awk -v var="\"id\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $IMAGE_ID_FILE
if [ -s $IMAGE_ID_FILE ]
then
IMAGE_ID=$(cat $IMAGE_ID_FILE)
else
output_result "CRITICAL - Unable to get image ID from nova API" $STATE_CRITICAL
fi
# Get flavor ID
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/flavors | python -mjson.tool | grep -B11 "$FLAVOR_NAME" | awk -v var="\"id\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $FLAVOR_ID_FILE
if [ -s $FLAVOR_ID_FILE ]
then
FLAVOR_ID=$(cat $FLAVOR_ID_FILE)
else
output_result "CRITICAL - Unable to get flavor ID from nova API" $STATE_CRITICAL
fi
# Spawn the new instance
curl -s -d '{"server": {"name": "'$SERVER_NAME'", "imageRef": "'$IMAGE_ID'", "flavorRef": "'$FLAVOR_ID'", "max_count": 1, "min_count": 1}}' "$ENDPOINT_URL"/"$TENANT_ID"/servers -X POST -H "X-Auth-Token: $TOKEN" -H "Content-Type: application/json" | python -mjson.tool | awk -v var="\"id\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $NOVA_ID_FILE
if [ -s $NOVA_ID_FILE ]
then
INSTANCE_ID=$(cat $NOVA_ID_FILE)
else
output_result "CRITICAL - Unable to get instance ID from nova API" $STATE_CRITICAL
fi
# Get the new instance status
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/servers/"$INSTANCE_ID" | python -mjson.tool | awk -v var="\"status\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $INSTANCE_STATUS_FILE
if [ -s $INSTANCE_STATUS_FILE ]
then
INSTANCE_STATUS=$(cat $INSTANCE_STATUS_FILE)
else
output_result "CRITICAL - Unable to get instance status from nova API" $STATE_CRITICAL
fi
# While the instance is not in ACTIVE or ERROR state we check the status
while [ "$INSTANCE_STATUS" != "ACTIVE" ]
do
sleep 5
# Check the instance status
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/servers/"$INSTANCE_ID" | python -mjson.tool | awk -v var="\"status\":" '$0 ~ var { print $2 }' | sed -e 's/"//g' -e 's/,//g' > $INSTANCE_STATUS_FILE
if [ -s $INSTANCE_STATUS_FILE ]
then
INSTANCE_STATUS=$(cat $INSTANCE_STATUS_FILE)
else
output_result "CRITICAL - Unable to get instance status from nova API" $STATE_CRITICAL
fi
if [ "$INSTANCE_STATUS" == "ERROR" ];
then
output_result "CRITICAL - Unable to spawn instance" $STATE_CRITICAL
fi
done
END=`date +%s`
TIME=$((END-START))
# Delete the new instance
curl -s -H "X-Auth-Token: $TOKEN" "$ENDPOINT_URL"/"$TENANT_ID"/servers/"$INSTANCE_ID" -X DELETE
# Cleaning
rm $IMAGE_ID_FILE $FLAVOR_ID_FILE $NOVA_ID_FILE $INSTANCE_STATUS_FILE $EXISTING_INSTANCE_ID_FILE
if [ $TIME -gt 300 ]; then
output_result "CRITICAL - Unable to spawn instance quickly" $STATE_CRITICAL
else
if [ $TIME -gt 180 ]; then
output_result "WARNING - Spawn image in 180 seconds, it's too long" $STATE_WARNING
else
output_result "OK - Nova instance spawned in $TIME seconds | time=$TIME" $STATE_OK
fi
fi

View File

@ -1,79 +0,0 @@
#!/bin/bash
#
# Nova Scheduler monitoring script
#
# Copyright © 2013 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 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='nova-network'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK

View File

@ -1,79 +0,0 @@
#!/bin/bash
#
# Nova Scheduler monitoring script
#
# Copyright © 2013 eNovance <licensing@enovance.com>
#
# Author: Emilien Macchi <emilien.macchi@enovance.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Requirement: netstat
#
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
DEAMON='nova-scheduler'
usage ()
{
echo "Usage: $0 [OPTIONS]"
echo " -h Get help"
echo "No parameter : Just run the script"
}
while getopts 'h' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
*)
usage
exit 1
;;
esac
done
if ! which netstat >/dev/null 2>&1
then
echo "netstat is not installed."
exit $STATE_UNKNOWN
fi
PID=$(ps -ef | awk "BEGIN {FS=\" \"}{if (/python(2.7)? [^ ]+${DEAMON}/) {print \$2 ; exit}}")
if [ -z $PID ]; then
echo "$DEAMON is not running."
exit $STATE_CRITICAL
fi
if [ "$(id -u)" != "0" ]; then
echo "$DEAMON is running but the script must be run as root"
exit $STATE_WARNING
else
#Need root to "run netstat -p"
if ! KEY=$(netstat -epta 2>/dev/null | awk "{if (/amqp.*${PID}\/python/) {print ; exit}}") || test -z "$KEY"
then
echo "$DEAMON is not connected to AMQP"
exit $STATE_CRITICAL
fi
fi
echo "$DEAMON is working."
exit $STATE_OK