Search code examples
bashpluginsnagiossystem-administrationopenstack-swift

Nagios custom plugin calling python Openstack Swift client


I want to check with NAGIOS whether my server can connect to Openstack Swift container. I wrote a simple script where I use Swift Python client to get stat of the container

Script looks like that

#!/bin/bash

set -e

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4


if ! which /usr/bin/swift >/dev/null 2>&1
then
    echo "Swift command not found"
    exit $STATE_UNKNOWN
fi
my_swift="/usr/bin/swift -V 2.0 -A http://my-swift-domain.com:5000/v2.0/  --insecure --os-username my-user-name --os-password my-password --os-tenant-name tenant-name stat container"


output=`$my_swift | grep Objects |  sed 's/Objects:\s*\([0-9]*\).*/\1/'`

if [ "$output" -eq "$output" ] 2>/dev/null
then
   echo "successfully connected to swift. Number of objects in container $output";
   exit $STATE_OK
else
   echo "Number of container objects is not correct";
   exit $STATE_CRITICAL
fi

Script has right permissions and NAGIOS is able to run it properly. The script itself called from bash works and returns something like:

successfully connected to swift. Number of objects in container          4973123

But it doesn't when I run it via nrpe. I checked it by running /usr/lib64/nagios/plugins/check_nrpe -H 127.0.0.1 -c check_swift I just get Number of container objects is not correct

After debugging I'm pretty sure that the command

output=`$my_swift | grep Objects |  sed 's/Objects:\s*\([0-9]*\).*/\1/'`

is not even called.

I tried to put swift --version there just to see if it will give me some output and it does. So, it let me think that there is something wrong with parameters but I really don't know what, because the command itself called in a shell works perfectly fine.

Any help appreciated :)


Solution

  • Turns out that it was SELinux (on CentOS) blocking the execution of the command because of the wrong context of the file. I copied the file from home directory to Nagios' plugins directory. restorecon check_swift_container -v helped