Ad Widget

Collapse

Zabbix LLD Macros and filters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chintan1
    Junior Member
    • Jun 2022
    • 24

    #1

    Zabbix LLD Macros and filters

    Hello All,

    Need your help with lld Macros and filters in discovery

    I have created an item of type http where I am running Prometheus query and fetching json data.



    Using this item I have created a dependent discovery where I am using preprocessing as $.data.metrics[*].metrics



    From this I m fetching multiple lld macros.





    I have a metric named Ab_serive which contains name like abx-main abx- backup



    I am storing {#abc1} $.ab_service

    {#abc2} $.ab_service storing same values in both macros.



    While applying filters



    Abc1 matches .*main

    Abc2 matches .*backup



    Or



    Abc1 matches .*main

    Abc1 doesnotmatch .*backup

    Abc2 matches .*backup

    Abc2 doesnot matches .*main



    These filters are not working as expected any suggestions?
  • chintan1
    Junior Member
    • Jun 2022
    • 24

    #2
    Click image for larger version

Name:	image.png
Views:	199
Size:	43.5 KB
ID:	498128Click image for larger version

Name:	image.png
Views:	148
Size:	43.5 KB
ID:	498129
    Click image for larger version

Name:	image.png
Views:	143
Size:	40.7 KB
ID:	498130
    Click image for larger version

Name:	image.png
Views:	148
Size:	70.4 KB
ID:	498131Click image for larger version

Name:	image.png
Views:	145
Size:	70.4 KB
ID:	498132​$.data.result[?(@.metric.mk_service=='{#MK_SERVICE_BACKUP}' && @.metric.channel_name=='{#CHANNEL_NAME}')].value[1]
    Json data:


    {"__name__":"mk_rt_tx_rate_mbps","account_id":" f94-48a5-8f13-635283cc8a48","account_name":"sss","backup_source_ id":"534a99ba84f90dee90f115","channel_id":"15bb0 88 70b1a71650e","channel_name":"ND","cloud":"azure"," container":"srt","endpoint":"http-metrics","env":"nb-c","env_type":"live","instance":":49365","job": "sr t-worker","main_source_id":"d7dd17485da83f643be93eec 59","mk_service":"1-mkn-backup","mode":"udp","namespace":"med","native":"t rue","pod":"srt-1-mkn-backup-srt-1-99c7-2qg54","prometheus":"med/metrics-kube-prometheus-st-prometheus","prometheus_replica":"prometheus-metrics-kube-prometheus-st-prometheus-0","region":"eastus2","service":"srt-1-mkn-backup-srt-1","zone":"eastus2"},"value":[1738127893,"34.358016"]},



    {"__name__":"mk_rt_tx_rate_mbps","account_id":" f94-48a5-8f13-635283cc8a48","account_name":"sss","backup_source_ id":"534a99ba84f90dee90f115","channel_id":"15bb0 88 70b1a71650e","channel_name":"ND","cloud":"azure"," container":"srt","endpoint":"http-metrics","env":"nb-c","env_type":"live","instance":":49365","job": "sr t-worker","main_source_id":"d7dd17485da83f643be93eec 59","mk_service":"1-mkn-main","mode":"udp","namespace":"med","native":"t rue","pod":"srt-1-mkn-backup-srt-1-99c7-2qg54","prometheus":"med/metrics-kube-prometheus-st-prometheus","prometheus_replica":"prometheus-metrics-kube-prometheus-st-prometheus-0","region":"eastus2","service":"srt-1-mkn-backup-srt-1","zone":"eastus2"},"value":[1738127893,"34.358016"]},​

    Comment

    • kyus
      Senior Member
      • Feb 2024
      • 171

      #3
      Hey!

      So, when you say your filters aren't working, what do you exactly mean?

      Are your items not being created in the Host?
      Are they being created but with the wrong values?

      Comment

      • chintan1
        Junior Member
        • Jun 2022
        • 24

        #4
        Hi kyus,

        Without filters it discovers both the metrics of mk_service


        Click image for larger version

Name:	image.png
Views:	140
Size:	50.1 KB
ID:	498165

        With filters everything gets undiscovered:

        Click image for larger version

Name:	image.png
Views:	138
Size:	22.1 KB
ID:	498166Click image for larger version

Name:	image.png
Views:	135
Size:	66.1 KB
ID:	498167​​

        Comment

        • chintan1
          Junior Member
          • Jun 2022
          • 24

          #5
          And with both as doesn't match, it filters both main and backup which gives rest everything

          Click image for larger version

Name:	image.png
Views:	150
Size:	27.1 KB
ID:	498169

          Comment

          • kyus
            Senior Member
            • Feb 2024
            • 171

            #6
            I'm not sure if the fact that you extracted the same value to 2 macros can be a problem, but you can test it, just to make sure.

            You don't really need 2 macros for what you want.

            Try removing both {#MK_SERVICE_BACKUP} and {#MK_SERVICE_MAIN}.
            Create a single {#MK_SERVICE} macro.

            In filters add a filter {#MK_SERVICE} matches .+backup|.+main

            Hope it helps

            Comment

            • Kos
              Senior Member
              Zabbix Certified SpecialistZabbix Certified Professional
              • Aug 2015
              • 3404

              #7
              Hi,

              unfortunately, it is not very clear for me what is your purpose.
              As well, to advice something useful, it's necessary, at least, the following information:
              • version of your Zabbix server;
              • example of JSON that is the source for your LLD rule.

              Comment


              • chintan1
                chintan1 commented
                Editing a comment
                Thank you @Kos

                Version is 7.2
                Source you mean the initial json data before preprocessing?

              • Kos
                Kos commented
                Editing a comment
                > Source you mean the initial json data before preprocessing?
                If possible, after preprocessing; but exactly JSON used for LLD, not for item prototypes (if they differ).
            • chintan1
              Junior Member
              • Jun 2022
              • 24

              #8
              kyus,

              I am actually looking for 2 item prototypes. One with main and another with backup so trying to filter main from backup and back up from main macros but it's not working

              Comment

              • kyus
                Senior Member
                • Feb 2024
                • 171

                #9
                Since both item prototypes seem to be equal, it won't really change anything if you had only one macro extracting both values...

                Well, it does look like either some error in your regex matching (it seems fine to me) or some unexpected behaviour in your preprocessing steps

                Comment

                Working...