Cacti / plugin_thold

Thold Plugin for Cacti

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Log tab undefined variable

unka65 opened this issue · comments

commented

In testing the develop version as of a few days ago, I noted something minor in the log. When using Thold tab (/plugins/thold/thold_graph.php), sub tab Logs, the Cacti log has errors:

CMDPHP PHP ERROR WARNING Backtrace: (/plugins/thold/thold_graph.php[112]:thold_show_log(), /plugins/thold/thold_graph.php[1500]:CactiErrorHandler())
2023/08/30 08:39:28 - ERROR PHP WARNING in Plugin 'thold': Undefined variable $decimals in file: /usr/share/cacti/site/plugins/thold/thold_graph.php on line: 1500

CMDPHP PHP ERROR WARNING Backtrace: (/plugins/thold/thold_graph.php[112]:thold_show_log(), /plugins/thold/thold_graph.php[1501]:CactiErrorHandler())
2023/08/30 08:39:28 - ERROR PHP WARNING in Plugin 'thold': Undefined variable $decimals in file: /usr/share/cacti/site/plugins/thold/thold_graph.php on line: 1501

Were you already at Cacti 1.2.25 when you installed this thold? Let me know.

Basically, if you are not at Cacti 1.2.25, upgrade. After the upgrade is done, run this command:

UPDATE plugin_config SET version='1.7' WHERE directory='thold';

The go to the Thold Tab and the plugin will auto-upgrade. After which you should have the following columns in both thold_data and thold_template:

DESC thold_data;
<snip>
| syslog_facility             | int(2)           | YES  |     | NULL                |                |
| syslog_enabled              | char(3)          | NO   |     |                     |                |
| data_type                   | int(12)          | NO   |     | 0                   |                |
| show_units                  | char(3)          | NO   |     |                     |                |
| units_suffix                | varchar(10)      | NO   |     |                     |                |
| decimals                    | int(11)          | NO   |     | -1                  |                |
<snip>
commented

Thank you for responding. Cacti might have been 1.2.24 when thold was updated but is now 1.2.25 (I plan to rebuild and test again). The tables have those columns. I ran the SQL update to revert the plugin version and went to the Thold tab. The plugin version updated. With the base code, the error occurred.

I noticed in function thold_show_log() that other values are retrieved individually but not decimals and so I wondered if decimals retrieval is missing.

$show_units   = (db_fetch_cell_prepared('SELECT show_units FROM thold_data WHERE id = ?', array($l['threshold_id'])) ? true : false);
$units_suffix = db_fetch_cell_prepared('SELECT units_suffix FROM thold_data WHERE id = ?', array($l['threshold_id']));
...
form_selectable_cell($l['threshold_value'] != '' ? thold_format_number($l['threshold_value'], $decimals, $baseu, $suffix, $show_units, $units_suffix):__('N/A', 'thold'), $l['id'], '', 'right');
form_selectable_cell($l['current'] != '' ? thold_format_number($l['current'], $decimals, $baseu, $suffix, $show_units, $units_suffix):__('N/A', 'thold'), $l['id'], '', 'right');

If the error is only in my setup and still after a clean rebuild, I will just modify my copy to eliminate the error.

(I wondered if it and some of the other values could be added the base query in get_allowed_threshold_logs() instead of retrieving each for each log entry but I noticed that would also include them in the export and so probably the reason for the separate queries.)

I struggled to associate a log entry with a threshold until I added name_cache to the log columns (required adding to the base query). A link to the threshold would be even better. Just a thought.

Can you log a separate feature request?

commented

I will look into the thold log enhancements.

I scratch built a server with Cacti 1.2.25 and Thold as of September 7, 2023. I migrated data from Cacti 1.2.24 and Thold 1.5.3. I went to the Thold tab (thold_graph.php) to trigger the database upgrade. Table thold_data had the decimals column.

The Thold tab, log page still generated the undefined variable $decimals error and the measured values had no decimals.

I added the following In thold_graph.php function thold_show_log() at line 1490 with the other specific value queries to eliminate the error and correct the measured value format,

$decimals = db_fetch_cell_prepared('SELECT decimals FROM thold_data WHERE id = ?', array($l['threshold_id']));

(A different item but about decimals, in the thold template edit prompt "Decimal Digits to Display" drop down has "3 digits" listed twice: arrays.php line 572).

Do you know how to create a pull request in GitHub? Maybe @xmacan can assist you.

@unka65 Thank you for your help!

Appreciate it too!