Ad Widget

Collapse

Auto-link template when certain software is installed

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • tompaah
    Junior Member
    • Jan 2025
    • 8

    #1

    Auto-link template when certain software is installed

    Already got the Autoregistration working well, with picking up the OS type and applying basic Linux or Windows template by checking the HostMetadataItem which is set to system.uname. Theoretically I could also pass installed software with the HostMetadataItem configuration parameter for additional template linking at the Autoregistration stage, but it is not practical with hundreds of machines to build different configuration files for each host agent. Also, installed software on a host can vary over time, it would then need to modify the agent configuration after a change.

    Is it possible to automatically link a template to a host, based on what software the host has installed?
    For example, to automatically link the Docker by Zabbix agent 2 template if the host has Docker installed, or to link MSSQL by ODBC template if the host has MS SQL installed?

    Tried fiddling around with Triggers but went into a dead end in how to make a trigger link a template. Also checked out Discovery rules which doesn't seem to be what would help here. Just started playing around with Zabbix in an enterprise environment so forgive me for asking total noob questions.
    Last edited by tompaah; 20-01-2025, 18:07. Reason: Corrected typo
  • Answer selected by tompaah at 21-01-2025, 19:12.
    cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    HostMetadataItem is not just run once... it will run at least with every restart (of agent)... and if metadata changes, autoreg is run again, which then allows adding new templates...


    Autoregistration is rerun:
    • if host metadata information changes:
      • due to HostMetadata changed and agent restarted
      • due to value returned by HostMetadataItem changed
    Over API you can do whatever, just need to have source data... there is "system.sw.packages[<regexp>,<manager>,<format>]​" but for windows you probably need to find something else.. If you run something from cron/scheduler to get installed software, you might aswell update metadata in agent config.. which will trigger new autoreg..

    Comment

    • tompaah
      Junior Member
      • Jan 2025
      • 8

      #2
      No answers, is this trickier than I thought? Or am I thinking wrong?

      I'd just like to
      1. deploy as generic zabbix_agent2.conf as possible to my host agents that..
      2. .. enables Autoregistration of the host on the server and links the right basic template according to what operating system the host has, for example Linux by Zabbix agent active
        (this far I got it working fine by setting HostMetadata or HostMetadataItem)
      3. Now get Zabbix to discover what software is installed and link appropriate templates.
        This shouldn't be rocket science, installed software can be detected by checking installed packages or checking for the presence of a file.
      How is this done normally, are you all just manually applying templates to hosts after adding them to Zabbix?

      Comment

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

        #3
        You cannot trigger autoreg actions from agent (software) discovery. You probably should provide this information via metadata. It could be a local scipt. Thats why it is calle "HostMetadataItem".. it is something to run and obtain the data... Then you don't need to build lots of different configs... And trust me, that software list does not change that often.. Most probably you do not repurpose a server, easier to start from blank page, decommission it, when not needded and deploy a new one for new task/software/etc. Other way would be to use somekind of naming conventions for servers, so you could decide based on name..

        Comment

        • tompaah
          Junior Member
          • Jan 2025
          • 8

          #4
          You're right about hosts usually not being repurposed or changing application software altogether. It's rare or non-existant.

          But deployment of the Agent2 (and thus its Autoregistration) would most likely be done as a standardised flow to deploy the OS, so the Agent2 is always deployed (and thus the host is Autoregistered) before the actual application is installed. So all hosts deployed would only appear in Zabbix with the standard OS template, not any application specific templates.

          So I'd still be interested in automatically finding installed software and linking the appropriate template/-s in Zabbix to the host.

          If this isn't possible natively with Zabbix or the Agent2 maybe we need to do this with a scheduled job/cronjob on the host that checks installed software and links the host to the right templates via the Zabbix API.

          Comment

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

            #5
            HostMetadataItem is not just run once... it will run at least with every restart (of agent)... and if metadata changes, autoreg is run again, which then allows adding new templates...


            Autoregistration is rerun:
            • if host metadata information changes:
              • due to HostMetadata changed and agent restarted
              • due to value returned by HostMetadataItem changed
            Over API you can do whatever, just need to have source data... there is "system.sw.packages[<regexp>,<manager>,<format>]​" but for windows you probably need to find something else.. If you run something from cron/scheduler to get installed software, you might aswell update metadata in agent config.. which will trigger new autoreg..

            Comment

            • tompaah
              Junior Member
              • Jan 2025
              • 8

              #6
              Okay, thanks cyber . There was a few things I didn't understand but now I do.
              1. HostMetadataItem is able to call and run scripts and commands, and not only pass on static information. This is a game changer here since it can be made run a inventory script that outputs whatever you want, and that output can be picked up by the Autoregistration rules in Zabbix
              2. Autoregistration runs periodically, when the HostMetadataItem changes
              These two in combination achieves exactly what I want and does it very elegantly.

              So Donkey .. edit your zabbix_agent2.conf and configure
              Code:
              HostMetadataItem=system.run[/etc/zabbix/hostmedatascript.sh]
              which I now learned runs the script /etc/zabbix/hostmetadata.sh

              This script in turn is a very simple one that does a uname to get the operating system type and apt list --installed to list all packages, with some formatting added to make this a one-liner (not sure if it's needed) and strip out some packages we don't care about in any case.

              Code:
              #/bin/sh
              uname | cat | tr '\n' ' ' && apt list --installed 2>/dev/null | grep -v -E 'lib|Listing' | cut -d'/' -f1 | tr '\n' ' '
              The script is run quite often by default and if the package listing is a heavy task for the system you can turn up the value
              RefreshActiveChecks=5
              so it doesn't run too often.

              Here are the Autoregistration rules that picks up the base operating system and the docker package.

              Click image for larger version  Name:	image.png Views:	1 Size:	36.0 KB ID:	497552
              Last edited by tompaah; 21-01-2025, 21:42. Reason: Correct typo

              Comment

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

                #7
                Originally posted by Donkey
                Oh wow. I had no idea. No one tells you this stuff. I'll give that a go.
                It is all in docs... just need to put 2 and 2 together..

                Originally posted by Donkey
                Are we saying this whole thing relies on Active Checks?
                yes ... Check for items contains metadata, to provide it, it needs to be refreshed. If no "ServerActive" is defined, agent never turns to server/proxy, never autoregisters and does not get any items either... It just sits there and waits for polls from server/proxy

                Comment

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

                  #8
                  What is there so complicated?
                  Active item means agent will perform all the querying by itself and sends data to proxy/server, passive item means, proxy/server will query for values. As long as I can remember only items that cannot be used as passive are log and logrt as they need local "memory" of the positions, where to look in logfiles...
                  Active agent will ask for config by itself, passive does not have anything locally. Having active agent does not mean you cannot use passive checks from proxy/server (if FW-s etc allow connections in that direction), as agent knows those items anyway, it will perform that query and return the answer... If your agent has not configured as active, there is no point assigning active items to it..

                  Comment

                  Working...