Code Monkey home page Code Monkey logo

Comments (4)

boenrobot avatar boenrobot commented on July 30, 2024

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.

etiennesw avatar etiennesw commented on July 30, 2024

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.

boenrobot avatar boenrobot commented on July 30, 2024

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.

etiennesw avatar etiennesw commented on July 30, 2024

Thanks. That worked perfectly.

from net_routeros.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.