gmazoyer / looking-glass

Easy to deploy Looking Glass
GNU General Public License v3.0
435 stars 139 forks source link

Mikrotik Traceroute #125

Open agent-squirrel opened 4 years ago

agent-squirrel commented 4 years ago

The Traceroute tool on Mikrotik ROS operates like an MTR and continually updates the console with metrics. This can be avoided with count=1 but if the traceroute encounters a blank hop for any reason, the router rewrites the console anyway. If running the traceroute with no controlling terminal, as in the case of an LG, the result gets output in chunks and only the final chunk is actually useful.

A solution is to explode the resultant string data into an array using the blank line between each chunk as a deliminator and then takes the final index as the resultant string.

Adding $filtered = end(explode("\n\n",trim($filtered))); Somewhere before the filtered output is returned has fixed this issue on our install of LG. We have added it just before return preg_replace('/(?:\n|\r\n|\r)$/D', '', $filtered);

safnz commented 3 years ago

Can confirm the above fix works, great stuff @agent-squirrel

jordandalley commented 2 months ago

The above solution didn't work for me unfortunately.. might be due to a different routeros or php version.

Instead, I placed the following as the first line of the format_output function in router.php:

$output = substr($output, strrpos($output, "\r\n\r\nColumns:") + 2, strlen($output));