Community discussions

MikroTik App
 
termax
just joined
Topic Author
Posts: 5
Joined: Fri Sep 16, 2011 10:40 pm

PHP API get RX etc.

Mon Jan 02, 2012 2:36 am

Hi,
how I can get via API rx/tx info?

I use http://wiki.mikrotik.com/wiki/API_PHP_class.

I tried this, but displays only the name. What's wrong?
<?php

require('routeros_api.class.php');

$API = new routeros_api();

$API->debug = false;

if ($API->connect('1.0.0.101', '0', '0')) {   // Change this as necessery

$ARRAY = $API->comm('/interface/print');
$ARRAY2 = $API->comm('/interface/print stats-detail from 0');
$ARRAY3 = $API->comm('/interface/monitor-traffic "Port 1 - WAN"');
   
$first = $ARRAY['0'];
$second = $ARRAY2['0'];
$third = $ARRAY3['0'];
  
echo "name: " . $first['name'] . " <br />";
echo "rx-byte: " . $second['rx-byte'] . " <br />";
echo "rx-bits-per-second: " . $third['rx-bits-per-second'] . " <br />";

$API->disconnect();

}

?>
 
User avatar
boen_robot
Forum Guru
Forum Guru
Posts: 2400
Joined: Thu Aug 31, 2006 4:43 pm
Location: europe://Bulgaria/Plovdiv

Re: PHP API get RX etc.

Mon Jan 02, 2012 3:03 am

With most clients, arguments must be written separately from the command, whereas you're writing them together. This results in an error response from RouterOS. You're not testing if what you're getting is an error, so trying to display something that is not there simply displays nothing.

Also, nameless arguments are not supported in API - you must explicitly write all argument names.

With my client, only the last requirement is still there. If you insist on using this client... I believe the comm() function accepts arguments to the command as a second argument that is an array, i.e.
$ARRAY = $API->comm('/interface/print');
$ARRAY2 = $API->comm('/interface/print', array('stats-detail' => '', 'from' => '0'));
$ARRAY3 = $API->comm('/interface/monitor-traffic', array('interface'=>"Port 1 - WAN"));
 

Who is online

Users browsing this forum: JoelPul and 23 guests