Checkcommand and check_dhcp

Hello all!
I’m trying to check dhcp and I’m getting a socket error (I think because the command is actually asking the dhcp addy to be assigned to my nic.

Can someone tell me the correct command_line entry in checkcommands.cfg?

Tks much!

./check_dhcp --help
All i did was type
./check_dhcp and hit enter. Seems to report correctly
./check_dhcp
DHCP ok: Received 2 DHCPOFFER(s), max lease time = 2592000 sec.

OH, and the checkcommands.cfg defintion would be fairly easy then.
define command{
command_name check_dhcp
command_line $USER1$/check_dhcp
}

This is what I get when I run the command from the prompt…

check_dhcp IPADDRESS

DHCP ok: Received 1 DHCPOFFER(s), max lease time = 0 sec.

The command line in checkcommands.cfg looks like this…
command_line $USER1$/check_dhcp $HOSTADDRESS$

On the browser I get an UNKNOWN status and Status Information like the following: 08-18-2005 12:05:49 0d 1h 43m 5s 5/5 Error: Could not bind socket to interface eth0. Check your privileges…

any ideas?

Please, read the
./check_dhcp --help

It states that this plugin checks for DHCP servers, it doesn’t say that you HAVE to specify an IP addy.
Besides that, you didn’t use the correct sytax even if you ARE going to specify an IP address.

Your network may have many DHCP servers, but if you really really DEMAND that a particular one responds, then that IP addy can be entered IF you use the correct syntax, which you did not.
So again read the output of
./check_dhcp --help
and fix your checkcommands.cfg file, that is not the correct syntax to use check_dhcp.

it also looks like you will have to su to run this one. If I figure out otherwise, I’ll let ya know.

The syntax seemed to work for me (IP Addy being the DHCP server). You’re right though, it’s a priviledges issue. I can’t get the right response other than as root.

I decided to write a shell (ksh) script to sudo nagios to run check_dhcp as root.
First, I added a line to /etc/sudoers.

nagios ALL=(root) NOPASSWD: /usr/local/nagios/libexec/check_dhcp

Then I wrote the script with the following line…
sudo /usr/local/nagios/libexec/check_dhcp

This all works from the command line. As user nagios, I can run the script and get an “ok” answer back.

I edited my checkcommands file with the commandline entry pointing to check_dhcp.ksh (my script).

I restarted nagios and, voila, it works!

I know this post was a little long, but I wanted to show enough that someone else with the same problem will be able to solve it.

Thanks for your help, jakkedup!

I’ve yet to find another way around this. sudo appears to be the only way, other than changing permissions on some file, which would not be the correct way to handle this.

BTW, good job on setting up the sudo command with no help. I had faith in you, that’s why I didn’t say any more than just “you will have to su, to run this”
Edited Fri Aug 19 2005, 09:59AM ]

Hi guys
I hate bumping an old thread, but this worked for me
chmod +s check_dhcp
Source
machinekit.com/

I’m sure this is the “incorrect” way and not for everyone, but for those that need a quick fix, it worked for me

Nope, I’m sure you are right. That would be a great and easy fix.