Ad Widget

Collapse

How can override trigger for some items ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bab
    Senior Member
    • Aug 2020
    • 176

    #1

    How can override trigger for some items ?

    I have created a discovery that include an item prototype also defines a trigger prototype for this itemprototype. Item prototype will find free space of tables on datatabse . Now I have added this as template to more than 50 hosts . It is working excellent I just need change trigger for such tables on some hosts for example my trigger prototype will fire when free space of each table is les than 1G . but for example on host1 I have table1 also this table exist on host2 now how can define for hosts 2 it does not use from trigger prototype and if free space is less than 10G trigger fire ?
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Use custom macros in the trigger expression and override macros at the host level.

    Comment

    • bab
      Senior Member
      • Aug 2020
      • 176

      #3
      Originally posted by Hamardaban
      Use custom macros in the trigger expression and override macros at the host level.
      https://www.zabbix.com/documentation...os/user_macros
      Thanks . But this is my trigger prototype . As I find out you are saying set value map on the template and override it on the hosts but as you can see I need change value for each items for example want to change trigger on BGTBS to fire if < 30 and for DM_TRANS < 10 for the others without changes


      Attached Files

      Comment

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

        #4
        Then you need to use user macros with context https://www.zabbix.com/documentation...macros_context

        Comment

        • bab
          Senior Member
          • Aug 2020
          • 176

          #5
          Originally posted by cyber
          Then you need to use user macros with context https://www.zabbix.com/documentation...macros_context
          As I find out :

          At the first step had to define a macro such as {$SIZE} = 1 in my template .
          Second step change trigger to last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE} on template
          finally we have to add values such as follow

          {$SIZE: BGTBS} = 30
          {$SIZE: DM_TRANS} = 10

          but How should change trigger ?

          Comment

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

            #6
            You need to use context already in prototype...
            Code:
            last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE:"{#TABLESPACE_NAME}"}
            Then you can use general {$SIZE} macro for those Tablespaces where you do not have special context, or don't want to use overrides
            and {$SIZE:"<your tablespace name>"} for those cases where you need special value...

            Comment

            • bab
              Senior Member
              • Aug 2020
              • 176

              #7
              Originally posted by cyber
              You need to use context already in prototype...
              Code:
              last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE:"{#TABLESPACE_NAME}"}
              Then you can use general {$SIZE} macro for those Tablespaces where you do not have special context, or don't want to use overrides
              and {$SIZE:"<your tablespace name>"} for those cases where you need special value...
              I am really confused .
              1- As I find out at the first step should add new macro such as {$SIZE} = 1 to my template . Is this correct ?
              2- for the next step should change trigger prototype from last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<1 to last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE:"{#TABLESPACE_NAME}"} is this correct ?
              3- Finally don't know what is the last step while want to change trigger for some tablespacenames ? Do I have to do changes on each hosts on macro ?
              Last edited by bab; 18-04-2023, 08:27.

              Comment

              • bab
                Senior Member
                • Aug 2020
                • 176

                #8
                Would you please help me about above questions ?

                Comment

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

                  #9

                  1. yes, but it can also be second step..
                  2. yes
                  3. If you read the docs on macros with context, then you would notice, that if you create a "general" {$SIZE} macro, it will be used everywhere, where context macro is not defined... You can add also (for example) {$SIZE:"BGTBS"} and {$SIZE:"DM_TRANS"} macros to your template, if you can define values what should fit most of your hosts... for any other mountpoint it will use "general" macro". In case you need to fine tune on host level, you can then add needed macro on host level, which will override template level macro.

                  This is exactly how contextual macros are used in out-of-the-box templates for filesystems, for example... triggers are created with context, but values for such macros you can define where you need ...

                  Comment

                  • bab
                    Senior Member
                    • Aug 2020
                    • 176

                    #10
                    Originally posted by cyber
                    1. yes, but it can also be second step..
                    2. yes
                    3. If you read the docs on macros with context, then you would notice, that if you create a "general" {$SIZE} macro, it will be used everywhere, where context macro is not defined... You can add also (for example) {$SIZE:"BGTBS"} and {$SIZE:"DM_TRANS"} macros to your template, if you can define values what should fit most of your hosts... for any other mountpoint it will use "general" macro". In case you need to fine tune on host level, you can then add needed macro on host level, which will override template level macro.

                    This is exactly how contextual macros are used in out-of-the-box templates for filesystems, for example... triggers are created with context, but values for such macros you can define where you need ...


                    Thanks. The issue solved just one question
                    I set this one as event name FreeSpace of Table [{#TABLESPACE_NAME}] is less than {$SIZE:"{#TABLESPACE_NAME}"}G
                    because I want it detect the size that I have defined as override on the host . Now it is showing 1G for all events although I set {$SIZE:"{#TBSB}"} = 6 on host1 .
                    How can fix it ?
                    Last edited by bab; 18-04-2023, 23:24.

                    Comment

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

                      #11
                      LLD macro {#TABLESPACE_NAME} gets replaced with the real name during dicovery process, so you end up with {$SIZE:"TBSB"} not {$SIZE:"{#TBSB}"}. Can you spot your mistake?

                      Comment

                      • bab
                        Senior Member
                        • Aug 2020
                        • 176

                        #12
                        Originally posted by cyber
                        LLD macro {#TABLESPACE_NAME} gets replaced with the real name during dicovery process, so you end up with {$SIZE:"TBSB"} not {$SIZE:"{#TBSB}"}. Can you spot your mistake?
                        I changed it such as : FreeSpace of Table [{#TABLESPACE_NAME}] is less than {$SIZE}G but another trigger fires with FreeSpace of Table [TBSSPOT] is less than 1G​ although I set it trigger if less than 5 on this host

                        Comment

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

                          #13
                          You still did not notice, what I wrote and what you configured?

                          Set your trigger name as "FreeSpace of Table [{#TABLESPACE_NAME}] is less than {$SIZE:"{#TABLESPACE_NAME}"}G"
                          (I hope your trigger expression is still "last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE:"{#TABLESPACE_NAME}"}" ?? )

                          Create macro {$SIZE} with value 1
                          Create macro {$SIZE:"TBSSPOT"} with value 5
                          (additionally) Create macro for any tablespace, what needs a value different from general {$SIZE} macro...

                          Observe how triggers behave...

                          Comment

                          • bab
                            Senior Member
                            • Aug 2020
                            • 176

                            #14
                            Originally posted by cyber
                            You still did not notice, what I wrote and what you configured?

                            Set your trigger name as "FreeSpace of Table [{#TABLESPACE_NAME}] is less than {$SIZE:"{#TABLESPACE_NAME}"}G"
                            (I hope your trigger expression is still "last(/TBS/FreeSpace[{#TABLESPACE_NAME}])<{$SIZE:"{#TABLESPACE_NAME}"}" ?? )

                            Create macro {$SIZE} with value 1
                            Create macro {$SIZE:"TBSSPOT"} with value 5
                            (additionally) Create macro for any tablespace, what needs a value different from general {$SIZE} macro...

                            Observe how triggers behave...

                            Thanks. But before that I was created Create macro {$SIZE:"TBSSPOT"} with value 5 on specific host (override) . But after trigger another shows FreeSpace of Table [TBSSPOT] is less than 1G​ . Do I have to also add {$SIZE} with value 1 on this host as I have added {$SIZE} with value 1 to template before that.

                            Comment

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

                              #15
                              If you have a macro in template, then you don't need to add it on host level. You should do that only if you want to override a value set in a template macro.. If you have a macro already in host level it will take precedence over the template level macro...


                              Zabbix resolves macros according to the following precedence:
                              1. host level macros (checked first)
                              2. macros defined for first level templates of the host (i.e., templates linked directly to the host), sorted by template ID
                              3. macros defined for second level templates of the host, sorted by template ID
                              4. macros defined for third level templates of the host, sorted by template ID, etc.
                              5. global macros (checked last)

                              In other words, if a macro does not exist for a host, Zabbix will try to find it in the host templates of increasing depth. If still not found, a global macro will be used, if exists.
                              Its all there in docs..

                              Comment

                              Working...