Ad Widget

Collapse

Pass an item value to an external script as a parameter

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • codemaker
    Junior Member
    • Aug 2019
    • 10

    #1

    Pass an item value to an external script as a parameter

    Hello,

    I'm a newbie in Zabbix but I'm enjoying learning it. Very capable monitoring solution.

    Here is my situation. I would like to pass a value, collected by a remote command executed on a host, to an external script. Is it possible?

    What I want to do is that I run a remote command to get the instance ID of an Amazon EC2 instance and then use it when I need to destroy it by executing and external script.
  • codemaker
    Junior Member
    • Aug 2019
    • 10

    #2
    Any ideas?

    Comment

    • brunohl
      Senior Member
      Zabbix Certified Specialist
      • Mar 2019
      • 215

      #3
      Yes, you could:
      - create an item that would do that check via UserParameter if needed
      - create a trigger that evaluates the response and trigger an action or external script using your parameter

      Comment

      • codemaker
        Junior Member
        • Aug 2019
        • 10

        #4
        Thanks for your answer.

        OK. How to pass that item value to the external script?

        Here is an example:

        I have an item that gets the instance ID by running
        Code:
        system.run[curl -s -f http://169.254.169.254/latest/meta-data/instance-id]
        on the host as follows:

        Name: instanceid
        Type: Zabbix agent (Active)
        Key: system.run[curl -s -f http://169.254.169.254/latest/meta-data/instance-id
        Type of information: character

        Now, I would like to pass the value of "instanceid" as a parameter to an external script executed by another item which I use to get the instance state as follows:

        Name: instance status
        Type: external check
        key: instance_status.sh (the instance id should be passed here)

        Can you please show me how to write the key of the previous item?

        Comment

        • brunohl
          Senior Member
          Zabbix Certified Specialist
          • Mar 2019
          • 215

          #5
          The key could be the same. What you should is figure a trigger to activate an action and then pass the value to that action.

          Comment

          • codemaker
            Junior Member
            • Aug 2019
            • 10

            #6
            I'm sorry but I do not understand.

            The key can't be the same. The key for the "instance status" is a bash script that needs a parameter which should get from the value of "intanceid" item.

            In the case I explained, no trigger is needed.

            Comment

            • brunohl
              Senior Member
              Zabbix Certified Specialist
              • Mar 2019
              • 215

              #7
              Yeah, what I said is that you could use that item which you posted to set a trigger because a trigger will set an action that will execute a script.

              OR

              You could set up a custom item that is a script called by UserParameter, which will get your instance id and then terminate it, returning the result of the operation.

              Comment

              • codemaker
                Junior Member
                • Aug 2019
                • 10

                #8
                I understand what you're saying but It seems that I'm not explaining myself well.

                Let me give you another example. Suppose that I have an item which is something like:

                ITEM 1
                Name: get_instance_id
                Type: Zabbix agent (Active)
                Key: system.run[curl -s -f http://169.254.169.254/latest/meta-data/instance-id
                Type of information: character

                now, I want to create another item which should check the status of that instance. In order to do that, I need the instance id to run a script called "get_instance_status.sh". Since I already have an item (ITEM 1) that gets the instance id, I just need to pass it to ITEM2 which is something like:
                ITEM 2
                Name: get_instance_status
                Type: External check
                Key: get_instance_status.sh["instanceid"]
                Type of information: character


                My question is that how to pass the value of ITEM1 to be used as a parameter for the script get_instance_status.sh which is in ITEM2?

                Comment

                • dirai19
                  Junior Member
                  • Jul 2019
                  • 8

                  #9
                  brunohl, maybe u can suggest something: i have python script, and i need to pass additional argument to it. this argument user should enter from UI (textbox, combobox etc.). im not sure if its possible

                  Comment


                  • brunohl
                    brunohl commented
                    Editing a comment
                    Where that UI element would be? Why does it have to be like that?

                  • dirai19
                    dirai19 commented
                    Editing a comment
                    zabbix frontend, casual textbox/combobox.
                    I did some research and now i think its not allowed

                  • brunohl
                    brunohl commented
                    Editing a comment
                    Maybe use the zabbix api
                • Markku
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                  • Sep 2018
                  • 1781

                  #10
                  Originally posted by codemaker

                  My question is that how to pass the value of ITEM1 to be used as a parameter for the script get_instance_status.sh which is in ITEM2?
                  How about creating a LLD rule based on the metadata? That LLD would then create the item1 (if needed) and item2 for you.

                  Otherwise I don’t immediately figure out how to use an item data to populate other item.

                  Markku

                  Comment

                  • brunohl
                    Senior Member
                    Zabbix Certified Specialist
                    • Mar 2019
                    • 215

                    #11
                    Ah, OK, now I got you. I would go with Markku suggestion and use LLD.

                    You should create an item that do a LLD and then create propotype of the items related to that value.

                    Comment

                    • codemaker
                      Junior Member
                      • Aug 2019
                      • 10

                      #12
                      Actually, I have been working on creating a LLD. I think so far it goes well with what I want to do. Thanks guys for all your help and suggestions.

                      It's very strange that it's not possible to use an item's value in another item's key. The possibilities would be great. Is it something that the Zabbix team is working on in the new versions?

                      Comment


                      • codemaker
                        codemaker commented
                        Editing a comment
                        With LLD, it's not possible to create an action right? A prototype trigger can be created but can't define an action that can make use of the item value?
                    • Markku
                      Senior Member
                      Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                      • Sep 2018
                      • 1781

                      #13
                      Regarding the actions, if you need a specific action for the triggers created by the LLD trigger prototypes, you can set a specific tag in those triggers. Then configure an action that is executed only for triggers with that tag. Actions are not quite designed to be created/modified on-the-fly but using f.ex. tags and host groups they can be pretty flexible anyway.

                      Markku

                      Comment

                      • codemaker
                        Junior Member
                        • Aug 2019
                        • 10

                        #14
                        OK. In this case, the items values obtained by the LLD can't be used in the actions right?
                        Is it possible to execute the action multiple times?

                        Comment

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

                          #15
                          I don't have a clue what you are actually trying to do. That said, I believe you can use LLD macros to set tags in trigger prototypes. Also, you can use steps in actions to execute multiple operations.

                          Markku

                          Comment

                          Working...