#!/bin/bash # # Swift monitoring script for Nagios # # Copyright © 2012 eNovance # # Author: Julien Danjou # # 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 . # # Modified by Sara Bertocco (sara_dot_bertocco_at_pd_dot_infn_dot_it) 2014/10/14 set -e STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 STATE_DEPENDENT=4 usage () { echo "Be sure file /etc/swift/swift-check.conf exists configured." echo "Usage: $0 [OPTIONS]" echo " -h Get help" } while getopts 'hH:' OPTION do case $OPTION in h) usage exit 0 ;; *) usage exit 1 ;; esac done while read line; do export "$line"; done < /etc/swift/swift-check.conf 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 --insecure 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 --insecure upload "$container" "$TMPFILE" 2>/dev/null) then echo "Unable to upload file" exit $STATE_CRITICAL fi if ! swift --insecure 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 --insecure delete "$container" "$KEY" >/dev/null 2>&1 then sleep 3 if swift --insecure list "$container" |grep "$KEY" |grep $KEY >/dev/null 2>&1 then echo "File upload+download OK, but unable to delete uploaded file" exit $STATE_WARNING fi fi echo "Upload+download+delete of $(($BLOCK_NUMBER * $BLOCK_SIZE / 1024)) KiB file in container $container"