Ad Widget

Collapse

External Script No Value returned

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • okoester
    Junior Member
    • Aug 2014
    • 11

    #1

    External Script No Value returned

    Hello,

    I'm trying to run an external script from Zabbix Server (3.2) to run SSL checks.

    I set up the script zext_ssl_cert.sh (coming from Zabbix forum). When trying to run it manually, it does what it should do ;-)

    But when trying to run from within Zabbix Server it does not work. I can't get any values...

    I then checked if the script is in the right place (/usr/local/etc/zabbix32/zabbix/externalscript under FreeBSD 11).

    Still not working.
    Then I decided to create a simple script check.sh in the same location:
    #! /usr/local/bin/bash
    echo "Programm $0 gestartet am `date`" >> /tmp/test.log

    echo 12345
    (BASH path differs from linux)
    The program does what it should, when checked manually:
    It writes a log file with its date of last run and returns value 12345 to console.

    But when I start it from within zabbix, it still writes the log file, but there seems no value to be returned...
    So the script MUST be in the right location. I also checked that it is running with zabbix user permissions...

    What's wrong here?

    Any help is appreciated!

    Regards
    Olaf
  • okoester
    Junior Member
    • Aug 2014
    • 11

    #2
    some more information

    I'm still messing around with this issue. And by now I'm pretty sure that there must be a bug that makes Zabbix unable to catch the return value.

    What I've done so far since the last thread:
    * To see if there's maybe a permission problem I've moved the "externalscripts" directive in zabbix_server.conf to /tmp
    * The test script's permissions are
    -rwxr-xr-x 1 zabbix wheel 18 May 23 20:35 http.check.sh
    As you ca see, i wrote a new, very simple script that always responds with value "1":
    #!/bin/sh
    echo 1
    I've set Log Level to 5 to get as much information from zabbix log file. Below is the output grepped from log file...
    65366:20170523:205116.133 End of activate_host()
    65366:20170523:205116.133 End of get_values():1
    65366:20170523:205116.133 In get_values()
    65366:20170523:205116.133 In DCconfig_get_poller_items() poller_type:0
    65366:20170523:205116.133 End of DCconfig_get_poller_items():1
    65366:20170523:205116.133 In substitute_key_macros() data:'http.check.sh[]'
    65366:20170523:205116.133 End of substitute_key_macros():SUCCEED data:'http.check.sh[]'
    65366:20170523:205116.133 In get_value() key:'http.check.sh[]'
    65366:20170523:205116.134 In get_value_external() key:'http.check.sh[]'
    65366:20170523:205116.134 In zbx_popen() command:'/tmp/http.check.sh ""'
    65366:20170523:205116.136 End of zbx_popen():7
    But still, no data is returned as a Zabbix value.
    Only "positive" result I had during my tests was when I tried to start curl from within another test script. curl wasn't found from within the script and Zabbix showed that error inside "latest data", marked with a red "i"...
    uname -a:
    FreeBSD freebsd02.xxxx.xxx 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 01:43:23 UTC 2016 [email protected]:/usr/obj/usr/src/sys/GENERIC amd64
    Anyone any ideas? Might this be a bug to file for Zabbix developers?

    Any help appreciated...

    Regards
    Olaf

    Comment

    • nobodysu
      Member
      • Sep 2016
      • 84

      #3
      zabbix user under FreeBSD does not have necessary PATH configured. Provide it in your script:
      Code:
      #! /usr/local/bin/bash
      export PATH=/usr/local/sbin:/usr/local/bin
      echo "Programm $0 gestartet am `date`" >> /tmp/test.log
      
      echo 12345

      Comment

      • okoester
        Junior Member
        • Aug 2014
        • 11

        #4
        No changes

        Hello,

        I added the PATH but nothing changed :-(

        Is there maybe some option I have to set to make it work?

        As mentioned before, the script itself seems to be executed because it writes a log file.
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:17:17 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:17:27 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:17:37 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:17:48 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:17:57 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:18:08 CEST 2017
        Programm /usr/local/etc/zabbix32/zabbix/externalscripts/check.sh gestartet am Thu May 25 15:18:17 CEST 2017
        But still no data received. Ald also the "last check" stays empty as you can see in attachment.

        The Zabbix Server is installed from pkg
        Attached Files

        Comment

        • nobodysu
          Member
          • Sep 2016
          • 84

          #5
          Not all binaries in PATH maybe? test.log contents?

          Comment

          • okoester
            Junior Member
            • Aug 2014
            • 11

            #6
            Test.log

            Test.log contents can be found above starting with:
            "Programm "
            (see quoted)

            I added /bin and /sbin to your PATH suggestion to make date work ;-)

            Still: when running from cmd it works fine. But not from Zabbix. Still no values returned.

            When I'd set logging in server conf to debug level (4 or 5), what should I expect to see? How should a value coming from an external script should look like?
            (In my second post in this thread I already set Log Level to 5, but cant surely identify what line should be a result...)

            Regards

            Comment

            • ovas
              Senior Member
              Zabbix Certified Trainer
              Zabbix Certified SpecialistZabbix Certified Professional
              • Apr 2017
              • 138

              #7
              Hello!

              In Zabbix agent configurations, are the options EnableRemoteCommands and LogRemoteCommands turned on? If yes, what does executing script write to zabbix_agentd.log file? Are you able to execute the script as zabbix user?

              Comment

              • nobodysu
                Member
                • Sep 2016
                • 84

                #8
                What about your item configuration (especially 'Type of information')? Please make a screen of that.
                Also, in your host you should see an error beside your external check item (Configuration - Hosts - host - items).

                Comment

                • okoester
                  Junior Member
                  • Aug 2014
                  • 11

                  #9
                  Why EnableRemoteCommands?

                  Hello Ovas,

                  EnableRemoteCommands and LogRemoteCommands were not enabled (just did that now). But I do no see how that could help here?

                  I was trying to run an external script located in the "ExternalScripts" folder on Zabbix server. The script should only return a value like 0 or 1 .
                  Started first with a script that should give me the number of days SSL certificate is still valid. Uses openssl s_client command to grab certificate values and returns number of days. Does not use any Zabbix Agent connectivity. Since that does not return anything, I started debugging that issue with a very small script. Pls see bash script above.

                  Both scripts, the SSL and the bash script seem not to return any results to Zabbix server but return results when running them from command line

                  And Yes, I was able to execute as Zabbix User with sudo -u zabbix scriptname.sh
                  And I also see that script is running because of entries in my log file test.log

                  Originally posted by ovas
                  Hello!

                  In Zabbix agent configurations, are the options EnableRemoteCommands and LogRemoteCommands turned on? If yes, what does executing script write to zabbix_agentd.log file? Are you able to execute the script as zabbix user?
                  Last edited by okoester; 27-05-2017, 11:31. Reason: Missed answer to second question

                  Comment

                  • okoester
                    Junior Member
                    • Aug 2014
                    • 11

                    #10
                    No error informations

                    Hello,

                    Please see attached screenshots from host configuration and item list as mentioned.
                    What I really do not understand:
                    I really looks like Zabbix does not get any results back from the script nor does it show any date in 'last checked' (latest data). It really seems to ignore my settings. But the check.sh script is being executed as my log file shows...
                    And I do not find any errors as mentioned. Neither in Zabbix Server Log nor in the Zabbix frontend. I'd expect at least an error regarding wrong type of data returned in the value or something.

                    Originally posted by nobodysu
                    What about your item configuration (especially 'Type of information')? Please make a screen of that.
                    Also, in your host you should see an error beside your external check item (Configuration - Hosts - host - items).
                    Attached Files

                    Comment

                    • okoester
                      Junior Member
                      • Aug 2014
                      • 11

                      #11
                      Works...

                      Hello Guys,

                      please dont call me a moron, but as for now it seems to work...

                      I really cant say what caused the problem here. I followed Ovas' hint to activate RemoteCommands. And even that they are running on the same host the Zabbix server is on, and as (from my point of view) the Zabbix Agent is not involved at all, Zabbix Server started to receive values from my script.

                      Ok, I added also a line "echo $?" to see the exit code. That led to another error (wrong type of result), but at least I had a response to work with

                      Now it seems to work but there is still some error (sometimes):

                      In some cases my final script zext_ssl_cert_check.sh throws an error inside sed command: "sed: stdout: broken pipe" That of course leads to an error regarding type of result...
                      But that is another history

                      So far, let me say thank you for your support guys!!

                      Regards
                      Olaf

                      Comment

                      Working...