Cacti / plugin_mactrack

Mactrack Plugin for Cacti
GNU General Public License v2.0
12 stars 25 forks source link

QA: Avoid use of strlen() and some light PSR 7a0a625 breaks mactrack #225

Closed jdcoats closed 5 months ago

jdcoats commented 5 months ago
2024/06/17 09:22:51 - MACTRACK ERROR: Site not found in database. Can not continue.
2024/06/17 09:22:51 - MACTRACK ERROR: Site not found in database. Can not continue.
2024/06/17 09:22:51 - MACTRACK ERROR: Site not found in database. Can not continue.
TheWitness commented 5 months ago

Should be fixed now.

jdcoats commented 5 months ago
2024/06/17 15:24:00 - CMDPHP ERRORS DETECTED - DISABLING PLUGIN 'mactrack'
2024/06/17 15:24:00 - CMDPHP PHP ERROR Backtrace: (CactiShutdownHandler())
2024/06/17 15:24:00 - ERROR PHP ERROR in Plugin 'mactrack': Uncaught ValueError: substr_count(): Argument #2 ($needle) cannot be empty in /var/www/localhost/htdocs/cacti/plugins/mactrack/lib/mactrack_functions.php:345 Stack trace: #0 /var/www/localhost/htdocs/cacti/plugins/mactrack/lib/mactrack_functions.php(345): substr_count('.1.3.6.1.4.1.9....', '') #1 /var/www/localhost/htdocs/cacti/plugins/mactrack/mactrack_scanner.php(161): find_scanning_function(Array, Array) #2 {main} thrown in file: /var/www/localhost/htdocs/cacti/plugins/mactrack/lib/mactrack_functions.php on line: 345
jdcoats commented 5 months ago

@xxconn & @TheWitness okay so now we have this

2024/06/18 11:41:00 - CMDPHP PHP ERROR WARNING Backtrace: (/plugins/mactrack/mactrack_utilities.php[88]:mactrack_display_run_status(), /plugins/mactrack/mactrack_utilities.php[248]:CactiErrorHandler())
2024/06/18 11:41:00 - ERROR PHP WARNING in Plugin 'mactrack': Trying to access array offset on value of type null in file: /var/www/localhost/htdocs/cacti/plugins/mactrack/mactrack_utilities.php on line: 248
TheWitness commented 5 months ago

Awesome Dan. Thanks for confirming.

TheWitness commented 5 months ago

What is the value of mt_collection_timing in your case?

xxconn commented 5 months ago

I think the value of mt_collection_time is null at the first installation plugin and in PHP 8.1, it may raise this problem. I don't have PHP 8.1 runtime environment, so I cannot confirm the cause.

TheWitness commented 5 months ago

So, then we need a check and if null set_config_option() to the default.

Maybe a feature request to set all defaults, but that could be dangerous too.

jdcoats commented 5 months ago

dont know, it is still broken though, every time it starts a run it disables the plugin

TheWitness commented 5 months ago
SELECT * FROM settings WHERE name='mt_collection_timing;`
jdcoats commented 5 months ago

mt_collection_timing | 120 |

TheWitness commented 5 months ago

Refresh and try again.

TheWitness commented 5 months ago

Commit here.

https://github.com/Cacti/plugin_mactrack/commit/d51e6f5e1986a4c9366e538ccfee4ac8ec80415d

jdcoats commented 5 months ago

okay next run time in 40min

jdcoats commented 5 months ago

looks good now. Thanks!

xxconn commented 5 months ago

When I modify the code like this, I will show blank value in 'Poller Frequency' and write the error log:

2024-06-20 09:26:17 - CMDPHP PHP ERROR WARNING Backtrace: (/plugins/mactrack/mactrack_utilities.php[88]:mactrack_display_run_status(), /plugins/mactrack/mactrack_utilities.php[248]:CactiErrorHandler()) 2024-06-20 09:26:17 - ERROR PHP WARNING in Plugin 'mactrack': Undefined array key 7200 in file: /usr/share/cacti/plugins/mactrack/mactrack_utilities.php on line: 248

I think the $seconds_offset should be still divided by 60 into minutes to get the right poller frequency.

xxconn commented 5 months ago

@jdcoats

I have modified the new code, you could try it.

jdcoats commented 5 months ago

looks good, thanks!

TheWitness commented 5 months ago

Cool!!!