Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility issues with Zabbix 7.x #1914

Closed
viper2pt0 opened this issue Nov 17, 2024 · 42 comments · Fixed by #1931
Closed

Compatibility issues with Zabbix 7.x #1914

viper2pt0 opened this issue Nov 17, 2024 · 42 comments · Fixed by #1931
Assignees
Labels

Comments

@viper2pt0
Copy link

Describe the bug
After updating plugin and moving zabbix to new server, now getting this message when trying to reauthenticate and connect the plugin.

Expected behavior
Authentication to succeed and healthy response from zabbix api.

Software versions

Grafana Zabbix Grafana-Zabbix Plugin
11.3.0 7.2.0rc1 4.5.7
@jakub-nowak-pl
Copy link

I second this.

Getting the same error in grafana dockerized.

@isaqueprofeta
Copy link

You're using an unsupported version, 7.2 isn't production ready and not supported. Currently support goes till 7.0.x

@sglamm
Copy link

sglamm commented Nov 29, 2024

For me, every version on 7.2 has worked until 7.2 rc1. Wonder what changed to cause this issue? Going to the API page gives http error 412 now. Does the API page work for anyone on RC1?

@isaqueprofeta
Copy link

For me, every version on 7.2 has worked until 7.2 rc1. Wonder what changed to cause this issue? Going to the API page gives http error 412 now. Does the API page work for anyone on RC1?

You should check it out on Zabbix side. As I said, 7.2 isn't production ready, and is not currently supported by the Plug-in.

@lphbraz
Copy link

lphbraz commented Dec 6, 2024

I'm also getting this same error. Is there no solution? I downloaded the latest versions of zabbix and grafana and they just don't work together? I installed zabbix 7.2 on all my hosts and now I have to go back to 7.0 and start all over again? Did you find a solution? @viper2pt0 @jakub-nowak-pl @isaqueprofeta @sglamm

@isaqueprofeta
Copy link

@lphbraz you shouldn't use zabbix 7.2 yet, it isn't released. Check on https://www.zabbix.com/road map : "Zabbix 7.2 Planned release date: Q4 2024"

@sglamm
Copy link

sglamm commented Dec 6, 2024 via email

@lamenawuer
Copy link

lamenawuer commented Dec 10, 2024

I have the exact same issue and I'm using a supported zabbix version, 7.0.6

[Tue Dec 10 09:37:59.459857 2024] [proxy_fcgi:error] [pid 1251512:tid 140701517969152] [client x.x.x.x.:51310] AH01071: Got error 'PHP message: PHP Deprecated: Parameter "/auth" is deprecated. in /usr/share/zabbix/include/classes/validators/CApiInputValidator.php on line 1516

@alxcreate
Copy link

alxcreate commented Dec 10, 2024

Starting from version 6.4, it was announced that the auth property would be deprecated and removed in future releases. That moment has arrived, and no one was prepared for it.

@sglamm
Copy link

sglamm commented Dec 10, 2024

Odd part about 7.2 is even the API page does not work. Gives 412 error. Not a Grafana issue, but part of the puzzle. I am waiting for some kind of update from Zabbix for a resolution.

@isaqueprofeta
Copy link

@alxcreate thx for the pointer.

Being technical here now, 7.2.0 is out and looking at the API Docs now zabbix does not use the "auth" field for the AuthToken. Now the session/auth token, being an API Key or an authorize sesssion token should be at the header 'Authorization: Bearer {TOKEN}'.

@yesoreyeram @zoltanbedi @ivanahuckova can you take a look? This is a a pretty critical one.

@infiniteACodevops
Copy link

boa... alex

A partir da versão 6.4, foi anunciado que a propriedade de auth seria obsoleta e removida em versões futuras. Esse momento chegou, e ninguém estava preparado para isso.

@yesoreyeram
Copy link
Collaborator

@isaqueprofeta - we are looking at it.

@alxcreate
Copy link

alxcreate commented Dec 11, 2024

Odd part about 7.2 is even the API page does not work. Gives 412 error. Not a Grafana issue, but part of the puzzle. I am waiting for some kind of update from Zabbix for a resolution.

Zabbix API works well:

root@127:/home# curl -k --request POST \
    --url 'https://zabbix-server/zabbix/api_jsonrpc.php' \
    --header 'Content-Type: application/json-rpc' \
    --data '{"jsonrpc":"2.0","method":"user.login","params":{"username":"grafana","password":"password"},"id":1}'
{"jsonrpc":"2.0","result":"db3dfa980315dacb0edf3a5411edfb08","id":1}
root@127:/home# 
root@127:/home# cat data.json 
{
    "jsonrpc": "2.0",
    "method": "host.get",
    "params": {
        "output": [
            "hostid",
            "host"
        ],
        "selectInterfaces": [
            "interfaceid",
            "ip"
        ]
    },
    "id": 2
}
root@127:/home# curl -k --request POST \
    --url 'https://zabbix-server/zabbix/api_jsonrpc.php' \
    --header 'Authorization: Bearer db3dfa980315dacb0edf3a5411edfb08' \
    --header 'Content-Type: application/json-rpc' \
    --data @data.json
{"jsonrpc":"2.0","result":[{"hostid":"10084","host":"Zabbix server","interfaces":[{"interfaceid":"1","ip":"127.0.0.1"}]}...

@alxcreate
Copy link

Trying set token in http header, but get an error:
Invalid params. The "apiinfo.version" method must be called without authorization header.

Image

@albertofreire
Copy link

Trying set token in http header, but get an error: Invalid params. The "apiinfo.version" method must be called without authorization header.

Image

I created an intermediary proxy using Flask, a framework I am more familiar with. This solution resolved the issues

While connecting Grafana to Zabbix, I faced the following issues:

Grafana was sending obsolete parameters (auth and real_hosts) that the Zabbix API could not process correctly.
Authentication headers were missing for some API methods, resulting in failed requests.
Grafana's behavior in certain HTTPS configurations caused communication errors with the Zabbix API.

Solution: Flask-Based Proxy
The proxy intercepts requests from Grafana, sanitizes the payload, and adds the required headers for authentication. It then forwards the sanitized request to the Zabbix API and returns the response.

Below is the Python implementation:

#!/usr/bin/env python3
from flask import Flask, request, jsonify
import requests
import json

app = Flask(__name__)

# Internal Zabbix URL (use localhost if on the same machine)
ZABBIX_URL = "http://127.0.0.1/zabbix/api_jsonrpc.php"

# Replace with your real token
AUTH_TOKEN = "7d88a9978a7sdauydguags76dgadvajhbdae0117daceiauhy823ihiuicd1f2"

@app.route('/zabbix/api_jsonrpc.php', methods=['POST'])
def proxy():
    # Read raw request body
    raw_data = request.data
    try:
        data = json.loads(raw_data.decode('utf-8'))
    except Exception as e:
        # Return a 400 error for invalid JSON
        print("Error parsing JSON:", e)
        return "Invalid JSON format", 400

    # Remove obsolete parameters
    if 'auth' in data:
        del data['auth']
    if 'params' in data and 'real_hosts' in data['params']:
        del data['params']['real_hosts']

    headers = {
        'Content-Type': 'application/json-rpc'
    }

    method = data.get('method')
    # Add Bearer token for non-'apiinfo.version' requests
    if method != 'apiinfo.version':
        headers['Authorization'] = f'Bearer {AUTH_TOKEN}'

    try:
        # Use `verify=False` if HTTPS issues occur
        # response = requests.post(ZABBIX_URL, json=data, headers=headers, verify=False)
        response = requests.post(ZABBIX_URL, json=data, headers=headers)
    except Exception as e:
        print("Error connecting to Zabbix:", e)
        return "Internal error connecting to Zabbix", 502

    # Return Zabbix response with fixed headers
    return response.content, response.status_code, {'Content-Type': 'application/json-rpc'}

if __name__ == '__main__':
    # Run Flask server on port 8080
    app.run(host='127.0.0.1', port=8080)

How It Works
The proxy listens on http://127.0.0.1:8080/zabbix/api_jsonrpc.php.
Requests from Grafana are intercepted and processed:
Invalid JSON payloads are rejected with a 400 Bad Request response.
Obsolete parameters (auth and real_hosts) are removed.
A Bearer token is added to the headers, except for the apiinfo.version method.
The proxy forwards the sanitized request to the Zabbix API and returns its response to Grafana.

Outcome
This proxy solution resolved all the integration issues. The Flask application has been running smoothly, ensuring seamless communication between Grafana and Zabbix.

I hope this implementation provides valuable insights. If there’s anything further I can clarify or contribute, please let me know!

Image

Image

@greenaar
Copy link

I created an intermediary proxy using Flask, a framework I am more familiar with. This solution resolved the issues

Nice workaround! I wrapped this in a dockerfile, which i've added below.

FROM python:3.10-alpine

WORKDIR /opt
COPY proxy.py /opt
COPY requirements.txt /opt

RUN pip install flask requests
EXPOSE 8080

CMD ["/opt/proxy.py"]

It'll do what I need in the short term.

@viper2pt0
Copy link
Author

viper2pt0 commented Dec 11, 2024

I've deployed the proxy in docker as well and it seems to be working. I did notice that there appears to be other API changes though. For example when interacting with an item in the problem panel: Image

Just more of a heads up for the folks working on the official fix.

@albertofreire
Copy link

I've deployed the proxy in docker as well and it seems to be working. I did notice that there appears to be other API changes though. For example when interacting with an item in the problem panel: Image

Just more of a heads up for the folks working on the official fix.

It seems that Zabbix 7.2 has received other changes besides authentication.

It would be possible to add conditionals to intercept and modify the invalid parameters, but that would be too costly, and I think it’s better to wait for the Grafana team to proceed with their official adjustments.

In the meantime, this adaptation (at least for me) is working well.

Cheers!

@yesoreyeram
Copy link
Collaborator

Hiya. We are working on a fix and expecting to be available this week.

@Miata-RX7
Copy link

if method != 'apiinfo.version':

datasource save&test will report:[Invalid params. The "user.login" method must be called without authorization header.]

change it to:
if method not in ['apiinfo.version', 'user.login']:

@ivanahuckova
Copy link
Member

I have a PR with the fix ready #1931. If anyone here has time and is up for it, would you verify that it fixes the issue for you. Thank you 🙏 .

@jakub-nowak-pl
Copy link

I have a PR with the fix ready #1931. If anyone here has time and is up for it, would you verify that it fixes the issue for you. Thank you 🙏 .

I've got all dockerized but If this fix will got into grafana dockerized I can check.

@rusitschka
Copy link

I have a PR with the fix ready #1931. If anyone here has time and is up for it, would you verify that it fixes the issue for you. Thank you 🙏 .

I've got all dockerized but If this fix will got into grafana dockerized I can check.

Same here. I tried to mount the branch into /var/lib/grafana/plugins but that did not work. Do you have a how-to for testing this?

@yesoreyeram
Copy link
Collaborator

We have the build available to test through docker.

docker run -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://storage.googleapis.com/integration-artifacts/alexanderzobnin-zabbix-app/4.5.7/main/163fabf651b776bf70adc08fa41bec4f52645374/alexanderzobnin-zabbix-app-4.5.7%2B163fabf6.linux_amd64.zip;alexanderzobnin-zabbix-app" grafana/grafana-enterprise:latest

Once you start the above docker instance, you need to enable the plugin in http://localhost:3000/plugins/alexanderzobnin-zabbix-app and then can test.

Can someone help to test the above build works both in 6.x and 7.x version of zabbix?

@rusitschka
Copy link

Works fine with Zabbix 7.2.0 - thanks!

@yesoreyeram yesoreyeram changed the title Invalid request. Invalid parameter "/": unexpected parameter "auth". Compatibility issues with Zabbix 7.x Dec 13, 2024
@alxcreate
Copy link

When this will be available for typical installation? I mean command grafana-cli plugins install alexanderzobnin-zabbix-app

@Machos65
Copy link

i was using grafana OSS not in docker instance is how can i go around that problem cause am still facing it when i upgrade zabbix to 7.2

@alxcreate
Copy link

i was using grafana OSS not in docker instance is how can i go around that problem cause am still facing it when i upgrade zabbix to 7.2

You can manually download plugin and unzip it in plugins folder of Grafana.

But it's not a production choice. In your position, I would continue using the old versions and wait for a published fix.

@eglyn
Copy link

eglyn commented Dec 16, 2024

Same issue here :(

I don't understand why you say Zabbix 7.2 is not a production version, it's the version on their main website, and it seems a prod version.

@Mordong
Copy link

Mordong commented Dec 16, 2024

7.2 is in production and actually it's quite strange to not to work on Zabbix changes sice ver. 7 was out in beta

@yesoreyeram
Copy link
Collaborator

Planning to release by EOD tomorrow.

@isaqueprofeta
Copy link

We have the build available to test through docker.

docker run -p 3000:3000 -e "GF_INSTALL_PLUGINS=https://storage.googleapis.com/integration-artifacts/alexanderzobnin-zabbix-app/4.5.7/main/163fabf651b776bf70adc08fa41bec4f52645374/alexanderzobnin-zabbix-app-4.5.7%2B163fabf6.linux_amd64.zip;alexanderzobnin-zabbix-app" grafana/grafana-enterprise:latest

Once you start the above docker instance, you need to enable the plugin in http://localhost:3000/plugins/alexanderzobnin-zabbix-app and then can test.

Can someone help to test the above build works both in 6.x and 7.x version of zabbix?

Gimme a sec, I'll try it with my zabbix-lab project.

@isaqueprofeta
Copy link

isaqueprofeta commented Dec 16, 2024

Planning to release by EOD tomorrow.

Tested with the following versions on docker (used the https://github.com/isaqueprofeta/zabbix-lab project)

Zabbix 5.4

Image

Zabbix 6.0

Image

Zabbix 6.4

Image

Zabbix 7.0

Image

Zabbix 7.2

Image

@yesoreyeram
Copy link
Collaborator

Thank you @isaqueprofeta

@ryanreche
Copy link

When this will be available for typical installation? I mean command grafana-cli plugins install alexanderzobnin-zabbix-app

I updated the environment and I have the same problem, grafana gives the same error as auth, can anyone help me?

@isaqueprofeta
Copy link

When this will be available for typical installation? I mean command grafana-cli plugins install alexanderzobnin-zabbix-app

I updated the environment and I have the same problem, grafana gives the same error as auth, can anyone help me?

The new version with the correction is planned to be release tomorrow at the end of the day.

@ryanreche
Copy link

d to be release tomorrow at the end of the da

tks

@github-project-automation github-project-automation bot moved this from In Progress to Complete in OSS Big Tent Dec 17, 2024
@Mordong
Copy link

Mordong commented Dec 17, 2024

working after full plugin wipe and re-install

@alxcreate
Copy link

New plugin works fine. Thanks.

Grafana Zabbix Grafana-Zabbix Plugin
11.4.0 7.2.0 4.6.0

@jakub-nowak-pl
Copy link

Works like a charm :)
Thanks for fixing it.

@gfvendra
Copy link

Plugin updating and working.

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Complete
Development

Successfully merging a pull request may close this issue.