Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
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:
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
A reserved instance will expire in -374918 hours. Please renew via EC2 console.
nowdate is 1381243625
reserveddate is
diffdate is
remaininghours is -374918
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.
I think the issue might be earlier on than that. What are the permissions for the /opt/ec2-api-tools/bin/ec2-describe-reserved-instances command? If the nagios user cannot execute it, then your "command" will not run, therefor never allowing "reservations" to get data, etc etc.
Is it valid to test by:
#su - nagios
Then run the command? If so, the nagios user can run the command without issue, and can run my shell script without issue.
Can you show us the output of you actually su'ing to nagios, then running the script specifying the full path name? While you're at it, wanna actually show the output of "ls -l /opt/ec2-api-tools/bin/ec2-describe-reserved-instances" again as nagios? One last thing, try "touch /opt/ec2-api-tools/bin/test" for good measure.
Be sure to sanitize any potential sensitive information. Shouldn't be any in this case, but always a good thing to keep in mind.
[root@linserver2 ~]# su - nagios
-bash-4.1$ /opt/ec2-api-tools/bin/ec2-describe-reserved-instances | head -n 1
RESERVEDINSTANCES *************************************** us-east-1b m1.small Linux/UNIX 1y 227.5 0.03 1 2011-10-06T12:33:23+0000 retired USD default Medium Utilization
-bash-4.1$ /etc/nagios/scripts/ec2-reserve-warn.sh
A reserved instance will expire in 33 hours. Please renew via EC2 console.
nowdate is 1381255882
reserveddate is 1349841600
diffdate is 31414282
remaininghours is 33
-bash-4.1$ ls -l /opt/ec2-api-tools/bin/ec2-describe-reserved-instances
-rwxr-xr-x 1 root root 728 Sep 10 14:11 /opt/ec2-api-tools/bin/ec2-describe-reserved-instances
-bash-4.1$ touch /opt/ec2-api-tools/bin/test
touch: cannot touch `/opt/ec2-api-tools/bin/test': Permission denied
Script(s) run without issue, nagios doesn't have write permission to that dir, but the x bit is set for other.
tmcdonald wrote:Can you show us the output of you actually su'ing to nagios, then running the script specifying the full path name? While you're at it, wanna actually show the output of "ls -l /opt/ec2-api-tools/bin/ec2-describe-reserved-instances" again as nagios? One last thing, try "touch /opt/ec2-api-tools/bin/test" for good measure.
Be sure to sanitize any potential sensitive information. Shouldn't be any in this case, but always a good thing to keep in mind.
Yep, in the OP there are two code sections showing the output.
The script is echoing the variables for debugging purposes. In the shell version all 4 variables contain values. In the Nagios web UI version there are empty variables such as $reserveddate. Because there is no value, the other calculated variables have the wrong values as well.
yancy wrote:steved,
I can run the script from a shell without issue, but when Nagios runs it as a check some values are not populated:
Can you be more specific about what values are and are not populating?
Judging from the output on your first post, it definitely seems like the $command is not running or returning bad data, as the variables are wrong/empty from that point on.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
I would venture to say that it is not, however you could always modify and set an echo after each line to print that particular value and be 100% certain!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.