Ad Widget

Collapse

How can create a custom item for a script

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

    #1

    How can create a custom item for a script

    I have a script that return follow output :

    HTML Code:
     |spa       |dae_0_1_disk_12  |    4771
                        |spa       |dae_0_1_disk_14  |    4916
                        |spa       |dae_0_1_disk_16  |   337.5
                        |spa       |dae_0_1_disk_18  |   91.52
                        |spa       |dae_0_1_disk_2   |    6375
                        |spa       |dae_0_1_disk_20  |    9826
                        |spa       |dae_0_1_disk_22  |   10133
                        |spa       |dae_0_1_disk_24  |   127.1
                        |spa       |dae_0_1_disk_4   |   194.9
                        |spa       |dae_0_1_disk_6   |   146.0
                        |spa       |dae_0_1_disk_8   |   11435
                        |spa       |dae_0_2_disk_0   |   15726
                        |spa       |dae_0_2_disk_10  |   14060
                        |spa       |dae_0_2_disk_12  |   15737
                        |spa       |dae_0_2_disk_14  |   11848
                        |spa       |dae_0_2_disk_16  |    5843
                        |spa       |dae_0_2_disk_18  |   15882
                        |spa       |dae_0_2_disk_2   |   15678
                        |spa       |dae_0_2_disk_20  |   549.0
                        |spa       |dae_0_2_disk_22  |   346.4
                        |spa       |dae_0_2_disk_24  |   776.8
                        |spa       |dae_0_2_disk_4   |   865.2
                        |spa       |dae_0_2_disk_6   |    9026
                        |spa       |dae_0_2_disk_8   |    4180
                        |spa       |dae_0_3_disk_0   |    6810
    ​
    As the output will change every 5 minutes (here is "4916 , 337.5 , 91.52, .........".Is that possible create items for this output ? For example it shows
    dae_0_1_disk_14 = 4916
    dae_0_1_disk_16 = 337.5
    dae_0_1_disk_18 = 91.52
    .
    .
    .
    .
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Of course it is possible - use dependent item with a regex type preprocessing.


    If the data set can change and you don't want to create many identical elements with your hands, use LLD.


    For details, refer to the documentation.

    Comment

    • bab
      Senior Member
      • Aug 2020
      • 176

      #3
      Originally posted by Hamardaban
      Of course it is possible - use dependent item with a regex type preprocessing.
      https://www.zabbix.com/documentation...ependent_items

      If the data set can change and you don't want to create many identical elements with your hands, use LLD.
      https://www.zabbix.com/documentation...evel_discovery

      For details, refer to the documentation.

      Thanks. Actually I prefer to use LLD but I am just running follow command on zabbix server :

      "uemcli -d 172.2.2.2 -u USER -securePassword -sslPolicy store /metrics/value/rt -path sp..physical.disk..responseTime show "

      and it returns such as this

      HTML Code:
      |spa |dae_0_1_disk_14 | 4916
      |spa |dae_0_1_disk_16 | 337.5
      |spa |dae_0_1_disk_18 | 91.52
      |spa |dae_0_1_disk_2 | 6375
      |spa |dae_0_1_disk_20 | 9826
      |spa |dae_0_1_disk_22 | 10133​
      ​Would you please some help me how can create this LLD
      Last edited by bab; 07-01-2023, 20:45.

      Comment

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

        #4
        This output is not the best to convert, but doable... but you could try to obtain data already as CSV ( at least https://www.dell.com/support/manuals...0b2&lang=en-us shows a command with -output csv) or even better json (I cannot find anything in docs about this one) ... Then you can skip all the converting in Zabbix side .. With current output format you should do "convert to CSV" and then "CSV to JSON". Then you can point LLD macros to correct place in JSON. and then you can do all your discovery stuff...
        If you can format data already at origin point properly, yu can skip some conversion steps. Rest of it is in the link given above...

        Comment

        • bab
          Senior Member
          • Aug 2020
          • 176

          #5
          Originally posted by cyber
          This output is not the best to convert, but doable... but you could try to obtain data already as CSV ( at least https://www.dell.com/support/manuals...amp;lang=en-us shows a command with -output csv) or even better json (I cannot find anything in docs about this one) ... Then you can skip all the converting in Zabbix side .. With current output format you should do "convert to CSV" and then "CSV to JSON". Then you can point LLD macros to correct place in JSON. and then you can do all your discovery stuff...
          If you can format data already at origin point properly, yu can skip some conversion steps. Rest of it is in the link given above...

          I could convert output such as follow :

          HTML Code:
          Timestamp,SP,disk,Average Response Time us
          2023-01-10 05:33:00,spa,dae_0_1_disk_0,730.1
          2023-01-10 05:33:00,spa,dae_0_1_disk_10,159.5
          2023-01-10 05:33:00,spa,dae_0_1_disk_12,20786
          2023-01-10 05:33:00,spa,dae_0_1_disk_14,9578
          2023-01-10 05:33:00,spa,dae_0_1_disk_16,20647
          2023-01-10 05:33:00,spa,dae_0_1_disk_18,20.97
          2023-01-10 05:33:00,spa,dae_0_1_disk_2,4902
          2023-01-10 05:33:00,spa,dae_0_1_disk_20,19.72
          2023-01-10 05:33:00,spa,dae_0_1_disk_22,9451
          2023-01-10 05:33:00,spa,dae_0_1_disk_24,19.11
          2023-01-10 05:33:00,spa,dae_0_1_disk_4,23060
          2023-01-10 05:33:00,spa,dae_0_1_disk_6,986.3
          2023-01-10 05:33:00,spa,dae_0_1_disk_8,314.4
          2023-01-10 05:33:00,spa,dae_0_2_disk_0,130.0
          2023-01-10 05:33:00,spa,dae_0_2_disk_10,18438
          2023-01-10 05:33:00,spa,dae_0_2_disk_12,498.4
          2023-01-10 05:33:00,spa,dae_0_2_disk_14,27105
          2023-01-10 05:33:00,spa,dae_0_2_disk_16,630.4
          2023-01-10 05:33:00,spa,dae_0_2_disk_18,177.4
          2023-01-10 05:33:00,spa,dae_0_2_disk_2,174.6
          2023-01-10 05:33:00,spa,dae_0_2_disk_20,7830
          2023-01-10 05:33:00,spa,dae_0_2_disk_22,193.0
          2023-01-10 05:33:00,spa,dae_0_2_disk_24,1783
          ​
          ​​​​​​​What should I do now ?

          Comment

          • Hamardaban
            Senior Member
            Zabbix Certified SpecialistZabbix Certified Professional
            • May 2019
            • 2713

            #6
            Originally posted by cyber
            With current output format you should do (1) "convert to CSV" and then (2) "CSV to JSON". Then you can (3) point LLD macros to correct place in JSON . and then you can do (4) all your discovery stuff...
            Step (1) - Done!
            Step (2) - see https://www.zabbix.com/documentation...ng/csv_to_json
            Step (3) - https://www.zabbix.com/documentation...#custom-macros
            Step (4) - https://www.zabbix.com/documentation...tem_prototypes

            Comment

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

              #7

              So I assume your item works and retrieves data? Add a preprocessing to it, "CSV to JSON". then your data is saved as
              [
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_0","Aver age Response Time us":"730.1"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_10","Ave rage Response Time us":"159.5"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_12","Ave rage Response Time us":"20786"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_14","Ave rage Response Time us":"9578"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_16","Ave rage Response Time us":"20647"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_18","Ave rage Response Time us":"20.97"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_2","Aver age Response Time us":"4902"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_20","Ave rage Response Time us":"19.72"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_22","Ave rage Response Time us":"9451"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_24","Ave rage Response Time us":"19.11"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_4","Aver age Response Time us":"23060"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_6","Aver age Response Time us":"986.3"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_1_disk_8","Aver age Response Time us":"314.4"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_0","Aver age Response Time us":"130.0"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_10","Ave rage Response Time us":"18438"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_12","Ave rage Response Time us":"498.4"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_14","Ave rage Response Time us":"27105"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_16","Ave rage Response Time us":"630.4"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_18","Ave rage Response Time us":"177.4"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_2","Aver age Response Time us":"174.6"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_20","Ave rage Response Time us":"7830"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_22","Ave rage Response Time us":"193.0"},
              {"Timestamp":"2023-01-10 05:33:00","SP":"spa","disk":"dae_0_2_disk_24","Ave rage Response Time us":"1783"}
              ]​
              Add a discovery. Type of information -> text. Set its type as "dependent item" and point master item to the item that retrieves your data. Add to LLD macros tab "{#DISK} -> $.disk".
              Add item prototype to discovery, Type of information -> float. Set its type as "dependent item" and point master item to the item that retrieves your data. (yes the same as in discovery). Add preprocessing "JSONPath -> $.[?(@.disk=="{#DISK}")].['Average Response Time us'].first()"
              EDIT2: name your item prototype as disk_avgerage[{#DISK}] for example... it has to contain LLD macro, but rest is up to you...

              Now, when your main item acquires data, first time all the items are created, based on disk name. Second time, they are already populated with a value.

              ​EDIT: oh short answer came earlier..
              Last edited by cyber; 10-01-2023, 12:03.

              Comment


              • Hamardaban
                Hamardaban commented
                Editing a comment
                The full answer is much better! :-)
            • bab
              Senior Member
              • Aug 2020
              • 176

              #8
              Originally posted by cyber
              So I assume your item works and retrieves data? Add a preprocessing to it, "CSV to JSON". then your data is saved as

              Add a discovery. Type of information -> text. Set its type as "dependent item" and point master item to the item that retrieves your data. Add to LLD macros tab "{#DISK} -> $.disk".
              Add item prototype to discovery, Type of information -> float. Set its type as "dependent item" and point master item to the item that retrieves your data. (yes the same as in discovery). Add preprocessing "JSONPath -> $.[?(@.disk=="{#DISK}")].['Average Response Time us'].first()"
              EDIT2: name your item prototype as disk_avgerage[{#DISK}] for example... it has to contain LLD macro, but rest is up to you...

              Now, when your main item acquires data, first time all the items are created, based on disk name. Second time, they are already populated with a value.

              ​EDIT: oh short answer came earlier..


              I have created an item on my server with userparameter such as attach pic 11.jpg and it is returns follow output :

              HTML Code:
              Storage system address: 172.22.30.29
              Storage system port: 443
              HTTPS connection
              
              Timestamp,SP,disk,Average Response Time us
              2023-01-15 15:27:45,spa,dae_0_1_disk_0,2994
              2023-01-15 15:27:45,spa,dae_0_1_disk_10,150.5
              2023-01-15 15:27:45,spa,dae_0_1_disk_12,19662
              2023-01-15 15:27:45,spa,dae_0_1_disk_14,41225
              2023-01-15 15:27:45,spa,dae_0_1_disk_16,222.9
              2023-01-15 15:27:45,spa,dae_0_1_disk_18,21.00
              2023-01-15 15:27:45,spa,dae_0_1_disk_2,12836
              2023-01-15 15:27:45,spa,dae_0_1_disk_20,19.57
              2023-01-15 15:27:45,spa,dae_0_1_disk_22,37016
              2023-01-15 15:27:45,spa,dae_0_1_disk_24,33111
              2023-01-15 15:27:45,spa,dae_0_1_disk_4,274.4
              2023-01-15 15:27:45,spa,dae_0_1_disk_6,19460
              2023-01-15 15:27:45,spa,dae_0_1_disk_8,9598
              2023-01-15 15:27:45,spa,dae_0_2_disk_0,5841
              2023-01-15 15:27:45,spa,dae_0_2_disk_10,184.8
              2023-01-15 15:27:45,spa,dae_0_2_disk_12,209.1
              2023-01-15 15:27:45,spa,dae_0_2_disk_14,17660
              2023-01-15 15:27:45,spa,dae_0_2_disk_16,20.77
              2023-01-15 15:27:45,spa,dae_0_2_disk_18,21181
              2023-01-15 15:27:45,spa,dae_0_2_disk_2,8786​

              In the next step I have created a discover rule with attached item.prototype and preprocessing but when I click on test it shows error . How can solve it ?


              Attached Files

              Comment

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

                #9
                Remove that part first
                Code:
                Storage system address: 172.22.30.29
                Storage system port: 443
                HTTPS connection​
                you only need CSV part...

                When you test, give also value to macro ... replace that {#DISK} there with real value from data (like dae_0_2_disk_16), so you can compare, that correct thing will be extracted. I also don't see anything entered into "value" field during testing... ? You need to feed it with proper json...

                Comment

                • bab
                  Senior Member
                  • Aug 2020
                  • 176

                  #10
                  Originally posted by cyber
                  Remove that part first
                  Code:
                  Storage system address: 172.22.30.29
                  Storage system port: 443
                  HTTPS connection​
                  you only need CSV part...

                  When you test, give also value to macro ... replace that {#DISK} there with real value from data (like dae_0_2_disk_16), so you can compare, that correct thing will be extracted. I also don't see anything entered into "value" field during testing... ? You need to feed it with proper json...


                  At the first step I have created an item such as emc1.jpg that returns follow output :

                  HTML Code:
                  Timestamp,SP,disk,Average Response Time us
                  2023-01-19 21:45:20,spa,dae_0_1_disk_0,22.62
                  2023-01-19 21:45:20,spa,dae_0_1_disk_10,49368
                  2023-01-19 21:45:20,spa,dae_0_1_disk_12,20.83
                  2023-01-19 21:45:20,spa,dae_0_1_disk_14,19.21
                  2023-01-19 21:45:20,spa,dae_0_1_disk_16,12239
                  2023-01-19 21:45:20,spa,dae_0_1_disk_18,49557
                  2023-01-19 21:45:20,spa,dae_0_1_disk_2,12074
                  2023-01-19 21:45:20,spa,dae_0_1_disk_20,21.17
                  2023-01-19 21:45:20,spa,dae_0_1_disk_22,8135​
                  in the second step I have create a discovery rule such as emc2.jpg
                  in the next step I have created an itemprototype such as emc3.jpg with preprocessing emc4.jpg
                  now when click on test it shows error (emc5.jpg)
                  Also I gave value to macro but returns error (emc6.jpg)
                  What is the issue ?

                  Attached Files

                  Comment

                  • bab
                    Senior Member
                    • Aug 2020
                    • 176

                    #11
                    Originally posted by bab



                    At the first step I have created an item such as emc1.jpg that returns follow output :

                    HTML Code:
                    Timestamp,SP,disk,Average Response Time us
                    2023-01-19 21:45:20,spa,dae_0_1_disk_0,22.62
                    2023-01-19 21:45:20,spa,dae_0_1_disk_10,49368
                    2023-01-19 21:45:20,spa,dae_0_1_disk_12,20.83
                    2023-01-19 21:45:20,spa,dae_0_1_disk_14,19.21
                    2023-01-19 21:45:20,spa,dae_0_1_disk_16,12239
                    2023-01-19 21:45:20,spa,dae_0_1_disk_18,49557
                    2023-01-19 21:45:20,spa,dae_0_1_disk_2,12074
                    2023-01-19 21:45:20,spa,dae_0_1_disk_20,21.17
                    2023-01-19 21:45:20,spa,dae_0_1_disk_22,8135​
                    in the second step I have create a discovery rule such as emc2.jpg
                    in the next step I have created an itemprototype such as emc3.jpg with preprocessing emc4.jpg
                    now when click on test it shows error (emc5.jpg)
                    Also I gave value to macro but returns error (emc6.jpg)
                    What is the issue ?

                    Attached emc6.jpg
                    Attached Files

                    Comment

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

                      #12
                      Did you enter something into "value" filed also, when testing?
                      I cannot find from pics, where do you apply "csv to json" preprocessing? emc1.jpg does not have any preprocessing steps...

                      Comment

                      • bab
                        Senior Member
                        • Aug 2020
                        • 176

                        #13
                        Originally posted by cyber
                        Did you enter something into "value" filed also, when testing?
                        I cannot find from pics, where do you apply "csv to json" preprocessing? emc1.jpg does not have any preprocessing steps...
                        According to emc6.jpg I just insert parameter in macro part for test
                        I used CSV to json according emc4.jpg in item prototype in discovery

                        Comment

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

                          #14
                          That pic show only jsonpath preprocessing, but no "csv to json", please add it to the item on pic emc1.jpg....
                          And if you test, you need to give also starting data to test, not just one value to macro...

                          I tried to restore my testing template, adding it here... "should" work... but I had no time to test it thoroughly.
                          Attached Files

                          Comment

                          • bab
                            Senior Member
                            • Aug 2020
                            • 176

                            #15
                            Originally posted by cyber
                            That pic show only jsonpath preprocessing, but no "csv to json", please add it to the item on pic emc1.jpg....
                            And if you test, you need to give also starting data to test, not just one value to macro...

                            I tried to restore my testing template, adding it here... "should" work... but I had no time to test it thoroughly.

                            Thanks but after add template to that host and select it in discovery role to execute it shows "Cannot send request: wrong discovery rule type."
                            Also this returns numbers with microsecond unit how can change it to millisecond unit ?
                            Attached Files
                            Last edited by bab; 20-01-2023, 11:46.

                            Comment

                            Working...