Ad Widget

Collapse

LLD - IP Interfaces

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • un tecnico mas
    Junior Member
    • Apr 2022
    • 10

    #1

    LLD - IP Interfaces

    Hello,

    I am using low level discovery to get only the interfaces that have IP, but I am not getting it. I have gone through all the Zabbix documentation on their website.

    Has anyone been able to do it?

    Regards
  • dave_t
    Junior Member
    • Apr 2007
    • 28

    #2
    Here's a write-up I created when I wanted to get my head around LLD.

    Not sure what O/S you're using, but you should be able to do something like:
    Code:
    ip a | grep -E "UP|inet"| awk '{print $2}'
    and then work the output of that into a custom LLD rule based on the info below, and then define Item Prototypes accordingy.

    Cheers

    ----------

    Low Level Discovery of Items (hopefully) simplified.

    I struggled a little when trying to figure out how to set this up, so wanted to share my "light-bulb" moment with those who may want to perform LLD but are still confused.

    Plase note: This is my understanding thus far, and I am 100% sure there are far more things that LLD can offer - but this is just scratching the surface.

    Custom LLD two parts:

    1: "Discovery" - This is a a job/script/process which collates a bunch of information, and then formats the output according to a set of rules.
    2: "Items prototypes" - These are Zabbix "item-like" processes called "prototypes", which are associated with the "Discovery" rule.
    - They take input from the "Discovery", and create proper zabbix "items" on the hosts(s) where the LLD rule has been applied.

    3: "Trigger prototypes - These make sense after 1 & 2 are understood

    OK, so let's say I want to track the top CPU hog on a Unix/Linux system.
    In order to do this, I need to create a "Discovery" script which will periodically execute the "ps aux" which then needs to be numerically sorted of the 3rd field, and I only want the last line.

    Code:
    ps aux | sort -nk 3 | tail -n1
    This will provide me with the following output, which I will need to parse to give me the fields I am interested in.
    In this example, I want the Item Prototype to create a Zabbix Item called:

    Code:
    proc.cpu.util[<name>,<user>,<type>,<cmdline>,<mode>,<zone>] Process CPU utilization percentage. Returns float
    Therefore, I want to capture the following values from the "ps aux | sort -nk 3 | tail -n1" command:
    Code:
    <user> : $1
    <name> : $2 (which I will explain later, but it is to maintain uniqueness for the Item)
    <cmdline> : $11
    i.e.

    root 1 4.7 0.1 167508 11472 ? Ss 18:09 5:36 /sbin/init maybe-ubiquity
    $1 $2 $3 $4 $5 $6 $7 $8 $9 $10 $11 $12


    In order to do this, I prefer to use "awk" to format the output which can be used by the Item Prototype.
    I want the PID to be instered in the <name> field for the Item Prototype so that if there are more then one <cmdlines>, we can identify which one is the CPU hog by the PID.

    Therefore the format of the Item Prototype needs to be:

    Code:
    [ {"{#PID}": "$2","{#USER}": "$1","{#CMD}": "$11"} ]
    ...so we use the following "printf" formatting to produce the output that will be produced every time the Discover script is executed:

    Code:
    ps aux | sort -nk 3 | tail -n1 | awk '
    BEGIN { ORS = ""; print " [ "}
    { printf "%s{\"{#PID}\": \"%s\",\"{#USER}\": \"%s\",\"{#CMD}\": \"%s\"}", delim, $2,$1,$11
    delim = ", " }
    END { print " ] " }';
    RESULT:
    Code:
    [ {"{#PID}": "1","{#USER}": "root","{#CMD}": "/sbin/init"} ]


    (Hopefully) things will start to make sense from here on in...

    Now that the "Discovery" script is producing the desired output each time that it runs the , we need to tell Zabbix how to run it, and how often.
    This is pretty simple, and you should already be familiar with UserParameters, so put the above script somewhere that the zabbix get to it (i.e. /usr/local/bin/zbx.cpuhog.disco.sh") and change permissions etc...
    Then in the zabbix_agentd.conf, define a UserParameter and then restart the agent:

    UserParameter=cpuhog.disco,/usr/local/bin/zbx.cpuhog.disco.sh

    In either a Template (preferred) or on the Host itself, go to "Discovery", and create a Discovery called:

    Code:
    Name CPU Hog
    Type Zabbix Agent
    Item cpuhog.disco
    Update Interval 60s
    Keep Lost Resources 0 <- if the previously discovered process no longer exists, remove the item.
    OK - so you can "Test" this, (if you've set it up on a template you can apply the template to your host first)

    Now we want Zabbix to create an Item every time the Discovery script executes.
    To do this, go into the "Item Prototypes" for your Discovery rule, and add the following:
    NOTE, we can use the macros used in the item key to create a unique name for the item prototype:

    Code:
    Name CPU Hog : {#USER} --> {#PID}:{#CMD}
    Type Zabbix Agent
    Key proc.cpu.util["{#PID}","{#USER}",,"{#CMD}"]
    Type if info Float
    Update Interval 20s
    Create Enabled [tick the box] (if setting this up as a "template")
    Discover [tick the box]

    So, working this through....
    The "Discovery" will run every 60s, and identify the top CPU hog, which will feed information to the prototype to create an item which in this example will be:

    Code:
    Name CPU Hog : root --> 1:/sbin/init
    Type Zabbix Agent
    Key proc.cpu.util["1","root",,"/sbin/init"]
    *** NOTE ***
    In this example, if you change the value of "-n1" in the script to something like "-n10", the Discovery will produce a list of the top 10 CPU hogs, and the prototype will create 10 unique items, and as mentioned previously when they are no longer discoverable they will be automatically removed.


    Once you have grasped this concept, then Trigger Prototypes and Graph Prototyes will make perfect sense.

    Hope this helps at least someone :-)
    Last edited by dave_t; 25-04-2022, 21:15.

    Comment

    Working...