phpapimikrotik

Saving Mikrotik Simple Queue Statistic PHP API


I want to save the statistics of the Mikrotik /simple queue using the PHP API. I have been able to pull the data but seems my implementation on the PHP side is a problem. The following is the code and the resulting array object.

foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
        // $lasArray = $queueEntry;
        print_r($queueEntry);
}

Excerpt for Result since its returning for all users in the office, I have choosen just to display for one user. Take it that PEAR2\Net\RouterOS\Response Object is retuned for all users, i.e all in this case over 50 users. I would like to save this data to database but only the relevant ones like [.id], [name], [target], [limit-at], [max-limit] and [bytes], any assistance here would be highly regarded.

PEAR2\Net\RouterOS\Response Object
(
    [unrecognizedWords:protected] => Array
        (
        )

    [_type:PEAR2\Net\RouterOS\Response:private] => !re
    [attributes:protected] => Array
        (
            [.id] => *12
            [name] => GikundaPhone
            [target] => 192.168.1.108/32
            [parent] => none
            [packet-marks] => 
            [priority] => 8/8
            [queue] => default-small/default-small
            [limit-at] => 128000/384000
            [max-limit] => 384000/384000
            [burst-limit] => 0/0
            [burst-threshold] => 0/0
            [burst-time] => 0s/0s
            [bucket-size] => 0.1/0.1
            [bytes] => 16515474/129310087
            [total-bytes] => 0
            [packets] => 127812/133712
            [total-packets] => 0
            [dropped] => 76/8667
            [total-dropped] => 0
            [rate] => 0/0
            [total-rate] => 0
            [packet-rate] => 0/0
            [total-packet-rate] => 0
            [queued-packets] => 0/0
            [total-queued-packets] => 0
            [queued-bytes] => 0/0
            [total-queued-bytes] => 0
            [invalid] => false
            [dynamic] => false
            [disabled] => false
        )

    [_tag:PEAR2\Net\RouterOS\Message:private] => 
)

Solution

  • Have found and answer to my own question. This is what I have done. The

    foreach ($util->setMenu('/queue simple')->getAll() as $queueEntry) {
            // $lasArray = $queueEntry;
            print_r($queueEntry);
    }
    

    provided alot of information thats unnecessary, so I have found about the routeros_api.class.php downloadable from here and followed but modified information from here. Then just used

        $address = 'IPV4_Address_of_router';
        $user    = 'username_of_router';
        $pass    = 'password_of_router';
        require('routeros_api.class.php');
    
        $API        = new routeros_api();
        $API->debug = false;    
    
        // router credentials and after including the routeros_api.cass.php
            if ($API->connect($address, $user, $pass)) {
    
                   $results = $API->comm("/queue/simple/print");
                    foreach ($results as $row) {
                        $clientName =  $row['name'];
                        $clientIP = $row['target'];
                        $clientMaxDown = $row['limit-at'];
                        $clientMaxUp = $row['max-limit'];
                        $clientDownloads = $row['bytes'];              
                    }
              }
    

    Only thing remaining was to save to database which is simple. Maybe someone may get helped someday by this.