NRPE with dynamic IP


#1

Hi.

I set up Nagios monitoring server on my home server with dynamic IP (I use dyndns.org). Almost everything works fine, but there is just one thing bothering me - since my monitoring server’s IP changes dynamically, I can’t use NRPE plugin for monitoring. I followed directions found here. Everything works fine until the part that says I should configure file /etc/xinetd.d/nrpe and put my monitoring server’s IP into the line only_from=xxx.xxx.xxx.xxx
When I put current IP of the monitoring server, NRPE works fine and I can monitor it’s sensors. But if I put address of dynamic host (debian.homelinux.net), it doesn’t work.
Can someone please help me?

Thanks, Sasa.


#2

You could write a little cron job that re-writes the file for you periodically (depending on the frequency of your ip address changes to that of your checks)… I’d split /etc/xinetd.d/nrpe into 2 halves around the *only_from *line, a headfile and a tailfile, and then run something like this:

#!/bin/sh
cat /some/path/headfile > /etc/xinetd.d/nrpe
host your.domain.com | awk '{print "only_from="$4}' >> /etc/xinetd.d/nrpe
cat /some/path/tailfile >> /etc/xinetd.d/nrpe
service xinetd restart

It’ll probably need a little bit of a fiddle to get it working, but I think the principle is sound enough to get you where you want to be. I expect someone could come up with a neater solution that checks for an ip address change first before perhaps using *sed *to perform the re-write, but I’m afraid thats a bit beyond me… :cry:

HTH

/S


#3

thanks, I’ll give it a try tomorrow


#4

Hi Sasa

Not being able to check whether a change was required was annoying me :x , so I worked out how to check if the DNS entry matches what is in the nrpe file…

#!/bin/sh
checkresult=`host your.domain.com | awk '{print "/bin/grep "$4" /etc/xinetd.d/nrpe | /usr/bin/wc -l"}' | sh`
case "$checkresult" in
1)
        # One line found with the right IP address - do nothing
        ;;
0)
        # No lines found with the right IP address - re-write the file and restart servce
        cat /some/path/headfile > /etc/xinetd.d/nrpe
        host your.domain.com | awk '{print "only_from="$4}' >> /etc/xinetd.d/nrpe 
        cat /some/path/tailfile >> /etc/xinetd.d/nrpe
        service xinetd restart
        ;;
esac
exit 0

Once you make the pathways appropriate to your environment, you should be able to use cron to execute that as often as neccessary and it’ll only perform the re-write & restart if needed 8)

HTH

/S


#5

thank you sooooooo much Strides. you helped me big time :slight_smile:
you just have one error (probably a typo). in the second line, the path to nrpe file isn’t /uetc/xinetd.d/nrpe. it’s /etc/xinetd.d/nrpe :slight_smile:


#6

good spot - that was an over-paste of /usr/local/testfile gone awry :shock: (thanks for pointing it out - i’ll edit it out on the previous post…)

Anyway, glad to be of assistance :slight_smile:

/S