Ad Widget

Collapse

help needed to create a discovery rule and corresponding item prototypes

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

    #1

    help needed to create a discovery rule and corresponding item prototypes

    Hello,
    I'm trying - without luck - to create a discovery rule and corresponding item prototypes.
    I get the following data with an HTTP agent and like to create items for each "client_name" and the value[1].

    {"status":"success","data":{"resultType":"vector", "result":[{"metric":{"__name__":"urbackup_client_online","cl ient_group":"linux","client_id":"10","client_name" :"default","client_os_version":"Ubuntu 24.04.1 LTS (Noble Numbat); Kernel 6.8.0-47-generic x86_64","client_version":"2.5.25","container":"urb ackup-exporter","endpoint":"metrics","instance":"10.1.2. 80:9554","job":"urbackup-exporter","namespace":"kube-prom-stack","pod":"urbackup-exporter-67ff866df4-cfbwx","service":"urbackup-exporter"},"value":[1737549935.284,"0"]},{"metric":{"__name__":"urbackup_client_online"," client_group":"k8s","client_id":"3","client_name": "test","client_os_version":"Debian GNU/Linux 10 (buster); Kernel 6.8.0-51-generic x86_64","client_version":"2.5.25","container":"urb ackup-exporter","endpoint":"metrics","instance":"10.1.2. 80:9554","job":"urbackup-exporter","namespace":"kube-prom-stack","pod":"urbackup-exporter-67ff866df4-cfbwx","service":"urbackup-exporter"},"value":[1737549935.284,"1"]}]}}

    I would be very thankful if sbdy could show me the required configuration in detail - my trials never create the items.

    Thank you in advance.
  • Answer selected by daniva at 03-02-2025, 20:42.
    kyus
    Senior Member
    • Feb 2024
    • 171

    Hey!

    I'm glad it worked!

    It's pretty easy to create a trigger prototype:

    Set a name like: Something went wrong on {#CLIENT}
    Use the following expression:
    Code:
    last(/your template here/your.item.key[{#CLIENT}])=0
    You can use a different function if you're worried about false positives, maybe:
    Code:
    sum(/your template here/your.item.key[{#CLIENT}],#3)=0
    You may use a recovery expression if you wish.

    One last tip, you can also use the "Add" button to create your expressions.
    Click on the button, click on select prototype;
    Select your item prototype and define the desired function.

    Comment

    • daniva
      Junior Member
      • Jan 2025
      • 8

      #2
      I would really appreciate if somebody could help me, anybody?

      Comment

      • kyus
        Senior Member
        • Feb 2024
        • 171

        #3
        Hey!

        You need to create an item for each "client_name" to collect the "value[1]", so in this example you would get 2 items?
        Like:

        Item name: default
        value: 0

        Item name: test
        value: 1

        Is that what you want to achieve?

        Comment

        • daniva
          Junior Member
          • Jan 2025
          • 8

          #4
          Hi kyus,
          Yes the two items with the values would be the result.
          Actually there are much more items than the two (I've deleted it out of the sample data above), that's why I'd like to create the items with a discovery rule.
          Can you help me with the discovery rule? All my trials did not create any items.
          Thank you.

          Comment

          • kyus
            Senior Member
            • Feb 2024
            • 171

            #5
            Hey!

            Since that's what you need, i think you can do the following:

            1. Create a discovery rule that is dependent to your HTTP item.
            1.1. In the discovery rule, create a LLD Macro to store your client_name, let's say {#CLIENT}

            2. Create a item prototype in this discovery rule that is dependent to your HTTP Item.
            2.1. Set the name of the item to something like: Value on {#CLIENT}
            2.2. Set the key of the item to something like: value[{#CLIENT}]
            2.3. Set the value type to "Text"

            3. In the preprocessing tab of the item prototype, do the following:
            3.1. Add 2 regular expression preprocessing steps, like:
            3.1.1. Parameter "client_name":"{#CLIENT}".*?"value":.*?\]\} with output \0
            3.1.2. Parameter "value":.*?"(0|1)with output \1
            Click image for larger version

Name:	image.png
Views:	141
Size:	33.3 KB
ID:	498116

            Be aware that i didn't test the whole thing. I did test the regex, with {#CLIENT} being default and test, so you will need to store those values exactly like that in your LLD Macro, or you could also change the regex...

            I based this in a template that i created in my structure, the ideas are the same but it may need some adjusts.

            Comment

            • daniva
              Junior Member
              • Jan 2025
              • 8

              #6
              Hi kyus,
              Thank you very much for your explanation. I've updated my discovery rule and item prototype, when I press the test button it works - BUT when I apply the template to a host I only see the main item in Latest Data.
              Is there a way I can debug the discovery rule?

              Comment

              • kyus
                Senior Member
                • Feb 2024
                • 171

                #7
                Maybe your macros aren't being extracted as expected.

                In the way I made it, the macros need to receive a the value without any extra characters, in the example it would be only default and test
                Sometimes it can be a little bit tricky to extract these values with JSONPath and not have any extra character like a bracket or a quotation mark.

                You can try using different paths to get the right value

                Comment

                • daniva
                  Junior Member
                  • Jan 2025
                  • 8

                  #8
                  Hi kyus,
                  Would appreciate it very much if you could give me a hint how to define the preprocessing and LLD for the discovery rule - unfortunately I'm getting nowhere with it....

                  Comment

                  • kyus
                    Senior Member
                    • Feb 2024
                    • 171

                    #9
                    Hey, try doing the following:

                    In your discovery rule add a JSONPath preprocessing step with path: $.data.result[*].metric
                    Click image for larger version

Name:	image.png
Views:	129
Size:	21.0 KB
ID:	498285

                    In LLD macros add a {#CLIENT} macro with path $.client_name
                    Click image for larger version

Name:	image.png
Views:	114
Size:	16.2 KB
ID:	498286

                    Then proceed to create the item prototypes as described in the previous post.

                    Test it out and see if it does what you expect!

                    Comment

                    • daniva
                      Junior Member
                      • Jan 2025
                      • 8

                      #10
                      Hi kyus,
                      You're a hero! - it works. Could you maybe help me with a trigger prototype as well? Value 0 should create a warning.
                      Thank you very much.

                      Comment

                      • kyus
                        Senior Member
                        • Feb 2024
                        • 171

                        #11
                        Hey!

                        I'm glad it worked!

                        It's pretty easy to create a trigger prototype:

                        Set a name like: Something went wrong on {#CLIENT}
                        Use the following expression:
                        Code:
                        last(/your template here/your.item.key[{#CLIENT}])=0
                        You can use a different function if you're worried about false positives, maybe:
                        Code:
                        sum(/your template here/your.item.key[{#CLIENT}],#3)=0
                        You may use a recovery expression if you wish.

                        One last tip, you can also use the "Add" button to create your expressions.
                        Click on the button, click on select prototype;
                        Select your item prototype and define the desired function.

                        Comment

                        • daniva
                          Junior Member
                          • Jan 2025
                          • 8

                          #12
                          Hi kyus,
                          Thank you for your help, I'll give it a try later.

                          Comment

                          • daniva
                            Junior Member
                            • Jan 2025
                            • 8

                            #13
                            Hi kyus,
                            I've managed to create a trigger prototype, thks again for your help.
                            One more question: It looks like the http Agent truncates the data, is there a way to increase the amount of data transferred?

                            Comment

                            • kyus
                              Senior Member
                              • Feb 2024
                              • 171

                              #14
                              I know there are some limits, but I'm not sure whether or not they apply to your scenario.
                              I found this post that relates something similar:

                              Comment

                              Working...