Ad Widget

Collapse

How to correctly set application template with auto registration ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zeiko
    Junior Member
    • Feb 2022
    • 23

    #1

    How to correctly set application template with auto registration ?

    Hi,

    I 'm testing auto registration and all tutorial I could find only deal with the OS type (Windows vs Linux) to sort the host into group and assign template.

    I need to migrate 600 hosts from zabbix 2 to Zabbix 6, I setted up a new server because the zabbix 2 is really bad configured.

    Right now I want to use HostMetadataItem to detect sql server or web server (MySQL, apache2, Nginx....) is this possible ?

    Does anyone has a proper way to auto monitor application ?

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

    #2
    Yes, metadata can be used for that...

    Comment

    • Zeiko
      Junior Member
      • Feb 2022
      • 23

      #3
      Hi,

      I know they can, my question was more about a proper way to fill the medata field.

      Anyway for the first step of migration I ended up with a simple ansible playbook like this :

      Code:
      ---
      - hosts: all
       become: yes
       vars:
         pkg:
           - "apache2"
           - "mariadb-server"
           - "nginx"   
           - "mongodb"
       tasks:
         - name: "Retreive all installed packages"
           package_facts:
             manager: "auto"
          
         - name: Create metadata string
           set_fact:
             my_string: "{{ my_string | default('') ~ ' ' ~ item }}"
           loop: '{{ pkg }}'
           when: "item in ansible_facts.packages"
          
         - name: Generate zabbix conf file
           lineinfile:
             path: /etc/zabbix/zabbix_agentd.conf
             backrefs: yes
             regexp: "(HostMetadata=.*)$"
             line: '\1{{ my_string }}'
      This is really in baking stage so for now it will match any package in the pkg list with installed package and create the string when package is present on the vm

      Regards

      Comment

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

        #4
        Metdata is just a list of keywords... (with a limit of 255 characters). So how you exactly get it there, is up to you, hardcode (via ansible or manually), or use HostMetadataItem, which returns something each time its needed and you do not need ansible to run and update...
        HostMetadata no 0-255 characters Optional parameter that defines host metadata. Host metadata is used only at host autoregistration process (active agent).
        If not defined, the value will be acquired from HostMetadataItem.
        An agent will issue an error and not start if the specified value is over the limit or a non-UTF-8 string.
        HostMetadataItem no Optional parameter that defines a Zabbix agent item used for getting host metadata. This option is only used when HostMetadata is not defined.
        Supports UserParameters and aliases. Supports system.run[] regardless of AllowKey/DenyKey values.
        HostMetadataItem value is retrieved on each autoregistration attempt and is used only at host autoregistration process (active agent).
        During an autoregistration request an agent will log a warning message if the value returned by the specified item is over the limit of 255 characters.
        The value returned by the item must be a UTF-8 string otherwise it will be ignored.
        After that, all you need to configure, is actions based on that... "if metadata contains XXXX" Link to template XXXX"

        Comment

        • Zeiko
          Junior Member
          • Feb 2022
          • 23

          #5
          Well yes, my whole problem was that zabbix does not include an easy way to detect installed packages with a command in HostMetaDataItem, you can get a list of packages with an API call but I can't implement it for now.

          My actions where configured already, last thing I needed was a proper way to fill HostMetaData and I achieve that with the basic playbook in my previous response.

          This can be improved a lot I think but I still posted my solution in case anyone need it in the future

          Comment

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

            #6
            HostMetadataItem also supports system.run, so you can include local script or oneliner or UserParameter or something...

            Comment

            • Zeiko
              Junior Member
              • Feb 2022
              • 23

              #7
              Originally posted by cyber
              HostMetadataItem also supports system.run, so you can include local script or oneliner or UserParameter or something...
              yeah but for a monitoring tool that include a lot of template for differents services, it's a pain in the ass to automaticaly monitor installed services.

              Like just something where it can detect the existence of mariadb-server and install the monitoring template for mariadb, am I completly missing something to do that ?

              Comment

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

                #8
                No, you are not missing anything... You cannot easily run for example "systemd.unit.discovery" and based on results assign additional templates..
                But if you use HostMetadataItem for discoverying installed services, then autoreg rules can kick in and add needed templates. If your local script/Userparameter can do the same as your ansible thing does... returns that list (or part of it) of installed packages, then its almost OK, I guess. You have there 4 pkg-s, need 4 rules... if any of them match, that template will be added.
                I do agree, it could be improved...

                Comment


                • don Rumata
                  don Rumata commented
                  Editing a comment
                  Hi. Can developers add a new type "Key" (with fields "key", "value") besides "Host name", "Host Metadata" and "Proxy"? I want to use "Link to templates" based on keys like `system.sw.packages[htop,dpkg,short]`.
              Working...