Comments (4)
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
/interface pppoe-client monitor ?
you'll see the output
<numbers> -- List of item numbers
append --
as-value --
do -- Execute given script after each time it prints stats on the screen
file --
interval -- Refresh information in selected time interval
once --
without-paging --
which tells you that the first unnamed argument is actually called "numbers".
In both console and in API, you can write:
/interface pppoe-client monitor numbers=pppoe-out1 once
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";
}
from net_routeros.
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.
As you can see the the var_dump, the details for status and uptime are there, in the array. I just am getting confused how to extract the ones I need.
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:
object(PEAR2\Net\RouterOS\ResponseCollection)#7 (8) { ["responses":protected]=> array(2) { [0]=> object(PEAR2\Net\RouterOS\Response)#4 (4) { ["unrecognizedWords":protected]=> array(0) { } ["_type":"PEAR2\Net\RouterOS\Response":private]=> string(3) "!re" ["attributes":protected]=> array(11) _**{ ["status"]=> string(9) "connected" ["uptime"]=> string(10) "1d15h47m1s"_ **["active-links"]=> string(1) "1" ["encoding"]=> string(0) "" ["service-name"]=> string(0) "" ["ac-name"]=> string(5) "bsjn1" ["ac-mac"]=> string(17) "28:94:0F:8E:26:00" ["mtu"]=> string(4) "1480" ["mru"]=> string(4) "1492" ["local-address"]=> string(15) "XXX.XXX.XXX.XXX" ["remote-address"]=> string(15) "XXX.XXX.XXX.XXX" } ["_tag":"PEAR2\Net\RouterOS\Message":private]=> NULL } [1]=> object(PEAR2\Net\RouterOS\Response)#5 (4) { ["unrecognizedWords":protected]=> array(0) { } ["_type":"PEAR2\Net\RouterOS\Response":private]=> string(5) "!done" ["attributes":protected]=> array(0) { } ["_tag":"PEAR2\Net\RouterOS\Message":private]=> NULL } } ["responseTypes":protected]=> array(2) { [0]=> string(3) "!re" [1]=> string(5) "!done" } ["responseTags":protected]=> array(2) { [0]=> NULL [1]=> NULL } ["responsesIndex":protected]=> array(0) { } ["propertyMap":protected]=> NULL ["position":protected]=> int(0) ["index":protected]=> NULL ["compareBy":protected]=> array(0) { } }
Thanks once again for you expertise and help.
from net_routeros.
Oh, silly me. I didn't noticed your other mistake... the usage of $responses->getType()
. As written, this will show you the type (!re
, !done
, etc.) of the first response (in your case !re
) so when you pass that into a foreach, you're looping over that string... Which I'm not sure if it's allowed at all, but if it is, you're looping over string characters.
Since you're using "once", you can just use getProperty() on the $responses
, and you'll get those in the first and only response from the router, i.e.
$responses->getProperty('status')
Otherwise, just loop over the responses, not the type, i.e.
foreach ($responses as $item) {
echo 'Status :', $item->getProperty('status');
}
from net_routeros.
Thanks. That worked perfectly.
from net_routeros.
Related Issues (20)
- utils find implementation error HOT 4
- Error installing with composer HOT 3
- Error in Codeigniter HOT 7
- phar file for download? HOT 1
- Getting router MAC address HOT 3
- 6.45.8 - authentication failure HOT 2
- Hi, i already updated script to login with version 6.43.
- Caracters <> doesnt show ? HOT 2
- Unable to connect to the router HOT 4
- Authentication problem from RouterOS 6.45.6 HOT 1
- Workflow question HOT 4
- $response->getType return "!re" - what's going on? HOT 2
- "LIKE" in query HOT 1
- Best practice to add a large list HOT 4
- exec() problem HOT 2
- Persistent connection HOT 3
- Call "all" option on Hotspot Server submenu to use in Users submenu HOT 3
- Why can't I enable, disable or remove Hotspot Users? HOT 2
- Unable to login ROS v6.47.10 (long-term)
- Random Mac Address HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from net_routeros.