-
Notifications
You must be signed in to change notification settings - Fork 119
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
Get Flag value and PPPOE conenction data #21
Comments
With the API protocol, "yes" and "no" values are replaced with "true" and "false" on most places, which is why neither of your checks work. Also, there's no ".list" property or argument, only "list". If you want to limit the responses to show only the value of "list", use the argument ".proplist" with a value of "list" instead. So, to get the list names of all disabled items, you can use: $util->setMenu('/ip firewall address-list');
foreach ($util->getAll(array('.proplist' => 'list'), RouterOS\Query::where('disabled', 'true')) as $item) {
echo $item->getProperty('list');
} Unnamed arguments are not supported, since there's no way they can be reliably guessed. In console, if you type
you'll see the output
which tells you that the first unnamed argument is actually called "numbers". In both console and in API, you can write:
which in console is equivalent to what you have. So: $responses = $client->sendSync(new RouterOS\Request('/interface pppoe-client monitor numbers=pppoe-out1 once'));
foreach ($responses->getType() as $item) {
echo 'STATUS: ', $item->getProperty('status'),
"\n";
} |
I still didn't manage to get the PPPOE status to work. The getProperty doesn't seem to match any of the fields. I always get a blank page. Actually I am still learning php, therefore, I am not really understanding what the var_dump output means in relation to the API client. Here is the code I am using and a var_dump result <?php
use PEAR2\Net\RouterOS;
require_once 'PEAR2/Autoload.php';
$client = new RouterOS\Client('192.168.1.1', 'user', 'password');
$responses = $client->sendSync(new RouterOS\Request('/interface pppoe-client monitor numbers=pppoe-out1 once'));
foreach ($responses->getType() as $item){
echo 'Status :', $item->getProperty('status');
}
?> VAR_DUMP:
Thanks once again for you expertise and help. |
Oh, silly me. I didn't noticed your other mistake... the usage of Since you're using "once", you can just use getProperty() on the $responses->getProperty('status') Otherwise, just loop over the responses, not the type, i.e. foreach ($responses as $item) {
echo 'Status :', $item->getProperty('status');
} |
Thanks. That worked perfectly. |
QUESTION 1
Hi,
I am attempting retrieve the flag data of an address-list entry to check whether it is disabled or enabled, however none of the following worked.
$printRequest = new RouterOS\Request('/ip firewall address-list print');
$printRequest->setArgument('.list');
$printRequest->setQuery(RouterOS\Query::where('disabled', 'yes'));
echo $name = $client->sendSync($printRequest)->getProperty('.list');
or this
$util->setMenu('/ip firewall address-list');
foreach ($util->getAll() as $item) {
if ('yes' ===$item('disabled')){
echo $item->getProperty('list');
} else {
echo $item->getProperty('list');
}
}
When I use as-value on the console nothing is reported, however, when I use value-list, I get the disabled items I need.
/ip firewall address-list> print value-list where disabled=yes
list: Family Android All
address: 192.168.1.91 192.168.1.94 192.168.1.90-192.168.1.119
dynamic: no no no
/ip firewall address-list> print as-value where disabled=yes
nothing
QUESTION 2
Also tried to retrieve data about my PPPOE internet connection:
/ip firewall address-list> /interface pppoe-client monitor pppoe-out1 once
status: connected
uptime: 22h42m58s
active-links: 1
encoding:
service-name:
ac-name: bsjn1
ac-mac: 28:94:0F:8E:26:00
mtu: 1480
mru: 1492
local-address: xxx.xxx.xxx.xxx
with this script, however, I get an empty page
$responses = $client->sendSync(new RouterOS\Request('/interface pppoe-client monitor pppoe-out1 once'));
foreach ($responses->getType() as $item){
echo 'STATUS: ', $item->getProperty('status'),
"\n";
}
The text was updated successfully, but these errors were encountered: