#!/bin/bash

KEYTAB="/root/nagios_keytab/pbstest.keytab"

type /usr/bin/swift &>/dev/null
if [[ $? -eq 0 && -f $KEYTAB ]] ; then
    source /etc/profile.d/40_meta_swift.sh &>/dev/null
    
    export KRB5CCNAME="/tmp/krb5cc_1000_swift_client"
    kinit -k -t $KEYTAB pbstest

    RET=$(waitmax 30 /usr/bin/swift list 2>&1)

    if [[ $? -eq 255 && "$RET" == "" ]] ; then
        RET="swift timeout"
    fi

    kdestroy

    if [[ "$RET" == "nagios" ]] ; then
        echo "0 swift_client - OK"
    else
        echo "2 swift_client - CRITICAL: $(echo $RET | tr '\n' ' ')"
    fi
fi
