New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added Vlan discovery on LAG ports, Jetstream OS #13007
Conversation
Hi @Npeca75 And please provide test files (snmprec and JSON) as required. Thanx |
Hi @PipoCanaja sorry for mess, i am totally noob on GITHUB |
unset($result); | ||
|
||
if ($pos = strpos($var, ',LAG')) { // if input string contains 'LAG' | ||
$lag = str_replace('LAG', '', substr($var, $pos + 1)); // get the LAG ports in form of '1,2,4-8' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is really hard to read, could it perhaps be done with a regex?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @murrant
sorry, my "native" language is assembler on embedded devices, so i am not familiar with PHP
if you have any suggestion ...
TP-LINK made own way of representing Vlans in snmp
for example:
STRING: "1/0/1-2,1/0/4-6,1/0/25,LAG1-2,LAG4"
as you see, port 1,2,4,5,6,25 are tagged
and LAG1,2,4 are tagged
so, the information about ports and LAG's are in one line
it need to be splitted on two parts, first for ports, second for LAG's
then DASH need to be replaced with corresponding numbers
4-6 -> 4,5,6
same technique for PORTS (left) part of string
and same for LAG's (right) part of string
anyway, if you could / want to rewrite this i will be happy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try using a site like regex101.com https://regex101.com/r/7utMDz/1
Sample code:
$string = '1/0/1-2,1/0/4-6,1/0/25,LAG1-2,LAG4';
preg_match_all('/LAG(\d+)(?:-(\d+))?/', $string, $matches);
foreach ($matches[1] as $index => $start) {
$end = $matches[2][$index] ?: $start;
for ($i = $start; $i <= $end; $i++) {
dump((int)$i);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hi @murrant
following your advice , the whole function was rewritten ...
function jetstreamExpand($var)
{
unset($result);
preg_match_all('/LAG(\d+)(?:-(\d+))?/', $var, $lags);
foreach ($lags[1] as $index => $start) {
$end = $lags[2][$index] ?: $start;
for ($i = $start; $i <= $end; $i++) {
$result[] = 'LAG' . $i; //need to be in form LAGx
}
}
preg_match_all('/1\/0\/(\d+)(?:-(\d+))?/', $var, $ports);
foreach ($ports[1] as $index => $start) {
$end = $ports[2][$index] ?: $start;
for ($i = $start; $i <= $end; $i++) {
$result[] = '1/0/' . $i; //need to be in form 1/0/x
}
}
return $result;
}
Please add test data so we can ensure your change is not broken in the future. Read the docs to find out how: https://docs.librenms.org/Developing/os/Test-Units |
Ok, i hope these files are enough for testing |
Please see this on how to generate it. And it needs to be commited also |
hi @Jellyfrog
ok and pushed to GIT |
Looks much better @Npeca75 I've generated the test data for you and uploaded it. Here is the command (since vlans is not enabled by default) |
} | ||
} else { | ||
$result[] = $element; | ||
preg_match_all('/LAG(\d+)(?:-(\d+))?/', $var, $lags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we could combine these two regex. :)
hi @murrant i get this error running snmpsim
Starting snmpsim listening on 127.1.6.1:1161... jetstream_t1600g-28ts: Could not connect to 127.1.6.1, please check the snmp details and snmp reachability |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
@Npeca75 it requires you have a working snmpsim on your system. |
This pull request has been mentioned on LibreNMS Community. There might be relevant details there: |
Vlans discovery on LAG ports on TP-LINK Jetstram OS was missing
DO NOT DELETE THE UNDERLYING TEXT
Please note
Testers
If you would like to test this pull request then please run:
./scripts/github-apply <pr_id>
, i.e./scripts/github-apply 5926
After you are done testing, you can remove the changes with
./scripts/github-remove
. If there are schema changes, you can ask on discord how to revert.