Skip to content

Commit

Permalink
Fixing multiple issues
Browse files Browse the repository at this point in the history
* issue: Data Query Graphs with spaces in their indexes not working.  This is Cacti issue fixed in 1.2.280
* issue: Don't captitalize everything including Queues, etc.
* issue: Fix some PHP8 errors in Graph Automation
* issue: Update Data Queries to allow Spaces and Underscores
  • Loading branch information
TheWitness committed Jun 12, 2024
1 parent 0a3f46b commit 2fc73c4
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 97 deletions.
57 changes: 9 additions & 48 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,117 +2,78 @@
--- develop ---

* issue#78: SQL Syntax Error in poller_mikrotik.php
* issue: Data Query Graphs with spaces in their indexes not working. This is Cacti issue fixed in 1.2.280
* issue: Don't captitalize everything including Queues, etc.
* issue: Fix some PHP8 errors in Graph Automation
* issue: Update Data Queries to allow Spaces and Underscores

--- 3.1 ---

* issue: Devices packages pointing to incorrect locations

--- 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

* issue#61: PLUGIN WARNING: Function does not exist config_form with function
mikrotik_config_form

* 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
* issue#61: PLUGIN WARNING: Function does not exist config_form with function mikrotik_config_form
* issue#62: PHP DEPRECATED warnings in mikrotik plugin

* issue#63: ERROR PHP DEPRECATED in Plugin 'mikrotik': str_replace() in
poller_graphs.php on line: 386

* issue#63: ERROR PHP DEPRECATED in Plugin 'mikrotik': str_replace() in poller_graphs.php on line: 386
* feature: Add Device ID's to MikroTik API stats to track password failures

* feature: Add DNS Cache to MikroTik Plugin

* feature: Add Address Lists to MikroTik Plugin

* feature: Add DHCP Leases to Device Template

* feature: Add the Mikrotik Switch OS Device Package

* feature: Minimum Cacti version 1.2.24

--- 2.5 ---

* issue#36: Mikrotik Plugin -- simple queue issue

* feature: Allow disablement of API data collection

* feature: Moving from images to glyphs

* feature: Minimum version Cacti 1.2.11

* issue: Internationalization issues on console


--- 2.4 ---

* issue: Properly display uptime for Wireless Registrations

* issue: Do not log when a device does not have DHCP enabled

* issue: Workaround issues with the SNMP client and voltage, power, ampere and
temperature reporting

* issue: Workaround issues with the SNMP client and voltage, power, ampere and temperature reporting
* feature: Specify a retention time for DHCP Registrations


--- 2.3 ---

* issue#31: Handle case where 'dhcp' package is not installed

* issue#32: No Uptime and a non mikrotik device detected

* issue#35: Login Failure for RouterOS Login method post-v6.43

* feature: PHP 7.2 compatibility


--- 2.2 ---

* feature: Add DHCP table to view DHCP registrations

* issue#23: The health values are showed without dot

* issue: Undefined offset when attempting to connect to Mikrotik

* issue: MikroTik Uptime not reporting correctly


--- 2.1 ---

* issue: Resolve issues when you attempt to sort on reserved word

* issue: Properly remove aged Wireless AP interfaces

* issue: Remove dependency on custom snmp.php module

* feature: Add wireless registrations table view to show all registrations

* feature: Roll out Cacti sort API to support multiple column sort


--- 2.0 ---

* issue#10: SQL Error when sorting from the Wireless Aps page

* issue#12: All pages lack navigation

* feature: Support for Cacti 1.0

* feature: Lot's of new features

* feature: Update text domain for i18n


--- 1.01 ---

* bug#0002318: Invalid round robin archive


--- 1.0 ---

* Initial release
Expand Down
101 changes: 55 additions & 46 deletions poller_graphs.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,14 +260,14 @@ function mikrotik_gt_graph($host_id, $graph_template_id) {
AND graph_template_id=$graph_template_id");

if (!$exists) {
print "NOTE: Adding Graph: '$name' for Host: " . $host_id . "\n";
print "NOTE: Adding Graph: '$name' for Host: " . $host_id . PHP_EOL;

$command = "$php_bin -q $base/cli/add_graphs.php" .
" --graph-template-id=$graph_template_id" .
" --graph-type=cg" .
" --host-id=" . $host_id;

print str_replace("\n", " ", passthru($command)) . "\n";
execute_automation($command, 'Template Graph');
}
}

Expand All @@ -281,10 +281,16 @@ function add_summary_graphs($host_id, $host_template) {
if (empty($host_id)) {
/* add the host */
debug('Adding Host');
$result = exec("$php_bin -q $base/cli/add_device.php --description='Summary Device' --ip=summary --template=$host_template --version=0 --avail=none", $return_code);

$command = "$php_bin -q $base/cli/add_device.php --description='Summary Device' --ip=summary --template=$host_template --version=0 --avail=none";

execute_automation($command, 'Device Creation');
} else {
debug('Reindexing Host');
$result = exec("$php_bin -q $base/cli/poller_reindex_hosts.php -id=$host_id -qid=All", $return_code);

$command = "$php_bin -q $base/cli/poller_reindex_hosts.php -id=$host_id -qid=All";

execute_automation($command, 'Device Re-Index');
}

/* data query graphs first */
Expand All @@ -294,44 +300,44 @@ function add_summary_graphs($host_id, $host_template) {
WHERE host_id=$host_id");

if (cacti_sizeof($data_queries)) {
foreach($data_queries as $dq) {
$graph_templates = db_fetch_assoc("SELECT *
FROM snmp_query_graph
WHERE snmp_query_id=" . $dq['snmp_query_id']);

if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
mikrotik_dq_graphs($host_id, $dq['snmp_query_id'], $gt['graph_template_id'], $gt['id']);
}
foreach($data_queries as $dq) {
$graph_templates = db_fetch_assoc("SELECT *
FROM snmp_query_graph
WHERE snmp_query_id=" . $dq['snmp_query_id']);

if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
mikrotik_dq_graphs($host_id, $dq['snmp_query_id'], $gt['graph_template_id'], $gt['id']);
}
}
}
}
}

debug('Processing Graph Templates');
$graph_templates = db_fetch_assoc("SELECT *
FROM host_graph
WHERE host_id=$host_id");

if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
/* see if the graph exists already */
$exists = db_fetch_cell("SELECT count(*)
FROM graph_local
WHERE host_id=$host_id
AND graph_template_id=" . $gt["graph_template_id"]);
foreach($graph_templates as $gt) {
/* see if the graph exists already */
$exists = db_fetch_cell("SELECT count(*)
FROM graph_local
WHERE host_id=$host_id
AND graph_template_id=" . $gt["graph_template_id"]);

if (!$exists) {
print "NOTE: Adding item: '$field_value' for Host: " . $host_id;
if (!$exists) {
print "NOTE: Adding item: '$field_value' for Host: " . $host_id;

$command = "$php_bin -q $base/cli/add_graphs.php" .
" --graph-template-id=" . $gt["graph_template_id"] .
" --graph-type=cg" .
" --host-id=" . $host_id;
$command = "$php_bin -q $base/cli/add_graphs.php" .
" --graph-template-id=" . $gt["graph_template_id"] .
" --graph-type=cg" .
" --host-id=" . $host_id;

print str_replace("\n", " ", passthru($command)) . "\n";
execute_automation($command, 'Template Graphs');
}
}
}
}
}

function mikrotik_dq_graphs($host_id, $query_id, $graph_template_id, $query_type_id, $field = '', $regex = '', $include = true) {
Expand Down Expand Up @@ -383,29 +389,32 @@ function mikrotik_dq_graphs($host_id, $query_id, $graph_template_id, $query_type
" --snmp-query-id=$query_id --snmp-field=$field" .
" --snmp-value=" . cacti_escapeshellarg($field_value);

$return = 0;
$output = array();
execute_automation($command, 'Data Query Graph');
}
}
}
}

$lline = exec($command, $output, $return);
function execute_automation($command, $type) {
$return = 0;
$output = array();

if ($return != 0) {
print "WARNING: Error for Graph command and item '$field_value' Error Code:'$return'. Results below." . PHP_EOL;
$lline = exec($command, $output, $return);

if (sizeof($output)) {
foreach($output as $l) {
print trim("WARNING DATA: " . $l) . PHP_EOL;
}
}
} else {
print trim("NOTE: Graph command for item: '$field_value' succeeded. Results relow") . PHP_EOL;
if ($return > 0) {
print "WARNING: Error for $type command and item '$field_value' Error Code:'$return'. Results below." . PHP_EOL;

if (sizeof($output)) {
foreach($output as $l) {
print trim("WARNING DATA: " . $l) . PHP_EOL;
}
}
}
if (sizeof($output)) {
foreach($output as $l) {
print trim('WARNING Response: ' . $l) . PHP_EOL;
}
}
} else {
print trim("NOTE: $type command for item: '$field_value' succeded. Results relow") . PHP_EOL;

if (sizeof($output)) {
foreach($output as $l) {
print trim('Response: ' . $l) . PHP_EOL;
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions poller_mikrotik.php
Original file line number Diff line number Diff line change
Expand Up @@ -1180,7 +1180,7 @@ function collectHostIndexedOid(&$host, $tree, $table, $name, $preserve = false,
$parts = explode('.', $splitIndex[1]);
$index = '';
for ($i = 0; $i < 6; $i++) {
$index .= ($i>0 ? ':':'') . strtoupper(substr('0' . dechex($parts[$i]), -2));
$index .= ($i>0 ? ':':'') . substr('0' . dechex($parts[$i]), -2);
}
} else {
$index = $splitIndex[1];
Expand All @@ -1197,7 +1197,7 @@ function collectHostIndexedOid(&$host, $tree, $table, $name, $preserve = false,
$new_array[$index][$key] = 14;
}
} elseif ($key == 'name') {
$new_array[$index][$key] = str_replace('<', '', str_replace('>', '', strtoupper($mib['value'])));
$new_array[$index][$key] = str_replace('<', '', str_replace('>', '', $mib['value']));
} elseif ($key == 'date') {
$new_array[$index][$key] = mikrotik_dateParse($mib['value']);
} elseif ($key == 'mac') {
Expand Down Expand Up @@ -1697,7 +1697,7 @@ function collect_pppoe_users_api(&$host) {
if (cacti_sizeof($array)) {
foreach($array as $row) {
if (!isset($row['name'])) continue;
$name = strtoupper($row['name']);
$name = $row['name'];
if (isset($users[$name])) {
$user = $users[$name];

Expand Down

0 comments on commit 2fc73c4

Please sign in to comment.