Ad Widget

Collapse

Create item and template for getting information from custom scripts on agent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • g-host
    Junior Member
    • Oct 2020
    • 6

    #1

    Create item and template for getting information from custom scripts on agent

    Hello everyone! I have a problem with creating items and template with these items for right dialog between zabbix-server and zabbix-agent.
    On agent site i have an application which writes some data about some servers in sqlite DB, and I have added two special python scripts which i want to look through this DB and from which i want to send data to zabbix-server. First script (script1.py) takes no argument, that's why i have added it in UserParameter simple like: "UserParameter=agent.script1,../../../script1.py", but it returns a set of string values (some server's names), which it finds in DB. The second script (script2.py) takes one argument(one server name) and returns the status(numbers:0,1 or 2) of this server, that's why i have added it in UserParameter as: "UserParameter=agent.script2[*],../../../script2.py $1".
    I should say that i have added these two strings only on agent site in agent config file(am i right or not i don't know).
    And the main question for me is: how should i create new items for these scripts and then add these items to new created template for the purpose of configurating new host(with zabbix-agent, my scripts and DB with data about some servers) in Web-page of zabbix-server and adding this new-created template to this new-configurated host?
    For me the hard thing is how should i set second item and "tell" it to take as an argument value from the set which was returned from first added item.
    As a result on dashboard Web-page of zabbix-server for new added host i want to see the table like this:
    SERVER NAME I STATUS
    Server1 I 1(active)
    Server2 | 0(failed)
  • g-host
    Junior Member
    • Oct 2020
    • 6

    #2
    I need more details to understand the hole procedure. Maybe you can give a step-by-step instruction?
    Can you right me an example how should i add new item which will take value returned from first script as an argument?
    And what should i choose Agent or Agent(active)?

    Comment

    • sysadm.es
      Junior Member
      • May 2020
      • 21

      #3
      You have multiples ways for configure the script.

      Sending the data to zabbix through the trapper, configuring the key in the zabbix.agent ( preferible for actions that you must send it from localhost ) or placing at /usr/lib/zabbix/externalscripts/ for scripts that can be send to remote hosts.

      If you select this place the third option , just place the key at /usr/lib/zabbix/externalscripts/ and in your zabbix web server, place your item like this "my_scritp.py["-argument","{HOSTNAME}"] where {HOSTNAME} could be a dinamic value. example: "ssl_check.py["-s","www.google.com"]

      If you configure the key at zabbix_agent is the same

      You don't need configure the output of a script in order to serve those information to another item, just use autodiscovery items for generate each dynamic item than you can retrieve from your script.

      If you are familiar with python but not with zabbix, the simplest way for you is send the data through a trapper or API creating the item dynamically. ( if not exist ) through the api. Each item that you discover with your script will be send to zabbix.

      Comment

      • g-host
        Junior Member
        • Oct 2020
        • 6

        #4
        sysadm.es, thank you for your reply, now i will try to sum up.
        Step1. On agent site i add two strings in agent.conf file like i have written before: "UserParameter=agent.script1,../../../script1.py" and "UserParameter=agent.script2[*],../../../script2.py $1". And put sources of these scripts in /usr/lib/zabbix/externalscripts/. Then i can try to use on the server site "zabbix_get -s zabbix-agent-host-ip -k agent.script1 ...." or "zabbix_get -s zabbix-agent-host-ip -k agent.script2 server1 ...." to check that it works.
        Step2. Now on server site i need to add this zabbix-agent-host and create new items to see the data returned from it. I add first item like "agent.script1" and it will return data in format like [{SNAME}:server1, {SNAME}:server2]. Then i should add the second item like "agent.script2["-s","{SNAME}"]" and it will return simple numbers: 0,1 or 2.
        Step3. And now i should do something with Data overview widget to make the output of these two items looks more native and understandable.
        Am i right?

        Comment

        • sysadm.es
          Junior Member
          • May 2020
          • 21

          #5
          Originally posted by g-host
          sysadm.es, thank you for your reply, now i will try to sum up.
          Step1. On agent site i add two strings in agent.conf file like i have written before: "UserParameter=agent.script1,../../../script1.py" and "UserParameter=agent.script2[*],../../../script2.py $1". And put sources of these scripts in /usr/lib/zabbix/externalscripts/. Then i can try to use on the server site "zabbix_get -s zabbix-agent-host-ip -k agent.script1 ...." or "zabbix_get -s zabbix-agent-host-ip -k agent.script2 server1 ...." to check that it works.
          Step2. Now on server site i need to add this zabbix-agent-host and create new items to see the data returned from it. I add first item like "agent.script1" and it will return data in format like [{SNAME}:server1, {SNAME}:server2]. Then i should add the second item like "agent.script2["-s","{SNAME}"]" and it will return simple numbers: 0,1 or 2.
          Step3. And now i should do something with Data overview widget to make the output of these two items looks more native and understandable.
          Am i right?
          Related to the step 2, the simplest way is just send the host as parameter:

          For example, if you wanna check if a webserver response is 200 or not just send the data to the script and return the result 0 or 1 or true or false

          If you must use two scritps, is better option use your first script as parameter and inside this script import the function what you need from the second script. The zabbix server just expects a response as value or text.

          Comment

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

            #6
            Use first script for discovery and use its output to create items, which use second script. On dashboard use Data overview widget to display latest data of those items.

            Comment

            Working...