Ad Widget

Collapse

Using trigger to update host to be monitored by another proxy

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zyelony
    Junior Member
    • Jan 2023
    • 5

    #1

    Using trigger to update host to be monitored by another proxy

    Hello!

    I'm relatively new to using Zabbix, so I'm hoping someone will be able to help me with a solution.

    We are planning to implement monitoring using Zabbix in our company, as we have a distributed network, separated into three locations, we depend on monitoring external locations using a proxy server.
    In order to implement a fail-safe in case the proxy server fails, we would like to have a fallback output in the form of automatic switching of hosts from being monitored by the proxy, to the main server, or another proxy server. In short, we want to implement redundancy.

    We would like the solution to be as fast as possible, so I was wondering if it is possible to run scripts through triggers that would update the hosts by changing their "monitored by proxy" value.

    For the proxy, we have a trigger configured that reports immediately that there is no connection to the proxy.

    Trigger
    I found in the Actions menu, the ability to set an action for the Trigger, so that when a problem occurs, there is an opportunity to perform certain actions. At the same time, there is the possibility to use created scripts.
    However, I am not sure if it is possible to create a script that updates the values of a host or a hosts group.

    When scripting here, should the Zabbix API be used?
    Click image for larger version

Name:	image.png
Views:	577
Size:	17.7 KB
ID:	457694

    Is there anyone who would be able to explain if it can be done the way I described above, or do I have to look for another solution?

    Zabbix Server version: 6.0.12
    Zabbix Proxy version: 6.0.12​​
    The server as well as the proxy are put on FreeBSD

    If there is an option to do this using scripts in Python, I would ask for a possible explanation of how such scripts can be used in Zabbix itself
    Attached Files
  • fvilarnovo
    Junior Member
    • Jan 2023
    • 17

    #2
    Hello,
    As you described is a possible solution. Basically, you should execute an alert script only when a specific event generated by that trigger and matches you conditions (for example a specific tag, etc) also you should evaluate the issue considering flapping of the proxy in a way to not have false positives. The script should list all host that belong to that proxy and then use that array of hosts ids, to update. Once updated maybe you could also add a tag to those hosts in order to identify them. Have a look at this api method:

    https://www.zabbix.com/documentation...rence/host/get the parameter "proxyids" should let you filter hosts by proxy.

    Have a look at this blog post, maybe it has more sense to it:

    https://blog.zabbix.com/how-to-setup...rations/12092/

    Hope it helps.

    Comment

    • Zyelony
      Junior Member
      • Jan 2023
      • 5

      #3
      Hello,

      I've gotten to the point where I already have a simple working script written in python, written using the pyzabbix repo. However, I have a problem with this code.

      import sys
      import logging
      from pyzabbix import ZabbixAPI

      zapi = ZabbixAPI("http://192.168.1.232/zabbix")
      zapi.login(api_token = 'my_api_token')

      host_list = zapi.host.get(groupids=21, output=["extend"])
      print(host_list)

      zapi.proxy.update(proxyid=xxxxx, hosts=host_list)
      It's not a particularly complicated script, just a few lines, and the problem arises with the 'proxyid' parameter for the proxy.update method.
      I can use it without a problem to assign to selected hosts, specific selected proxies, however when I try to assign them to the main server by setting the proxyid=0 value I get an error, that the object does not exist. Can you tell what ID should I use to assign host to server, not proxies?

      Comment

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

        #4
        If I look into DB, then proxy_hostid field is empty for hosts, which are polled directly by server.
        So I suppose you don't need to specify anything there...

        Comment

        Working...