I’m using a remote [tt]syslog-ng[/tt] server on a port ~= 514 and would like to use [tt]logger[/tt] to log wattage to a remote server. The solution must not affect the standard logging to [tt]/etc/var/cmh[/tt].
This is how you send syslog to a remote server on OpenWrt. But that’ll only send the system log, and I sense you are actually referring to the Luup log produced by MiOS.
First get remote syslog to work for you. I think it works only on TCP, not UDP, so configure the syslog receiver accordingly.
Then try to copy the Luup log over to syslog, by running something like:
tail -f /var/log/cmh/LuaUPnP.log | logger
Prove that works and we can work at automating it.
[quote=“hazedav, post:7, topic:168780”]I was able to stream the contents of LuaUPnP.log to a syslog server using netcat.
For example:
tail -f /var/log/cmh/LuaUPnP.log | nc -u 192.168.0.100 514[/quote]
Is that working well for you? Do you just do that for short periods or did you put something in place to do that continuously? I used the while true do tail luup | logger trick in putty but it only does that while I am in SSH.
I then use the following to forward the LuaUPnP log to the local syslog:
tail -f /tmp/log/cmh/LuaUPnP.log | awk '{print $1 " " $2 " " $3 " - [LuaUPnP.log] - " substr($0, index($0,$4)) }' | logger &
and now it’s in the local syslog it is transferred on to the remote syslog server.
The ‘&’ at the end of the line allows the process to continue running in the background even when the calling terminal is closed (in this case).
This however will not survive a reboot.
Does anyone know how to add this to the config either to send the luaUPnP log directly to a syslog server or to do the above on a more permanent basis?
you can because Vera is running as root.
However you should wrap it in a shell script that kills itself if it’s already running … Then launch the command in a loop so it will survive the log rotation.
the reason for killing itself is for when Vera is reloaded, not for when it reboots.
#!/bin/sh
MPID=$$
PID=$(cat /tmp/syslog_copy.pid)
if [ $PID -ne $MPID ]; then
for cpid in $(ps -o pid --ppid $PID); do
kill $cpid
done
kill $PID
fi
echo $MPID > /tmp/syslog_copy.pid
while true; do
tail -f /tmp/log/cmh/LuaUPnP.log
done
Replace the tail command with your actual command.
This kills processes and sub processes from a previously run command … if it exists.
The reason for testing if the last process is equal to the current process … is that on a quick reboot … the process ID can be the same as the processed ID from the previous boot. On a Vera Restart/Reload they will never be the same.
#!/bin/sh
MPID=$$
PID=$(cat /tmp/syslog_copy.pid)
if [ $PID -ne $MPID ]; then
for cpid in $(ps -o pid --ppid $PID); do
kill $cpid
done
kill $PID
fi
echo $MPID > /tmp/syslog_copy.pid
while true; do
os.execute("[[ ! `ps -ef | grep 'tail -F /tmp/log/cmh/LuaUPnP.log' | grep -v grep` ]] && tail -F /tmp/log/cmh/LuaUPnP.log | awk '{print \"- [LuaUPnP.log - \" $2 \" \" $3 \" ] - \" substr($0, index($0,$4)) }' | logger >/dev/null 2>&1 & ")
sleep(15)
done
Placing the file in /etc and setting permissions:
chmod +x LuaLogger.sh
And then add to the startup lua:
os.execute("/etc/LuaLogger.sh")
I’m a little green at this, so please excuse me if it’s not wise to put this in the startup lua or if I have something in the wrong place here. I already have my syslog going to a Synology so this would make it easy for me to monitor for failures of devices and plugins.
add following script to your vera 7.0.x by ( ssh <vera_ip>, then copy paste in the terminal )
cat << 'EOF' > /etc/LuaLogger.sh
#!/bin/sh
MPID=$$
PID=$(cat /tmp/syslog_copy.pid)
if [ $PID -ne $MPID ]; then
for cpid in $(ps -o pid --ppid $PID); do
kill $cpid
done
kill $PID
fi
echo $MPID > /tmp/syslog_copy.pid
while true; do
tail -f /tmp/log/cmh/LuaUPnP.log | awk '{print "["$2" "$3"] " substr($0, index($0,$4)) }' | logger -t LuaUPnP >/dev/null 2>&1
done
EOF
Edit your lua startup code and adjust the variables as needed:
-- define syslog remote ip and port
syslog_ip="1.2.3.4"
syslog_port="514"
-- do not edit below unless you know what you are doing
os.execute("uci set system.@system[0].log_ip=" .. syslog_ip)
os.execute("uci set system.@system[0].log_port=" .. syslog_port)
os.execute("uci commit system")
os.execute("/etc/init.d/log restart")
os.execute("test -x /etc/LuaLogger.sh && /etc/LuaLogger.sh &")
/Alex
Best Home Automation shopping experience. Shop at Ezlo!