Problem with syslog to external server when DNS changes

Today the IP address for my Graylog server (which sits on a Dynamic DNS) changed. None of the dozens of devices that I have configured to push logs to it handled this correctly. They continued logging (apparently) to the old IP address.

I had to run service log restart after which they instantly started working again.

I understand this is a limitation of the logread binary which is part of OpenWRT. Still, a small helper script or daemon would be very helpful, when the configuration contains a hostname instead of an IP address, it should periodically be resolved and the service bounced if the IP address changes.

RutOS 7.15.2

For now, I created this little helper script:

#!/bin/sh

f=/tmp/logread_log_ip
h=$(uci get system.default.log_ip)
[ -n "$h" ] || exit 0
i=$(resolveip "$h")
if [ -z "$i" ]; then
  echo "cannot resolve $h"
  exit 1
fi
if [ ! -e $f ]; then
  echo "$i" > $f
  echo "initialized $h with $i"
  exit 0
fi
read -r p < $f
if [ "$p" = "$i" ]; then
  echo "IP unchanged ($i)"
  exit 0
fi
echo "log host IP changed ($p -> $i)"
echo "bouncing log service"
/etc/init.d/log restart
echo "$i" > $f

…and added it to my crontab

echo "*/10 * * * * /root/logread_helper.sh &>/dev/null" >>/etc/crontabs/root
/etc/init.d/cron reload
2 Likes

Hello,

Thanks for sharing a suggestion & a temporary solution as well, I’ll go ahead and register the suggestion for our R&D team.

Thank you kindly,
M.

This topic was automatically closed after 60 days. New replies are no longer allowed.