rbicelli / pfsense-zabbix-template

Zabbix Template for pfSense
Apache License 2.0
238 stars 107 forks source link

Broken PHP script on pfSense 23.01 #132

Closed RomLecat closed 1 year ago

RomLecat commented 1 year ago

Hello,

Since the 23.01 upgrade, the PHP script doesn't work anymore (likely related to the switch to PHP 8.1):

PHP Errors:
[19-Feb-2023 11:31:15 Europe/Paris] PHP Fatal error:  Uncaught Error: Undefined constant "crt" in /root/scripts/pfsense_zbx.php:1127
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1339): pfz_get_cert_date('validTo.min')
#1 {main}
  thrown in /root/scripts/pfsense_zbx.php on line 1127
[19-Feb-2023 11:31:43 Europe/Paris] PHP Fatal error:  Uncaught TypeError: count(): Argument #1 ($value) must be of type Countable|array, null given in /root/scripts/pfsense_zbx.php:976
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1022): pfz_dhcp_get('failover')
#1 /root/scripts/pfsense_zbx.php(1035): pfz_dhcp_check_failover()
#2 /root/scripts/pfsense_zbx.php(1323): pfz_dhcp('failover', NULL)
#3 {main}
  thrown in /root/scripts/pfsense_zbx.php on line 976
[19-Feb-2023 11:32:08 Europe/Paris] PHP Fatal error:  Uncaught Error: Undefined constant "crt" in /root/scripts/pfsense_zbx.php:1121
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1339): pfz_get_cert_date('validFrom.max')
#1 {main}
  thrown in /root/scripts/pfsense_zbx.php on line 1121
[19-Feb-2023 11:32:15 Europe/Paris] PHP Fatal error:  Uncaught Error: Undefined constant "crt" in /root/scripts/pfsense_zbx.php:1127
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1339): pfz_get_cert_date('validTo.min')
#1 {main}
  thrown in /root/scripts/pfsense_zbx.php on line 1127
yvesaccoe commented 1 year ago

Hi,

We upgraded to Zabbix 6.0 .. for the latest agent 6.0 we needed to upgrade to pFsense 23.01. Which has php 8.1.. Any help would be appreciated ..

LegsAJimbo commented 1 year ago

DISCLAIMER: I HAVE NO CLUE WHAT I AM DOING!

I'm not entirely sure whether this creates the desired behaviour or not, but is has suppressed the errors for me

It does seem that the is_countable may have the same effect as count > 0 and putting both like I have is pointless.

It may be that the variables are the incorrect data type as required by the php upgrade, so my modifications are preventing the duplicate removal functions from happening.

It may be that the variable does not exist yet, intentionally or not, and count is being used to check it's existence. If that is the case then I believe this should be a viable solution.

With that said, I managed to suppress the error by changing line 978 from: if (count($leases) > 0) { to if (is_countable($leases) && count($leases) > 0) {

And line 982 from: if (count($pools) > 0) { to if (is_countable($pools) && count($pools) > 0) {

Use at your own risk!

rbicelli commented 1 year ago

A better workaroud is to disable items related to DHCP Pool Failover instead of editing the script.

stephanehofman commented 1 year ago

DISCLAIMER: I HAVE NO CLUE WHAT I AM DOING!

I'm not entirely sure whether this creates the desired behaviour or not, but is has suppressed the errors for me

It does seem that the is_countable may have the same effect as count > 0 and putting both like I have is pointless.

It may be that the variables are the incorrect data type as required by the php upgrade, so my modifications are preventing the duplicate removal functions from happening.

It may be that the variable does not exist yet, intentionally or not, and count is being used to check it's existence. If that is the case then I believe this should be a viable solution.

With that said, I managed to suppress the error by changing line 978 from: if (count($leases) > 0) { to if (is_countable($leases) && count($leases) > 0) {

And line 982 from: if (count($pools) > 0) { to if (is_countable($pools) && count($pools) > 0) {

Use at your own risk!

after the modification, another error : PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1131, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1131 Stack trace:

0 /root/scripts/pfsense_zbx.php(1131): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validFrom.max')

2 {main}

thrown @ 2023-02-28 09:59:35 PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1139, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1139 Stack trace:

0 /root/scripts/pfsense_zbx.php(1139): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validTo.min')

2 {main}

thrown @ 2023-02-28 09:59:37

edeckers commented 1 year ago

What happens when you put the two occurrences of crt in double quotes "crt"? I did that on my local instance last week and that seems to have solved the situation, because the crt constant doesn't exist and we actually need a "crt" to access the correct field from $cert.

This output for php 8.1.x and 7.4.x with regards to undefined constants demonstrates why it used to work: https://onlinephp.io?s=s7EvyCjg5eLlSk3OyFdQCkktLlGyhvOTi0qsAQ%2C%2C&v=8.1.0%2C7.4.0

stephanehofman commented 1 year ago

it change nothing...

PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1131, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1131 Stack trace:

0 /root/scripts/pfsense_zbx.php(1131): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validFrom.max')

2 {main}

thrown @ 2023-03-02 11:00:01 PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1139, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1139 Stack trace:

0 /root/scripts/pfsense_zbx.php(1139): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validTo.min')

2 {main}

thrown @ 2023-03-02 11:00:04 PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1131, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1131 Stack trace:

0 /root/scripts/pfsense_zbx.php(1131): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validFrom.max')

2 {main}

thrown @ 2023-03-02 11:01:02 PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1139, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1139 Stack trace:

0 /root/scripts/pfsense_zbx.php(1139): in_array('62399625c19f2', NULL)

1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validTo.min')

2 {main}

thrown @ 2023-03-02 11:01:04

edeckers commented 1 year ago

I've submitted a PR https://github.com/rbicelli/pfsense-zabbix-template/pull/134 that fixes the issue.

I forgot about the change of this line: https://github.com/rbicelli/pfsense-zabbix-template/compare/master...edeckers:pfsense-zabbix-template:elydeckers/fix/broken-pfsense-23-php-8-1#diff-9874529ae15a98afff9726709aa3f7ef31b25cdd0d903ed892ebe626e64a3c57R1119. That's why it didn't work for you @stephanehofman .

stephanehofman commented 1 year ago

Hello, I have updated the script to last version, but I still have an error PHP errors

PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1131, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1131
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1131): in_array('62399625c19f2', NULL)
#1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validFrom.max')
#2 {main}
thrown @ 2023-03-07 09:45:37
PHP ERROR: Type: 1, File: /root/scripts/pfsense_zbx.php, Line: 1139, Message: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, null given in /root/scripts/pfsense_zbx.php:1139
Stack trace:
#0 /root/scripts/pfsense_zbx.php(1139): in_array('62399625c19f2', NULL)
#1 /root/scripts/pfsense_zbx.php(1354): pfz_get_cert_date('validTo.min')
#2 {main}
thrown @ 2023-03-07 09:45:38