Custom Nagios check works from command line, but not Nagios
Posted: Tue Oct 08, 2013 10:21 am
Hello all,
I've created a basic script that grabs our AWS reserved instance dates and does a simple calculation to determine if the oldest instance will expire in the next 5 days.
I can run the script from a shell without issue, but when Nagios runs it as a check some values are not populated:
Script:
Output in a shell:
Output from Nagios:
So it looks like when I try to convert $reserveddate the variable isn't being passed to the shell properly, or maybe not passed back? I'm not entirely sure why this is happening.
Any help is appreciated.
I've created a basic script that grabs our AWS reserved instance dates and does a simple calculation to determine if the oldest instance will expire in the next 5 days.
I can run the script from a shell without issue, but when Nagios runs it as a check some values are not populated:
Script:
Code: Select all
#!/bin/bash
nowdate=`date +%s`
command=`/opt/ec2-api-tools/bin/ec2-describe-reserved-instances -F state=active | awk '{print $10}' | awk -F T '{print $1}' | sed '/^$/d' | sort`
reservations=($(echo $command))
reserveddate=$(echo $reservations | xargs date +"%s" -d)
diffdate=$(($nowdate - $reserveddate))
remaininghours=$(((31536000 + $reserveddate - $nowdate) / 3600))
if [ $remaininghours -le 120 ]
then
echo "A reserved instance will expire in $remaininghours hours. Please renew via EC2 console."
# debug
echo nowdate is $nowdate
echo reserveddate is $reserveddate
echo diffdate is $diffdate
echo remaininghours is $remaininghours
# /debug
exit 1
else
echo "All reservations are current."
# debug
echo nowdate is $nowdate
echo reserveddate is $reserveddate
echo diffdate is $diffdate
echo remaininghours is $remaininghours
# /debug
exit 0
fi
Code: Select all
A reserved instance will expire in 37 hours. Please renew via EC2 console.
nowdate is 1381243634
reserveddate is 1349841600
diffdate is 31402034
remaininghours is 37
Code: Select all
A reserved instance will expire in -374918 hours. Please renew via EC2 console.
nowdate is 1381243625
reserveddate is
diffdate is
remaininghours is -374918
Any help is appreciated.