Ad Widget

Collapse

Issues with Discovery Rule running a custom script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • snowtr
    Junior Member
    • Jun 2017
    • 7

    #1

    Issues with Discovery Rule running a custom script

    Hi!

    I'm new to Zabbix and this forum but I'm trying to help out, both myself and others. After having used a bunch of templates and miners to my own Zabbix 3.2 installation working as well as it does I decided it was time to pay back a little and create my own template and script for something that no one else has yet posted (that I could find).

    I used this package as an example:
    Contribute to omni-lchen/zabbix-ssl development by creating an account on GitHub.


    I am looking to create a discovery that launches a PHP script that queries an API from my VoIP provider (voip.ms) and gathers the status of all the VoIP accounts I monitor. The PHP script works fine and I noticed it was easier to launch a bash script that launches the PHP script then to try to make Zabbix run the PHP script directly and those parts of it seem to work well.

    Now I seem to be running into the same problem as this post, except my JSON output already looks correct according to that post:


    I am getting 'Value should be a JSON object.' back from my discovery. I tried looking through the database to see if I could find some logs about how Zabbix is trying to run the script so I could more accurately simulate the running myself and maybe correct how the script runs, but I couldn't find anything. I also couldn't find any log files that contained anything about the running of the discovery rules at all.

    I get that the JSON may be invalid so here is the CLI:
    Code:
    /usr/lib/zabbix/externalscripts$ ./voipAccountDiscover.sh <username> <password>
    { "data": [{"{#ACCOUNT}": "account name 1"},{"{#ACCOUNT}": "account name 2"},{"{#ACCOUNT}": "account name 3"},{"{#ACCOUNT}": "account name 4"},{"{#ACCOUNT}": "account name 5"},{"{#ACCOUNT}": "account name 6"},{"{#ACCOUNT}": "account name 7"}] }
    I'm not sure what else it wants exactly from the output but I'll share the code if needed as well.

    Please help.
  • Semiadmin
    Senior Member
    • Oct 2014
    • 1625

    #2
    Hi, snowtr.
    Perhaps your LLD got an error message instead of JSON, because of timeout, for example.
    For troubleshooting try to create a text item which'll receive data from your php script, and see what it'll get - a json, an error message or something else.

    Comment

    • snowtr
      Junior Member
      • Jun 2017
      • 7

      #3
      After some more googling, I found this article which talks about using zabbix_get to troubleshoot:
      Hallo, first thank you very much for the super template. I have followed the guide and all the files installed. But when i tried to test the command " zabbix_get -s 127.0.0.1 -k "custom.vfs.discove...


      I had to download the .deb file directly from repo.zabbix.com for zabbix_get and install it with dpkg but that helped a lot.

      I was able to add the UserParameter to the agent's config on my Zabbix server itself and use zabbix_get to test running the command and it kept producing errors. I'd say that it is a bug in Zabbix to run an external shell and get back errors, then state to the user that the output isn't in JSON when there are much more useful errors it could give back.

      In the end, my idea I got from another article to have Zabbix run the PHP file directly by adding '#!/usr/bin/php' to the top of the .php file and run it was not working. I wrote a bash script instead that takes my two variables and runs the .php file with 'php ' in front and the two variables after it and that worked with zabbix_get.

      Once the above showed me PHP errors, I knew I was in business and tries the Discovery Rule (LLD) again and it works now.

      Comment

      Working...