Ad Widget

Collapse

Pass a parameter from Zabbix (external script) to python code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cyberneticrat
    Junior Member
    • Nov 2021
    • 7

    #1

    Pass a parameter from Zabbix (external script) to python code

    Hello.
    I want to know how to pass a parameter from zabbix to my python script. For example, I have an url in my script, example: "http://127.0.0.1/api/information". I need to pass the macro variable {HOST.CONN} in this ip area of my url, like this: "http://{HOST.CONN}/api/information" and this ip will be replaced by my configured ip host on zabbix. Now my python script is working, it's something like this: api_url = req.get("http://ip-address/api/information") but it's static.

    Any ideas?
  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2

    I might be misunderstanding the question, but...

    External Script Documentation section shows you how to pass params to script?

    Here is example from one of my Zabbix 4.4 setups:

    data_collection_v2_nix.py[SOMETHING-01, some_id]

    And in Python it goes something like:

    Code:
    import sys
    
    def main(argv):
      Name = argv[0]
      ID = argv[1]
      #Rest of code goes here
    
    main(sys.argv[1:])
    And then feel free to use your new variables in Python however you want.

    As {HOST.CONN} can be used in item keys, you should have no issue using it there instead of static strings in my example.

    Please do correct me if I did not understood what exactly you were asking for.

    Comment

    Working...