Ad Widget

Collapse

Macro in item key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jaiguru
    Junior Member
    • Jan 2007
    • 1

    #1

    Macro in item key

    Hi All,

    Alexei : thank you (again) for your really good job.

    I notice several posts requesting for the possibility to use macros in the key part of items :




    I need this functionnality too, because I need to monitor a large numer of Oracle databases with Zabbix. I would like to be able to create templates with items using some caracteristics from the final host. This will allow me to create "virtual hosts" with some naming conventions like this :

    1. I create a template named Oracle with items configured like that :
    item name : 'Db size'
    item key : 'zabora[{HOSTNAME},dbsize]'
    2. To monitor a database named 'MyDB', I create a host named 'MyDB' with IP address of the host executing my UserParametter script. The item is automatically created, using key 'zabora[MyDB,dbsize]'...

    Do you think it's possible ? Does anyone already created a patch for that ?

    Regards
  • dsipe
    Senior Member
    • Oct 2006
    • 184

    #2
    That kind of functionnality would definitly be very very userful.

    i vote for that too

    Comment

    • styx
      Junior Member
      • Jan 2007
      • 7

      #3
      That's exactly what I need. It would be so helpfull !!

      Comment

      • James Wells
        Senior Member
        • Jun 2005
        • 664

        #4
        Greetings,
        Originally posted by jaiguru
        I notice several posts requesting for the possibility to use macros in the key part of items
        A patch could be added to provide this functionality pretty easily, however, in the long run it would become completely unwieldy against the current stable and development code branches.

        There are two distinct ways of doing this, both of them easy to implement, but very painful to maintain due to the way Zabbix processes item keys;
        1. Have the UI process the {HOSTNAME} macro at item creation time. This method would allow you to use the macro when you create the item. The UI would then do a simple macro replacement when it stores the item key_ to the database. The problem though is that this item couldn't then be templated without some serious changes to the way templates work. When you tried to edit the items template, it would overwrite the now hardcoded host entry in all of the children, if it was able to find them, or break their template links if it was unable to find them. Additionally the creation of triggers would have to support this, which would be very expensive to do.

        2. Have the server process the {HOSTNAME} at item check time. In this mode, the Zabbix server would perform the macro replacement each time it sent the item check to the agent, this would have to be done in passive agent mode. This one would actually be fairly computationally expensive as the server would have to scan each and every item for possible macros. Overall this method would be easier to maintain than the first method, but would still increase the overhead on the server. BTW, this method could not be used with active agents.

        Thinking about this more, it seems to me, a third way would be to have the agent perform the macro replacement. This would distribute the computing cost a bit better, it would allow for templatization, and triggering... I will have to think on this a bit more. In this mode, neither the UI, nor server, would need to do anything with the macro, but the agent would need to process it at least twice, once to convert the macro to the host name and once to convert the hostname back to the macro for delivery to the server. Definately worth more thought.
        Unofficial Zabbix Developer

        Comment

        • Alexei
          Founder, CEO
          Zabbix Certified Trainer
          Zabbix Certified SpecialistZabbix Certified Professional
          • Sep 2004
          • 5654

          #5
          Both 1. and 2. can be implemented, I do not see any showstoppers here. However, it is likely, that the whole concept of the unique item keys will be changed in long tem. I do not like that parameters are stored in the key, this won't work for testing of database connections, etc.

          If we implement macros now, it would potentially create enormous difficulties for upgrade.
          Alexei Vladishev
          Creator of Zabbix, Product manager
          New York | Tokyo | Riga
          My Twitter

          Comment

          • Farzad FARID
            Member
            • Apr 2007
            • 79

            #6
            Hi,

            I see that I need this functionnality too now! I'm using the Zabbix 1.3.x serie.

            The solution I like most is having the zabbix server dynamically expand the macro before sending the item request to the agent, wether it's an active check or not.

            Maybe there could be 2 different macro expansion systems, one for the server, one for the agent? Specifically I need the "{IPADDRESS}" macro, it makes sense to expand this macro on the server, because the agent could have more than one active IP.

            Regards

            Comment

            • AdrianS
              Junior Member
              • Mar 2007
              • 12

              #7
              Fast patch for {HOSTNAME} macro in key value...

              zabbix-1.4.5/src/zabbix_server/poller/poller.c

              --- /tmp/poller.c 2008-06-11 16:49:24.000000000 +0200
              +++ poller.c 2008-06-11 15:34:41.000000000 +0200
              @@ -45,8 +45,14 @@

              struct sigaction phan;

              - zabbix_log(LOG_LEVEL_DEBUG, "In get_value(key:%s)",
              - item->key);
              + zabbix_log(LOG_LEVEL_DEBUG, "In get_value(key:%s) server:%s",
              + item->key, item->host_name);
              +
              +// Check if we have {HOSTNAME} in key
              + if(strstr(item->key,"{HOSTNAME}")){
              + zabbix_log(LOG_LEVEL_DEBUG, "Got {HOSTNAME} makro in key value - replacing.");
              + strcpy(item->key,string_replace(item->key,"{HOSTNAME}",item->host_name));
              + }

              phan.sa_handler = &child_signal_handler;
              sigemptyset(&phan.sa_mask);
              Last edited by AdrianS; 11-06-2008, 17:39.

              Comment

              • AdrianS
                Junior Member
                • Mar 2007
                • 12

                #8
                Here is the same patch for 1.6 version of zabbix.

                zabbix-1.6/src/zabbix_server/poller/poller.c

                --- poller.c 2008-09-18 22:15:26.000000000 +0200
                +++ poller.c-new 2008-10-30 15:12:40.000000000 +0100
                @@ -48,8 +48,14 @@ int get_value(DB_ITEM *item, AGENT_RESUL
                {
                int res = FAIL;

                - zabbix_log(LOG_LEVEL_DEBUG, "In get_value(key:%s)",
                - item->key);
                + zabbix_log(LOG_LEVEL_DEBUG, "In get_value(key:%s) server:%s",
                + item->key, item->host_name);
                +
                +// Check if we have {HOSTNAME} in key
                + if(strstr(item->key,"{HOSTNAME}")){
                + zabbix_log(LOG_LEVEL_DEBUG, "Got {HOSTNAME} makro in key value - replacing.");
                + strcpy(item->key,string_replace(item->key,"{HOSTNAME}",item->host_name));
                + }

                switch (item->type) {
                case ITEM_TYPE_ZABBIX:
                And now small explanation what we needed it for...
                For example - we have about 10 "zones" on Solaris OS or 20 Apache server. Now I can create template "t_zone", and "t_apache" - and create "normal" hosts (10 zones, 20 apache). As a hostname I use unique name, and as DNS/IP real name of physical server. Then on zabbix_agent side, scripts gets as a argument real apache/zone name and can return correct values.
                With that it's easy to maintain dozens of apache/jboss/zones/wls etc. since we have a template, and not just "cloned/copied" stuff inside real server statistics.

                It would be also helpful to have triggers yet...

                Comment

                • Alexei
                  Founder, CEO
                  Zabbix Certified Trainer
                  Zabbix Certified SpecialistZabbix Certified Professional
                  • Sep 2004
                  • 5654

                  #9
                  Note that macros {HOSTNAME}, {IPADDRESS}, {HOST.CONN} and {HOST.DNS} can be used in item key's parameters starting from 1.6.1.
                  Alexei Vladishev
                  Creator of Zabbix, Product manager
                  New York | Tokyo | Riga
                  My Twitter

                  Comment

                  • AdrianS
                    Junior Member
                    • Mar 2007
                    • 12

                    #10
                    Heh what can I say - GREAT

                    Comment

                    • geno
                      Junior Member
                      • Nov 2008
                      • 29

                      #11
                      {HOST.DNS} in Action msg body not working

                      Hi,

                      {HOST.DNS} would be very useful thanks! I do find however that it doesn't work when I use it as part of the msg body in an action; in the email I receive I literally get "{HOST.DNS}" displayed.

                      Regards
                      Geno

                      (I'm using v1.6.1)

                      Comment

                      • arli
                        Member
                        • Jan 2008
                        • 71

                        #12
                        Originally posted by Alexei
                        Note that macros {HOSTNAME}, {IPADDRESS}, {HOST.CONN} and {HOST.DNS} can be used in item key's parameters starting from 1.6.1.
                        I'm using Zabbix 1.6.3 and when I try to add simple check key:

                        tcp,{IPADDRESS},1521

                        I get - Incorrect key format 'key_name[param1,param2,...]'
                        Is this how it's supposed to work or am I doing something else wrong?

                        Comment

                        • geno
                          Junior Member
                          • Nov 2008
                          • 29

                          #13
                          no offense, but have you read the manual?

                          Comment

                          • arli
                            Member
                            • Jan 2008
                            • 71

                            #14
                            Yes I have:

                            ZABBIX Manual (PDF) 1.6 rev 17 16 January, 2009

                            4.10.5.Simple checks
                            Simple checks are normally used for agent-less monitoring or for remote checks
                            of services. Note that ZABBIX Agent is not needed for simple checks. ZABBIX
                            Server is responsible for processing of simple checks (making external
                            connections, etc).
                            All simple check accepts two optional parameters:
                            ip - IP address. Dafult value is 127.0.0.1
                            port - Port number. If missing, standard default service port is used.

                            So if manual suggest, that I can use two optional parameters, and Alexei is saying, that {IPADDRESS} macro is supported in item keys, I don't understand, why it's not working.

                            I also think, that one of the weakest aspects of Zabbix is it's documentation.

                            Comment

                            • geno
                              Junior Member
                              • Nov 2008
                              • 29

                              #15
                              you're not the first to feel this way about the docs.
                              I agree with you, the matrix on p90 says {IPADDRESS} is supported for Item's. I don't know if that includes simple check items... Alexei?

                              Comment

                              Working...