Ad Widget

Collapse

Custom Item/LLD/Discovery Help Reauest

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • d_mys
    Junior Member
    • Nov 2024
    • 3

    #1

    Custom Item/LLD/Discovery Help Reauest

    Hi

    I am a newbie at Zabbix and still getting to grips with the platform. I have a powershell script that gives the following output:

    [
    {
    "Duration": 12596,
    "TransferredData": 11.71,
    "StopTime": "\/Date(1730698241000)\/",
    "VMName": "vm1",
    "StartTime": "\/Date(1730685645000)\/"
    },
    {
    "Duration": 17277.547761499998,
    "TransferredData": 14.5,
    "StopTime": "\/Date(-2208996000000)\/",
    "VMName": "vm2",
    "StartTime": "\/Date(1730685685000)\/"
    },
    ]

    I have managed to configure the zabbix agent with the userparameter drjob. The script executes properly and I had to override the timeout to ensure it runs else the default 3s causes it to fail. I am trying to get an item with attributes as supplied by the json payload.

    I have read up on multiple blogs and he help guide but am confused on how to get this data into Zabbix. I have tried the following:

    Create a template with a discovery rule and LLD macro processing within the discovery rule

    Click image for larger version

Name:	image.png
Views:	235
Size:	15.3 KB
ID:	493754
    Have tried creating an item as well as item prototypes but cannot seem to get the data into Zabbix. I am not sure on the sequence of tasks to get this setup correctly and right now have no way of trying to see what data is being sent by the agent as looking at the agent I don't see any data with the keys defined. The agent is available an online and windows stats are being received correctly. I have also tried using the drjob[*] but still not sure where I am going wrong.

    I am also not sure on how Zabbix deal with the JSON date string as it seems that when powershell converts the date fields to JSON the output is the string shared in the snippet above.

    Any help of guidance will be appreciated and thank you in advance.

    D

  • ISiroshtan
    Senior Member
    • Nov 2019
    • 324

    #2

    I'm usually not that good with explaining things, but will try to guide you as to how to achieve what you want, while also giving details as to how it works.
    LLD is used for automatically creating items/triggers from prototypes based on iterable JSON. It does not populate said items with data, that should be performed by items itself one way or the other.

    With that in mind, you can do it one of the following ways:
    • Go and straight away create a new discovery of Zabbix agent type executing the script that produces this JSON. I would advise against doing this way in your case tho. As your JSON already contains all the data you want, doing it this way means you will then need to execute the script and parse data by each discovered item.
    • Create an "Master" item (just regular item onto which dependent items will be pointed later) of Zabbix agent type, that will execute your script and will collect resulting json and store it as a string type data.

    As I'm advising you to go 2nd route, I will give you example how to proceed with it:
    So you created your "master" item and it collect data. Create a discovery, set type to "dependent item" and point master item to your item that collects JSON. As discovery itself will not be assigning data into items, you will not need that many LLD Macros. You need only those that would be used in item/trigger names and keys. As such you can leave only {#VMNAME} macro (the path is correct on screenshot).
    Now as to how to populate values into the newly discovered items? We will once again use the dependent items (those things are really handy for a lot of things, read documentation linked about and try to understand them ). To give you one example how it would work: create an item prototype with following values:
    Name: VM {#VMNAME} Duration
    Type: dependent item
    Master item: point to your item that collets that big JSON
    Key: vm.duration[{#VMNAME}]
    Preprocessing steps:
    Type: JSONPath; Value: $[?(@.VMName == "{#VMNAME}")].Duration.first()
    (Documentation about Zabbix supported JSONPath)
    This should be enough for start and after discovery discovers items they should start populating with duration value of respected VM from JSON collected by your original item. Then you can go back to discovery and create more item/trigger prototypes based on your requirements

    One last thing to mention, initially set the master item history storage to some value, to actually be able to see the JSON that is fetched by script. But after all works as you want - you can set it to 0. This way JSON will not be stored in DB and will not be taking space, but it will still be properly used for populating data of dependent items. Really handy!

    Comment

    • d_mys
      Junior Member
      • Nov 2024
      • 3

      #3
      Hi ISiroshtan. Thanks for assisting... I think I understood the process you are trying to describe. I have done the following:

      Create a Template, Created an Item in the template and then created the dependant discovery rules.

      The data collects fine though I think I may have done something wrong in the dependant discovery rule as keep getting the belo error

      Click image for larger version

Name:	image.png
Views:	153
Size:	37.7 KB
ID:	493799


      I have attached the yaml for the template to see if what I did makes sense? Thanks again for the help thus far.


      Comment

      • ISiroshtan
        Senior Member
        • Nov 2019
        • 324

        #4
        Based on screenshot you created 4 discovery rules. That is not what you want. You need to create a single discovery rule without preprocessing (Name it as "DR Jobs discovery" for example). Then inside of discovery rule you create 4 item prototypes of dependent item type, point them to same item as discovery rule itself and add preprocessing in each of items to extract on single value,

        Comment

        • Brambo
          Senior Member
          • Jul 2023
          • 245

          #5
          Originally posted by d_mys
          Hi ISiroshtan. Thanks for assisting... I think I understood the process you are trying to describe. I have done the following:

          Create a Template, Created an Item in the template and then created the dependant discovery rules.

          The data collects fine though I think I may have done something wrong in the dependant discovery rule as keep getting the belo error

          Click image for larger version

Name:	image.png
Views:	153
Size:	37.7 KB
ID:	493799


          I have attached the yaml for the template to see if what I did makes sense? Thanks again for the help thus far.

          Like said above me, the json path of your discovery rules is what you should have used in Item Prototypes > pre-processing part.
          The LLD Macros of your first post should be part of your 1 and only discovery rules.

          Your end result should be something like, 1 discovery rules (depended on your data gathering item) and 4 item prototypes (depended on your data gathering item). And with a LLD macro in the itemkey, And pre-processing jsonpath.

          Comment

          Working...