Cacti / plugin_monitor

Monitor Plugin for Cacti
GNU General Public License v2.0
36 stars 39 forks source link

monitor plugin crashes with Uncaught TypeError #171

Closed sgvfr closed 6 months ago

sgvfr commented 6 months ago

Describe the bug in the last week of commits and changes, my monitor plugin crashed, and continues to crash when re-enabled in plugin management. I did try hard resets to the newest code but the problem remains. I'm staying on cacti 4563aaa1d for now because of a separate issue (pinging/advanced ping template seems to stop after 011ae4c but I need to find some more time to test further with pulling in steps to verify)

PHP 8.1.27 (cli) (built: Dec 21 2023 20:19:54) (NTS) SPINE 1.2.25 Copyright 2004-2023 by The Cacti Group

Cacti: 4563aaa1d (HEAD -> develop) Deleted translation using Weblate (English (Old)) plugin_monitor: 396fa1d (HEAD -> develop) Update translation files

2024-01-31 10:12:19 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'monitor'
2024-01-31 10:12:19 - PHP ERROR Backtrace: (CactiShutdownHandler())
2024-01-31 10:12:19 - ERROR PHP ERROR in Plugin 'monitor': Uncaught TypeError: date(): Argument #2 ($timestamp) must be of type ?int, float given in /var/www/html/cacti/plugins/monitor/poller_monitor.php:240 Stack trace: #0 /var/www/html/cacti/plugins/monitor/poller_monitor.php(240): date() #1 /var/www/html/cacti/plugins/monitor/poller_monitor.php(87): monitor_uptime_checker() #2 {main} thrown in file: /var/www/html/cacti/plugins/monitor/poller_monitor.php on line: 240
xmacan commented 6 months ago

Please show result of sql query: describe host; Column snmp_sysUpTimeInstance must be bigint(20) unsigned NOT NULL DEFAULT 0 Have you here different definition?

You can try change one line 240 in setup.php from: array($host['id'], date('Y-m-d H:i:s', (time()-$host['snmp_sysUpTimeInstance']))); to array($host['id'], date('Y-m-d H:i:s', (time()-intval($host['snmp_sysUpTimeInstance']))));

sgvfr commented 6 months ago

hi,

+------------------------+-----------------------+------+-----+---------------------+-------------------------------+ | Field | Type | Null | Key | Default | Extra | +------------------------+-----------------------+------+-----+---------------------+-------------------------------+ | snmp_sysUpTimeInstance | bigint(20) unsigned | NO | | 0 | |

it's not exactly how you say it should be. Would that be the cause of the problem for me?

xmacan commented 6 months ago

Error is "($timestamp) must be of type int, float given" It is here: (time()-$host['snmp_sysUpTimeInstance']) - error says that this isn't integer but float. Time always returns int. $host... is bigint. So no float.

Sorry - I made mistake in workaround: You can try change one line 240 in poller_monitor.php from: array($host['id'], date('Y-m-d H:i:s', (time()-$host['snmp_sysUpTimeInstance']))); to array($host['id'], date('Y-m-d H:i:s', (time()-intval($host['snmp_sysUpTimeInstance']))));

sgvfr commented 6 months ago

that seems to have fixed it, the error is gone, and the plugin remained enabled.

xmacan commented 6 months ago

Ok, wait few hours and let me know

sgvfr commented 6 months ago

2 hours. still no errors, and plugin has not disabled.

TheWitness commented 5 months ago

Great!

TheWitness commented 5 months ago

@xmacan,

It's not float, but bigint.

| snmp_community         | varchar(100)          | YES  |     | NULL                |                               |
| snmp_version           | tinyint(3) unsigned   | NO   |     | 1                   |                               |
| snmp_username          | varchar(50)           | YES  |     | NULL                |                               |
| snmp_password          | varchar(50)           | YES  |     | NULL                |                               |
| snmp_auth_protocol     | char(6)               | YES  |     |                     |                               |
| snmp_priv_passphrase   | varchar(200)          | YES  |     |                     |                               |
| snmp_priv_protocol     | char(6)               | YES  |     |                     |                               |
| snmp_context           | varchar(64)           | YES  |     |                     |                               |
| snmp_engine_id         | varchar(64)           | YES  |     |                     |                               |
| snmp_port              | mediumint(8) unsigned | NO   |     | 161                 |                               |
| snmp_timeout           | mediumint(8) unsigned | NO   |     | 500                 |                               |
| snmp_sysDescr          | varchar(300)          | NO   |     |                     |                               |
| snmp_sysObjectID       | varchar(128)          | NO   |     |                     |                               |
| snmp_sysUpTimeInstance | bigint(20) unsigned   | NO   |     | 0                   |                               |
| snmp_sysContact        | varchar(300)          | NO   |     |                     |                               |
| snmp_sysName           | varchar(300)          | NO   |     |                     |                               |
| snmp_sysLocation       | varchar(300)          | NO   |     |                     |                               |