Ad Widget

Collapse

Using Zabbix LLD to monitor a list of items

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kevind
    Member
    • Sep 2011
    • 40

    #1

    Using Zabbix LLD to monitor a list of items

    You know how to make items and triggers to monitor things. But what if you want to monitor a number of similar things on the same host? Or multiple hosts?

    You can use Zabbix low-level discovery to generate monitoring items, IF there is a way to return a JSON object with names and values for the items to monitor. Zabbix has a number of built-in methods for discovering items such as SNMP, file systems etc. But Zabbix currently doesn't have any way that I know of to just give it a list of things to monitor. So I made a script called "discover_items" which can do that. You place this script (attached with .txt extension, rename to no extension) in your externalscripts directory and make it executable.

    Then make a discovery rule to generate items. You can then use {#ITEM_NAME}, {#ITEM_INDEX}, {#ITEM_VALUE0} etc. in item prototypes as you would with any Zabbix LLD items.

    discovery item: discover_items[a#60,b#1440]
    will return JSON object:
    {
    "data":[
    {
    "{#ITEM_NAME}":"a",
    "{#ITEM_VALUE0}":"60",
    "{#ITEM_INDEX}":"0"
    }
    ,
    {
    "{#ITEM_NAME}":"b",
    "{#ITEM_VALUE0}":"1440",
    "{#ITEM_INDEX}":"1"
    }
    ]
    }

    Now, you can use this in a template. Suppose you want to monitor a number of directories on a number of Windows servers, to make sure that files are being create / modified, and you want to alert if file modification stops.

    You make a user macro {$RECENT_FILE_SPECS} for each host, with a list of filespecs to watch, and number of minutes to look back for each ('\' needs to be triple-escaped to get through to powershell):

    example {$RECENT_FILE_SPECS}:
    C:\\\\Reports\\\\Blue\\\\*#1440,C:\\\\Reports\\\\O range\\\\*#120,C:\\\\Reports\\\\Purple\\\\*#60

    You then create a template with a discovery item "Recent File Specs" of type "External Check":
    discover_items[{$RECENT_FILE_SPECS}]

    Then you create an item prototype "Recent files {#ITEM_NAME}" of type "Zabbix agent (active)", data type "Decimal":
    system.run["powershell \"@(Get-ChildItem {#ITEM_NAME} | Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-{#ITEM_VALUE0})}).count\"",wait]

    This item uses powershell to return the count of files which match the filespec and were written within {#ITEM_VALUE0} minutes. If no files were written within that period, we want to alert.

    Create a trigger prototype "{HOST.NAME}: No recent files matching {#ITEM_NAME}":
    {Template_Recent_Files_Windows:system.run["powershell \"@(Get-ChildItem {#ITEM_NAME} | Where-Object { $_.LastWriteTime -gt (Get-Date).AddMinutes(-{#ITEM_VALUE0})}).count\"",wait].last()}=0

    Now we can apply this template to any host, and create a user macro {$RECENT_FILE_SPECS} on each host with a list of file directories / file specs to monitor.

    This technique can be used in a wide variety of situations where we know the list of things we want to monitor, but we can't discover the list with the usual LLD methods.
    Attached Files
  • thijz
    Junior Member
    • Aug 2013
    • 12

    #2
    Hi Kevind,

    I came up with something similar to your script simply because there doesnt seem to be a way to provide a static (JSON) list to zabbix that it can then use for LLD.
    It would be a lot easier if you could somehow just create an item with static value, or even better use a macro (containing JSON) to set a item value.
    So far I have not found any way to do this :-(

    Anyway, i'm glad i found this post and the workaround

    Comment

    • prchalsefira
      Junior Member
      • Jan 2023
      • 5

      #3
      Hi folks,

      I'm dealing with the same problem. I need to monitor multiple tenants on a host. I assumed that I would put a list of values in JSON in the macro and create the items/hosts using discovery. Isn't there an option in the current version of Zabbix to use macro as input to discovery?

      Thanks.

      Comment

      • LenR
        Senior Member
        • Sep 2009
        • 1005

        #4
        I haven't done this, but I considered pushing a file (in our case with Puppet) to hosts containing JSON in LLD format then just using a vfs.file.contents item. Would that work? How you get the JSON file there doesn't matter, it could be static.

        The removal of user macro's from item names broke how we monitor "vanity" web url's on hosts. We had a template. defined a macro on the host with the URL. It worked for hosts with one vanity URL. I had considered pushing a JSON file with all URL's I wanted to monitor on a host then using LLD, but I don't think there is a web test LLD method either. I just scripted the entire web test setup with the API.

        Comment

        Working...