luci-app-lldpd: Fix mysterious Command failed: Unknown error

Executing the following command:

ubus call luci.lldpd getStatus

always returned 'Command failed: Unknown error', but the underlying

lldpcli -f json0 show *

worked fine. Fixed with a chained ?.read?

Tested on 23.05.3

Signed-off-by: Paul Donald <newtwen+github@gmail.com>
This commit is contained in:
Paul Donald 2024-10-10 22:03:46 +02:00
parent 02f2d47102
commit c40253ada3
1 changed files with 12 additions and 12 deletions

View File

@ -3,20 +3,20 @@
import { popen } from 'fs'; import { popen } from 'fs';
function lldpcli_json(section) { function lldpcli_json(section) {
return json(popen(`lldpcli -f json0 show ${section}`, 'r')); return json(popen(`lldpcli -f json0 show ${section}`, 'r')?.read?.('all'));
} }
return { const methods = {
'luci.lldpd': { getStatus: {
getStatus: { call: function() {
call: function() { return {
return { statistics: lldpcli_json("statistics"),
statistics: lldpcli_json("statistics"), neighbors: lldpcli_json("neighbors details"),
neighbors: lldpcli_json("neighbors details"), interfaces: lldpcli_json("interfaces"),
interfaces: lldpcli_json("interfaces"), chassis: lldpcli_json("chassis")
chassis: lldpcli_json("chassis") };
};
}
} }
} }
}; };
return { 'luci.lldpd': methods };