AndyTaylorTweet / Pi-Star_DV_Dash

Pi-Star DV Dashboard (Based on works by Hans-J. Barthen (DL5DI) and Kim Huebel (DG9VH)).
http://www.pistar.uk/downloads/
111 stars 120 forks source link

YSF Network on dashboard shows "Not Linked" for some reflectors #171

Closed DrlSm closed 1 year ago

DrlSm commented 1 year ago

I just installed and was experimenting with Pi-Star (version 4.1.6 / Dashboard 20221011), and noticed an issue. Specifically, I noticed that many times the YSF Network field on the Dashboard reported "Not Linked", even though the link was successful and active. It happened whether the link was initiated from the radio, or from the YSF Link Manager on the Dashboard.

I did some investigation and realized that the problem happened when I linked with nodes ending with "-Link", for example, "US-America-Link" or "US-Skyhub-Link". I found the source and dug around a bit, and it seems that the issue is in the function getYSFGatewayLog in mmdvmhost/functions.php.

Basically, the code that searches the logfile to figure out the most recent link status is getting fooled by the presence of the string "-Link" in the hexdump following the CONNECT Reply in the logfile. The grep command matches on, among other things, the string "ink" which is triggered by the hexdump, perhaps a better choice would be "inked" which matches the "Linked to -Link" and isn't spoofed by the hexdump.

The following shows the results of manually executing the command invoked by the function with the current and changed string:

before) "ink" matches hexdump string:

pi-star@pi-star(ro):pi-star$ grep -E "onnection to|onnect to|ink|isconnect|Opening YSF network" YSFGateway-2022-10-26.log | sed '/Linked to MMDVM/d' | sed '/Link successful to MMDVM/d' | sed '/Link/d' | tail -1 D: 2022-10-26 22:07:26.255 0030: 75 62 2D 4C 69 6E 6B 20 20 30 34 34 20 20 20 20 ub-Link 044 *

after) "inked" skips hexdump and finds desired command:

pi-star@pi-star(ro):pi-star$ grep -E "onnection to|onnect to|inked|isconnect|Opening YSF network" YSFGateway-2022-10-26. log | sed '/Linked to MMDVM/d' | sed '/Link successful to MMDVM/d' | sed '/*Link/d' | tail -1 M: 2022-10-26 22:07:25.330 Linked to US-Skyhub-Link

I patched the functions.php file in my environment with the above change and it seems to work ok now. I am not really familiar with this code base so there may be side effects I am not aware of, but perhaps this will point someone in the right direction.

W0CHP commented 1 year ago

Seems as though you have debug logging enabled. So any line in the log(s) with the prefix D: will be (unnecessarily) parsed by functions.php.

The following snippet will only parse meaningful Message (M:) lines:

$logLines1 = preg_split('/\r\n|\r|\n/', `egrep -h "^M.*(onnection to|onnect to|inked|isconnect|Opening YSF network)" $logPath1 | sed '/Linked to MMDVM/d' | sed '/Link successful to MMDVM/d' | sed '/*Link/d' | tail -1`);

...or simply try to disable debug logging :-)

DrlSm commented 1 year ago

Thanks for the feedback. I also thought that a better solution would be to not log the debug level messages by default, since you never can be sure what will show up in a debug log and doing greps might match things you don’t want. Your suggestion of explicitly only including relevant log message types in the search is even better.

But note that the debug messages are showing up by default, it isn’t something that I turned on. Just to make sure I just rebuilt the Raspberry Pi from scratch from the latest released file from http://www.pistar.uk/downloads/ www.pistar.uk/downloads http://www.pistar.uk/downloads (Pi-Star_RPi_V4.1.5_30-Oct-2021.zip), connected via ssh and did the necessary number of pistar-update, pistar-upgrade commands, then did a minimal configuration only enabling YSF Mode. When I link to a YSF reflector (using Admin / YSF Link Manager) I definitely see the debug messages show up in the /var/log/pi-star/YSFGateway*.log file.

It isn’t clear to me where these messages are coming from, or how to disable them. The Debug value shown in Expert mode for YSF GW is 0, which I suspect is coming from /etc/ysfgateway. I looked around in the code and configuration files a bit but didn’t see where these messages are coming from, perhaps they are coming from something at a lower level than pi-star. But they are definitely showing up by default after a clean install.

From: Chipster @.> Sent: Thursday, October 27, 2022 4:52 AM To: AndyTaylorTweet/Pi-Star_DV_Dash @.> Cc: DrlSm @.>; Author @.> Subject: Re: [AndyTaylorTweet/Pi-Star_DV_Dash] YSF Network on dashboard shows "Not Linked" for some reflectors (Issue #171)

Seems as though you have debug logging enabled. So any line in the log(s) with the prefix D: will be (unnecessarily) parsed by functions.php.

The following snippet will only parse meaningful Message (M:) lines:

$logLines1 = preg_split('/\r\n|\r|\n/', egrep -h "^M.*(onnection to|onnect to|inked|isconnect|Opening YSF network)" $logPath1 | sed '/Linked to MMDVM/d' | sed '/Link successful to MMDVM/d' | sed '/*Link/d' | tail -1);

...or simply try to disable debug logging :-)

— Reply to this email directly, view it on GitHub https://github.com/AndyTaylorTweet/Pi-Star_DV_Dash/issues/171#issuecomment-1293411982 , or unsubscribe https://github.com/notifications/unsubscribe-auth/A324JAAW7WZZSGS53V4IZ7TWFJUG3ANCNFSM6AAAAAARPQD2LQ . You are receiving this because you authored the thread. https://github.com/notifications/beacon/A324JACF22MU55XL22PYAKTWFJUG3A5CNFSM6AAAAAARPQD2LSWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTSNC7TI4.gif Message ID: @. @.> >

W0CHP commented 1 year ago

@DrlSm in your /etc/ysfgateway, and in the [Log] Section/Stanza:

DisplayLevel=0
FileLevel=2

...Should hopefully squelch debug messages. (Same goes for MMDMhost ini file, etc.)

kn2tod commented 1 year ago

Perhaps stating the obvious but ... how do you debug something when the debug messages interfere with the results/behavor? Best to include the additional selection criteria just in case, regardless of these settings.

DrlSm commented 1 year ago

Setting FileLevel=2 in the [Log] section of /etc/ysfgateway took care of this particular problem, but I tend to agree that a more robust solution would be to tighten up the search criteria to ignore any non "^M.*" lines in the logfile so that it wouldn't matter whether or not debug was enabled.

And it is also worth reiterating that a clean install doesn't currently work quite right, the dashboard indicates that the YSF reflector is Not Linked (for some reflectors) when it really is (unless the link comes from the YSF Startup Host value on the Configuration page.) Sort of makes for a head scratcher, or at the very least unexpected behavior.