Enable LAN port link status in system log when down

Hi is there other way to display the message in system log for a specific ports when cable is unplug or down something like "LAN4 link is down...". I am using TPLink Archer C5 V2 openwrt 19.07.10 and I wanted to monitor my ISP modem stability because there are times when my ISP modem reboots by itself and when it happens, it doesn't leave a log in my openwrt that this particular port is down. I tried my other openwrt newifi and it leaves a log when cable is unplug but using TPLink archer c5 v2 doesn't.

Or just help me to display "WAN is down..." in system log whenever cable is unplug or ISP modem reboot itself. It will do.

there should already be an entry in the log if a cable's unplugged ?

logread | grep down

Down, capital D.

System log is using lower case.

root@OpenWrt:~# logread | grep down
Tue May 10 01:00:26 2022 kern.info kernel: [   10.954714] eth1: link down
Tue May 10 02:11:45 2022 kern.info kernel: [ 3286.485987] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
Tue May 10 02:12:45 2022 kern.info kernel: [ 3345.877528] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
Tue May 10 07:37:40 2022 kern.info kernel: [22840.716907] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
Tue May 10 16:30:19 2022 kern.info kernel: [54799.620171] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
Tue May 10 17:44:41 2022 kern.info kernel: [59262.193451] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
Tue May 10 20:25:41 2022 kern.info kernel: [68921.544704] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
Wed May 11 00:56:22 2022 kern.info kernel: [85163.206382] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
Wed May 11 03:29:41 2022 kern.info kernel: [94361.769321] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
Wed May 11 06:42:22 2022 kern.info kernel: [105922.674643] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down

Just pulled the LAN ethernet cable -

Wed May 11 23:17:52 2022 kern.info kernel: [165652.347708] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down

Indeed it does, hadn't noticed the difference, I stand corrected.

Kernel log as well...

root@OpenWrt:~# dmesg | grep down
[   10.954714] eth1: link down
[ 3286.485987] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
[ 3345.877528] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
[22840.716907] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
[54799.620171] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
[59262.193451] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
[68921.544704] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
[85163.206382] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
[94361.769321] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
[105922.674643] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 4 is down
[165652.347708] Atheros AR8216/AR8236/AR8316 mdio.0:00: Port 2 is down
root@OpenWrt:~#

seems to be driver specific, mine report it using capital D and U, in dmesg.

Interesting.

How about logread?

logread's lower case.

I'll paste the output from dmesg later, but the host I have connected to the test router have the cert error

tried to unplug the wan cable but there's no message of "WAN is down". I only received an output of "Interface 'lan' is now down which is a log from my previous reboot of this router.

I thought dmesg output comes from the kernel ring buffer...

What version of the kernel are you on?

I'm currently on 5.4.188

it's 21.02.2 stable, 5.4.179.

I always saw lower case down on 21.02.2 using both logread and dmesg.

Strange.

See if this works for you...

dmesg | grep 'down\|Down'

mine just doesn't show up. I might try to downgrade since this router is not supported in version 21.0+ anymore.

it does, but if you need to match both, you might as well use the -i switch.

Yep.

Just something quick I threw together.

1 Like

So if you shutdown your computer, or pull the ethernet cable, you should see something in the log.

As a test, try one or the other...or both scenarios.

SSH in to the router and just run logread.

Copy all of the output and paste it in a text file.

Then search the text file for down or Down.

Repeat the above with dmesg.

The only log that worked is the interface 'LAN' but only during reboot of the router it will show like this but WAN doesn't seems to give a log that it is down whenever cable is unplug.

root@OpenWrt:~# logread | grep down
Thu May 12 06:59:40 2022 daemon.notice netifd: Interface 'lan' is now down
Thu May 12 06:59:40 2022 daemon.notice netifd: bridge 'br-lan' link is down
root@OpenWrt:~#