From 37847006dfb287c88ee2b8a5545e31bf2289033b Mon Sep 17 00:00:00 2001 From: TheWitness Date: Sat, 28 Jan 2023 13:20:02 -0500 Subject: [PATCH] Updating for Cacti 1.2.24 --- CHANGELOG.md | 4 +++ INFO | 4 +-- RouterOS/routeros_api.class.php | 49 ++++++++++----------------------- mikrotik.php | 4 +-- 4 files changed, 22 insertions(+), 39 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c856839..5cafc21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 @@ -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 diff --git a/INFO b/INFO index cf1ae50..31274aa 100644 --- a/INFO +++ b/INFO @@ -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 diff --git a/RouterOS/routeros_api.class.php b/RouterOS/routeros_api.class.php index 5b8643c..28e242d 100644 --- a/RouterOS/routeros_api.class.php +++ b/RouterOS/routeros_api.class.php @@ -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) @@ -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 @@ -47,14 +45,12 @@ public function isIterable($var) * * @return void */ - public function debug($text) - { + public function debug($text) { if ($this->debug) { echo $text . "\n"; } } - /** * * @@ -62,8 +58,7 @@ public function debug($text) * * @return void */ - public function encodeLength($length) - { + public function encodeLength($length) { if ($length < 0x80) { $length = chr($length); } elseif ($length < 0x4000) { @@ -82,7 +77,6 @@ public function encodeLength($length) return $length; } - /** * Login to RouterOS * @@ -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://' : '' ); @@ -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); @@ -159,7 +150,6 @@ public function disconnect() $this->debug('Disconnected...'); } - /** * Parse response from Router OS * @@ -167,8 +157,7 @@ public function disconnect() * * @return array Array with parsed data */ - public function parseResponse($response) - { + public function parseResponse($response) { if (is_array($response)) { $PARSED = array(); $CURRENT = null; @@ -201,7 +190,6 @@ public function parseResponse($response) } } - /** * Parse response from Router OS * @@ -209,8 +197,7 @@ public function parseResponse($response) * * @return array Array with parsed data */ - public function parseResponse4Smarty($response) - { + public function parseResponse4Smarty($response) { if (is_array($response)) { $PARSED = array(); $CURRENT = null; @@ -244,7 +231,6 @@ public function parseResponse4Smarty($response) } } - /** * Change "-" and "/" from array key to "_" * @@ -252,8 +238,7 @@ public function parseResponse4Smarty($response) * * @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); @@ -270,7 +255,6 @@ public function arrayChangeKeyName(&$array) } } - /** * Read data from Router OS * @@ -278,8 +262,7 @@ public function arrayChangeKeyName(&$array) * * @return array Array with parsed or unparsed data */ - public function read($parse = true) - { + public function read($parse = true) { $RESPONSE = array(); $receiveddone = false; while (true) { @@ -353,7 +336,6 @@ public function read($parse = true) return $RESPONSE; } - /** * Write (send) data to Router OS * @@ -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) { @@ -388,7 +369,6 @@ public function write($command, $param2 = true) } } - /** * Write (send) data to Router OS * @@ -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; @@ -429,8 +408,8 @@ public function comm($com, $arr = array()) * * @return void */ - public function __destruct() - { + public function __destruct() { $this->disconnect(); } } + diff --git a/mikrotik.php b/mikrotik.php index b7cab9e..dc0ba0f 100755 --- a/mikrotik.php +++ b/mikrotik.php @@ -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