Ad Widget

Collapse

Getting 'undefined return value' when testing a shell script Item with variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gwynll
    Junior Member
    • Apr 2021
    • 19

    #1

    Getting 'undefined return value' when testing a shell script Item with variables

    I'm posting a new question because I've learnt a lot from another question so I believe I've now refined what the problem is...

    I want to run a command from the Zabbix server that will query several hosts on a variety of ports.

    So I've created a file called /usr/share/zabbix/externalscripts/flexlm.sh with the following command:

    lmutil lmstat -A -c $1@$2 | grep -c "license server UP"

    I made the file executable using chmod 755.

    I created a new group in Zabbix called 'FlexLM servers'.

    I created a new template called 'FlexLM licence status', assigned to the above group. In Macros section of the template, I've created two macros, {$FLEXLM_SERVER} and {$FLEXLM_PORT} - I left the 'value' fields blank because I didn't know what to put there. Then within the template I created a new Item, with Type = Script, and the following item key:

    flexlm.sh["{$FLEXLM_PORT}","{$FLEXLM_SERVER}"]

    I then click Test, and in the 'Test item' box that popped up I set a value for both Macros (one specific server and one specific port), but when I click 'Get value' I get 'Cannot execute script: undefined return value'.

    Now, I understand that this is due to the fact that the script is using $1 and $2 as the variables, but Zabbix is sending it $FLEXLM_PORT and $FLEXLM_SERVER.

    Therefore could anyone explain what syntax I need to add above the command in the above script to define the variables and 'map' the Zabbix ones to $1 and $2?

    Many thanks.
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #2
    Hi, https://www.zabbix.com/documentation...types/external is the documentation about this. Anyway, you have a shell script that is given two arguments. Those arguments are $1 and $2. So that part is fine. How is your item configured?

    Markku

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #3
      When testing item, in the case of using an external script, the values of macros may not be passed. Instead, the script gets the names of the macros. Check it out.
      This happens precisely when using the built-in testing mechanism.

      Comment

      • gwynll
        Junior Member
        • Apr 2021
        • 19

        #4
        Ah OK, it's good to know that about the variables - I think I may have created a red herring by trying to echo the variables in the script. So removing that, and going back to a single-line script, I'm now getting...

        Value of type "string" is not suitable for value type "Numeric (unsigned)". Value ""

        The result I'm expecting is either a 0 or a 1.

        I've had a look through various documentation but haven't found the answer.

        I've attached screenshots of my item and the testing screen

        Thanks
        Attached Files

        Comment

        • gwynll
          Junior Member
          • Apr 2021
          • 19

          #5
          Hello, I've changed now to 'External check' but unfortunately I'm still getting the following when I hit Test:

          Value of type "string" is not suitable for value type "Numeric (unsigned)". Value ""

          Comment

          • Markku
            Senior Member
            Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
            • Sep 2018
            • 1781

            #6
            Is there a specific reason why you are using an empty string value in testing where in real case you expect an integer? Or do I miss something here.

            Markku

            Comment

            • gwynll
              Junior Member
              • Apr 2021
              • 19

              #7
              OK I think I have progress. But I'm not sure what I did apart from rebooting the Zabbix server.

              I'm no longer getting the above error. Now, when I do 'Get value and test', it just gives a '0' regardless of what values I give to my macros in the test. Please see new screenshot attached.

              When I run the following command on the Zabbix server's SSH console...

              /usr/share/zabbix/externalscripts/lmutil lmstat -A -c "27009@llnlic04" | grep -c "license server UP"

              Then I get a '1', which is what I expect. And then when I change the above port to 27012, I get a '0', which is also what I expect. But for some reason in the Zabbix application when testing I get '0' for everything.

              Any ideas?
              Attached Files

              Comment

              • Hamardaban
                Senior Member
                Zabbix Certified SpecialistZabbix Certified Professional
                • May 2019
                • 2713

                #8
                To check, run this command on behalf of the user under which zabbix is running.

                Comment

                • gwynll
                  Junior Member
                  • Apr 2021
                  • 19

                  #9
                  Thanks everyone for your input here. Turned out to be a very strange problem. Inside the script I re-wrote the command manually underneath the one that was there, and then commented out the original. And then it started working.

                  I had closely compared both lines and they were visibly identical. So the only thing I can think of is that when I copied/pasted the commend into my SSH console, some of the characters were a different format, or some kind of encoding issue during the copy/paste.

                  A good few hours that I spent on that problem!!

                  But it wasn't a waste anyway, as I've gained valuable info on Zabbix, and Linux in general.

                  Thanks again.

                  Comment

                  • cyber
                    Senior Member
                    Zabbix Certified SpecialistZabbix Certified Professional
                    • Dec 2006
                    • 4806

                    #10
                    I think script type item is meant to contain a javascript under "Script" field. Not pointing to a external script on "key" field. For such external scripts you should use "external check" type.

                    Comment

                    Working...