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
|
#!/bin/bash
#
# Swift monitoring script for Nagios
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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/>.
#
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 " -A <url> URL for obtaining an auth token"
echo " -U <username> Username to use to get an auth token"
echo " -K <key> Password to use ro get an auth token"
echo " -V <authversion> Version for authentication"
echo " -c <container> Container to upload to"
echo " -s <maxsize> Determine maximum file size in KB"
echo " (default: 1024)"
}
while getopts 'hH:A:U:K:V:c:s:' OPTION
do
case $OPTION in
h)
usage
exit 0
;;
A)
export OS_AUTH_URL=$OPTARG
;;
U)
export OS_USERNAME=$OPTARG
;;
K)
export OS_PASSWORD=$OPTARG
;;
V)
export ST_AUTH_VERSION=$OPTARG
;;
c)
container=$OPTARG
;;
s)
multi=$OPTARG
;;
*)
usage
exit 1
;;
esac
done
multi=${multi:-1024}
container=${container:-check_swift}
if ! which swift >/dev/null 2>&1
then
echo "Swift command not found"
exit $STATE_UNKNOWN
fi
delete_files ()
{
test -n "$KEY" && swift delete "$container" "$KEY" >/dev/null 2>&1 || true
rm -f "$TMPFILE" "$TMPFILE_TARGET"
}
trap delete_files EXIT
TMPFILE=`mktemp`
BLOCK_NUMBER=$(($RANDOM * $multi / 32767))
BLOCK_SIZE=1024
dd if=/dev/urandom of=$TMPFILE count=$BLOCK_NUMBER bs=$BLOCK_SIZE >/dev/null 2>&1
TMPFILE_TARGET=`mktemp`
if ! KEY=$(swift upload "$container" "$TMPFILE" 2>/dev/null)
then
echo "Unable to upload file"
exit $STATE_CRITICAL
fi
if ! swift download "$container" "$KEY" -o "$TMPFILE_TARGET" >/dev/null 2>&1
then
echo "File upload OK, but unable to download file"
exit $STATE_CRITICAL
fi
if ! swift delete "$container" "$KEY" >/dev/null 2>&1
then
echo "File upload+download OK, but unable to delete uploaded file"
exit $STATE_CRITICAL
fi
echo "Upload+download+delete of $(($BLOCK_NUMBER * $BLOCK_SIZE / 1024)) KiB file in container $container"
|