grumpy-systems / opnsense-zabbix

3 stars 0 forks source link

Issue running scripts #1

Open jeffclay opened 1 month ago

jeffclay commented 1 month ago

I get the error below in the zabbix server logs.

1533:20240918:051253.865 discovery rule "my.host.name:opn.gws" became not supported: Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: 'Traceback (most recent call last): File "/usr/home/gws.py", line 8, in data = json.loads(out) ^^^^^^^^^^^^^^^ File "/usr/lo 1532:20240918:051254.844 discovery rule "my.host.name:opn.interfaces" became not supported: Invalid discovery rule value: cannot parse as a valid JSON object: invalid object format, expected opening character '{' or '[' at: 'Traceback (most recent call last): File "/usr/home/interface.py", line 10, in root = ET.parse('/conf/config.xml').getroot() ^

I've double checked everything I can think of but I'm rather new to Zabbix.

I have confirmed that the script files are owned by the user running zabbix in OPNSense. I have also double checked the user parameters are set. If I run python3 /usr/home/gws.py on the firewall, I get a valid JSON print with both of my gateway names.

livdebus commented 4 days ago

Hi, I have the same issue. Have you found a solution?

jeffclay commented 4 days ago

No, I have not found a solution.

livdebus commented 4 days ago

@grumpy-systems Any idea? We just followed your blog post. Python scripts run as root and as normal user but not as zabbix user (not from shell or from zabbix itself)

sudo -u zabbix python3 /usr/home/gws.py

Traceback (most recent call last):
  File "/usr/home/gws.py", line 7, in <module>
    data = json.loads(out)
           ^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1)
grumpy-systems commented 3 days ago

Sorry, didn't see this issue originally.

I ran into the same issue and forgot to update the post, I'm pretty sure the magic sauce is to do sudo python3 ... for the command. I think you also need to check the "Enable sudo root permissions" on the main Zabbix service screen as well (where the hostname and whatnot is set)

If that works, I'll update the post to fix it as well. That broke in an update after I wrote the post.