Ad Widget

Collapse

Problem with API (py-zabbix)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • greg13
    Junior Member
    • Jan 2017
    • 3

    #1

    Problem with API (py-zabbix)

    Hi All,

    Since the migration of my zabbix server (3.0 to 3.2), we have problem with the API.
    We are using py-zabbix but now we have the following error.

    {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}
    The problem seems not coming from the module because I tried with curl and I have the same issue

    # curl -k -H "Content-Type: application/json" --data @version https://myzabbix/api_jsonrpc.php

    {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}

    # cat version
    {

    "jsonrpc": "2.0",
    "method": "apiinfo.version",
    "params": [],
    "id": 1

    }
    # curl -k -H "Content-Type: application/json" --data @data https://myzabbix/api_jsonrpc.php

    {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}

    # cat data
    {

    "jsonrpc": "2.0",
    "method": "user.login",
    "params": {

    "user": "MyzabbixAPI",
    "password": "MyPass"

    },
    "id": 1

    }
    # cat version | json_verify
    JSON is valid
    Thank you in advance for your help.
  • jan.garaj
    Senior Member
    Zabbix Certified Specialist
    • Jan 2010
    • 506

    #2
    Test command is correct:
    Code:
     curl -k -H "Content-Type: application/json" --data @version http://zabbix.org/zabbix/api_jsonrpc.php
    {"jsonrpc":"2.0","result":"3.3.0","id":1}
    Problem can be your network (for example big brother proxy in your network), test it directly on zabbix server
    or
    your zabbix server (for example malconfigured web server/server modules/PHP limits, https, ...) - try to test it with minimal vanilla web server configuration, ....
    Devops Monitoring Expert advice: Dockerize/automate/monitor all the things.
    My DevOps stack: Docker / Kubernetes / Mesos / ECS / Terraform / Elasticsearch / Zabbix / Grafana / Puppet / Ansible / Vagrant

    Comment

    • greg13
      Junior Member
      • Jan 2017
      • 3

      #3
      Thank you for your quick answer.
      I will investigate the network part and test on the server.

      Comment

      • greg13
        Junior Member
        • Jan 2017
        • 3

        #4
        Hello,

        On the zabbix server I have the same issue :

        It is fine on the zabbix.org server

        Code:
        $ curl -k -H "Content-Type: application/json" --data @version [url]https://zabbix.org/zabbix/api_jsonrpc.php[/url]
        {"jsonrpc":"2.0","result":"3.3.0","id":1}$
        Local :
        Code:
        $ curl -k -H "Content-Type: application/json" --data @version [url]https://127.0.0.1/api_jsonrpc.php[/url]
        {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}$
        Thanks in advance

        Comment

        • troseph
          Junior Member
          • Mar 2013
          • 10

          #5
          I'm having the same issue with Zabbix 3.2.2 and Zabbix Gnomes python API, have you found a solution?

          Comment

          • troseph
            Junior Member
            • Mar 2013
            • 10

            #6
            Fixed

            I fix this in our environment by moving an older version of pyzabbix over from a working box.

            For whatever reason the version of pyzabbix that pip installed has a bunch of cruft in it. I've attached our working version of pyzabbix, see if it works for you. If you're on python 2.7.

            Unpack to:
            /usr/lib/python2.7/site-packages/pyzabbix

            Hope this helps.
            Attached Files

            Comment


            • roberdaniel
              roberdaniel commented
              Editing a comment
              Hi Troseph, we are having the same problem with zabbix 4.2
              You said that you solved the problem reinstalling py-zabbix, but you had the problem also with cURL (wich nothing have to do with py-zabbix) so please explain what do you do in server side.
              Regards
          • roberdaniel
            Junior Member
            • Apr 2019
            • 22

            #7
            Resolved using Invoke-RestMethod instead of Invoke-WebRequest. (powershell), so i'm suspecting that the api has changed to "restful"
            I'm using Zabbix 4.2
            Can anyone confirm if api has changed?

            Comment

            • perkik1
              Junior Member
              • Dec 2021
              • 7

              #8
              I don't see a solution. I'm experiencing this from a curl command. Running python 3.6.8. Zabbix LTS 6.0. This below works from the Zabbix API Testing Tool - Zabbix Tutorials (sbcode.net)​ when executed from there. When executed from command line curl on Linux it errors out as seen below.
              + curl -k --header Content-Type:application/json --request POST --data '{"jsonrpc":"2.0", "method": "hostgroup.create", \
              "params": {"name": "Syslog servers"}, "id": 2, "auth": "bba9fc082ffad2e108f5ba3469d32bad"}' https://srlis0004.corp.dvn.com/api_jsonrpc.php -lrpc=trace
              Warning: Invalid character is found in given range. A specified range MUST
              Warning: have only digits in 'start'-'stop'. The server's response to this
              Warning: request is uncertain.
              {"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error","data":"Invalid JSON. An error occurred on the server while parsing the JSON text."},"id":null}+ echo -e 'Creation of host group Syslog servers complete\n'

              Comment

              • perkik1
                Junior Member
                • Dec 2021
                • 7

                #9
                I found what I think is the main issue. Its more to do with Bash, parenthesis, backticks and how it formulates the command to send. In a nutshell, I ended up putting the whole command with backticks. Here is an example,
                WKRETCODE=`curl -k --header "Content-Type: application/json" \
                --request POST \
                --data '{"jsonrpc": "2.0", "method": "hostgroup.create", "params": {"name": "'"${HGNAME}"'"}, "id": 2, "auth": "'$WKAUTH4'"}' \
                "https://servername.com/api_jsonrpc.php" `
                ​... in this case creating a host group. Where HGNAME is the new host group name, and WKAUTH4 is the authority token acquired from the user.login API. the main point is that the command is enveloped by the backticks. Also, spaces & exact syntax are critical too.

                Comment

                Working...