Skip to content

Commit

Permalink
Updating for Cacti 1.2.24
Browse files Browse the repository at this point in the history
  • Loading branch information
TheWitness committed Jan 28, 2023
1 parent f5a1006 commit 3784700
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 39 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

--- develop ---

--- 3.0 ---

* issue: When combined with Cacti's new test data source, errors in scripts are thrown

* issue: Move the package location for scripts and resource files to the correct location
Expand All @@ -21,6 +23,8 @@

* feature: Add the Mikrotik Switch OS Device Package

* feature: Minimum Cacti version 1.2.24

--- 2.5 ---

* issue#36: Mikrotik Plugin -- simple queue issue
Expand Down
4 changes: 2 additions & 2 deletions INFO
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[info]
name = mikrotik
version = 2.6
version = 3.0
longname = MikroTik Switch Tool
author = The Cacti Group
email =
homepage = http://www.cacti.net
compat = 1.2.11
compat = 1.2.24
capabilities = online_view:1, online_mgmt:0, offline_view:0, offline_mgmt:0, remote_collect:0
49 changes: 14 additions & 35 deletions RouterOS/routeros_api.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*
******************************/

class RouterosAPI
{
class RouterosAPI {
var $debug = false; // Show debug information
var $connected = false; // Connection state
var $port = 8728; // Port to connect to (default 8729 for ssl)
Expand All @@ -30,8 +29,7 @@ class RouterosAPI
var $error_str; // Variable for storing connection error text, if any

/* Check, can be var used in foreach */
public function isIterable($var)
{
public function isIterable($var) {
return $var !== null
&& (is_array($var)
|| $var instanceof Traversable
Expand All @@ -47,23 +45,20 @@ public function isIterable($var)
*
* @return void
*/
public function debug($text)
{
public function debug($text) {
if ($this->debug) {
echo $text . "\n";
}
}


/**
*
*
* @param string $length
*
* @return void
*/
public function encodeLength($length)
{
public function encodeLength($length) {
if ($length < 0x80) {
$length = chr($length);
} elseif ($length < 0x4000) {
Expand All @@ -82,7 +77,6 @@ public function encodeLength($length)
return $length;
}


/**
* Login to RouterOS
*
Expand All @@ -92,8 +86,7 @@ public function encodeLength($length)
*
* @return boolean If we are connected or not
*/
public function connect($ip, $login, $password)
{
public function connect($ip, $login, $password) {
for ($ATTEMPT = 1; $ATTEMPT <= $this->attempts; $ATTEMPT++) {
$this->connected = false;
$PROTOCOL = ($this->ssl ? 'ssl://' : '' );
Expand Down Expand Up @@ -143,14 +136,12 @@ public function connect($ip, $login, $password)
return $this->connected;
}


/**
* Disconnect from RouterOS
*
* @return void
*/
public function disconnect()
{
public function disconnect() {
// let's make sure this socket is still valid. it may have been closed by something else
if( is_resource($this->socket) ) {
fclose($this->socket);
Expand All @@ -159,16 +150,14 @@ public function disconnect()
$this->debug('Disconnected...');
}


/**
* Parse response from Router OS
*
* @param array $response Response data
*
* @return array Array with parsed data
*/
public function parseResponse($response)
{
public function parseResponse($response) {
if (is_array($response)) {
$PARSED = array();
$CURRENT = null;
Expand Down Expand Up @@ -201,16 +190,14 @@ public function parseResponse($response)
}
}


/**
* Parse response from Router OS
*
* @param array $response Response data
*
* @return array Array with parsed data
*/
public function parseResponse4Smarty($response)
{
public function parseResponse4Smarty($response) {
if (is_array($response)) {
$PARSED = array();
$CURRENT = null;
Expand Down Expand Up @@ -244,16 +231,14 @@ public function parseResponse4Smarty($response)
}
}


/**
* Change "-" and "/" from array key to "_"
*
* @param array $array Input array
*
* @return array Array with changed key names
*/
public function arrayChangeKeyName(&$array)
{
public function arrayChangeKeyName(&$array) {
if (is_array($array)) {
foreach ($array as $k => $v) {
$tmp = str_replace("-", "_", $k);
Expand All @@ -270,16 +255,14 @@ public function arrayChangeKeyName(&$array)
}
}


/**
* Read data from Router OS
*
* @param boolean $parse Parse the data? default: true
*
* @return array Array with parsed or unparsed data
*/
public function read($parse = true)
{
public function read($parse = true) {
$RESPONSE = array();
$receiveddone = false;
while (true) {
Expand Down Expand Up @@ -353,7 +336,6 @@ public function read($parse = true)
return $RESPONSE;
}


/**
* Write (send) data to Router OS
*
Expand All @@ -365,8 +347,7 @@ public function read($parse = true)
*
* @return boolean Return false if no command especified
*/
public function write($command, $param2 = true)
{
public function write($command, $param2 = true) {
if ($command) {
$data = explode("\n", $command);
foreach ($data as $com) {
Expand All @@ -388,7 +369,6 @@ public function write($command, $param2 = true)
}
}


/**
* Write (send) data to Router OS
*
Expand All @@ -397,8 +377,7 @@ public function write($command, $param2 = true)
*
* @return array Array with parsed
*/
public function comm($com, $arr = array())
{
public function comm($com, $arr = array()) {
$count = count($arr);
$this->write($com, !$arr);
$i = 0;
Expand Down Expand Up @@ -429,8 +408,8 @@ public function comm($com, $arr = array())
*
* @return void
*/
public function __destruct()
{
public function __destruct() {
$this->disconnect();
}
}

4 changes: 2 additions & 2 deletions mikrotik.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ function clearFilter() {
$sql_limit = ' LIMIT ' . ($rows*(get_request_var('page')-1)) . ', ' . $rows;

$sql = "SELECT mti.*, h.hostname, h.description, h.disabled,
({$pref}RxTooShort+{$pref}RxTooLong+{$pref}RxFCFSError+{$pref}RxAlignError+{$pref}RxFragment+{$pref}RxOverflow+{$pref}RxUnknownOp+{$pref}RxLengthError+{$pref}RxCodeError+{$pref}RxCarrierError+{$pref}RxJabber+{$pref}RxDrop) AS RxErrors,
({$pref}TxTooShort+{$pref}TxTooLong+{$pref}TxUnderrun+{$pref}TxCollision+{$pref}TxExCollision+{$pref}TxMultCollision+{$pref}TxSingCollision+{$pref}TxLateCollision+{$pref}TxDrop+{$pref}TxJabber+{$pref}TxFCFSError) AS TxErrors
(${pref}RxTooShort+${pref}RxTooLong+${pref}RxFCFSError+${pref}RxAlignError+${pref}RxFragment+${pref}RxOverflow+${pref}RxUnknownOp+${pref}RxLengthError+${pref}RxCodeError+${pref}RxCarrierError+${pref}RxJabber+${pref}RxDrop) AS RxErrors,
(${pref}TxTooShort+${pref}TxTooLong+${pref}TxUnderrun+${pref}TxCollision+${pref}TxExCollision+${pref}TxMultCollision+${pref}TxSingCollision+${pref}TxLateCollision+${pref}TxDrop+${pref}TxJabber+${pref}TxFCFSError) AS TxErrors
FROM plugin_mikrotik_interfaces AS mti
INNER JOIN host AS h
ON h.id=mti.host_id
Expand Down

0 comments on commit 3784700

Please sign in to comment.