Creating a Zabbix Low Level Discovery rule step-by-step

I have never found a good guide for how to create my own Zabbix LLD rule and create a template for that.

In this post I will take you through these steps.

So, how is it works? What we need for it works?

How is it works

We need a script which return to us a JSON with a list of <key>:<value>. Where the keys are our LLD macros and the values are the data to use in our items prototypes.

When we create an example you will understand better.


In this case, I needed monitoring CPU usage and Memory usage by Pods in an Azure managed cluster Kubernetes (AKS) with nodes Windows and Linux.

I found a ready script fot it:

Then, I put it on: /usr/lib/zabbix/externalscripts/ and change your permission execution: chmod +x

Then, test it:

                ./ | jq
 “data”: [
 “{#NODE}”: “akswin000000”,
 “{#CONTAINER}”: “aspnet”,
 “{#NAMESPACE}”: “default”,
 “{#NAME}”: “aspnet-deploy-6568b8fb6f-89c4s”
 “{#NODE}”: “aks-linux-27581135-vmss000000”,
 “{#CONTAINER}”: “azure-ip-masq-agent”,
 “{#NAMESPACE}”: “kube-system”,
 “{#NAME}”: “azure-ip-masq-agent-pwtg9”

That’s cool!

Now, we can create a UserParameters to run this script in our discovery rule.

So, edit the zabbix_agentd.conf en add it:


Test it again!

                systemctl restart zabbix-agent.service

zabbix_agentd -t discovery.k8s.cluster

Return of test

Now, we can create our template and our rule and items.


Discovery rule

This is the point where we use the LLD macros to create each node and pod found.

The data passed as a param ({#NODE}) will be received by the UserParam to get the values and then return only one thing for for us.


Item prototypes

For each item prototype we need add more line in our zabbix_agentd.conf

                UserParameter=discovery.k8s.node.pcpu[*],kubectl top node '$1' --no-headers=true  | tr -s ' ' | cut -d' ' -f3 | grep -Eo '[0-9]*'
UserParameter=discovery.k8s.node.pmem[*],kubectl top node '$1' --no-headers=true  | tr -s ' ' | cut -d' ' -f5 | grep -Eo '[0-9]*'
UserParameter=discovery.k8s.node.cpu[*],kubectl top node '$1' --no-headers=true  | tr -s ' ' | cut -d' ' -f2 | grep -Eo '[0-9]*'
UserParameter=discovery.k8s.node.mem[*],kubectl top node '$1' --no-headers=true  | tr -s ' ' | cut -d' ' -f4 | grep -Eo '[0-9]*'
UserParameter=discovery.k8s.npods.mem[*],kubectl top pods '$1' -n '$2' --no-headers=true  | tr -s ' ' | cut -d' ' -f3 | grep -Eo '[0-9]*'
UserParameter=discovery.k8s.npods.cpu[*],kubectl top pods '$1' -n '$2' --no-headers=true  | tr -s ' ' | cut -d' ' -f2 | grep -Eo '[0-9]*'

Test again and again:

                systemctl restart zabbix-agent.service
zabbix_agentd -t discovery.k8s.node.pcpu[akswin000000]

Output for test of zabbix_agentd

I created some graphs too.

Some template macros for filters.

And the discovery rule filter using template macros.

To zabbix user can connect in my AKS was needed to do login in Azure CLI and get-credentials to merge kubectl config.

I created a user in Azure AD for it and assigned the roles for it:

                az role assignment create --assignee "" --role "Azure Kubernetes Service Cluster User Role" --scope $(az aks show --resource-group resource-grup --name cluster-name --query id -o tsv)

az role assignment create --assignee "" --role "Azure Kubernetes Service RBAC Reader" --scope "$(az aks show --resource-group resource-group --name cluster-name --query id -o tsv)"
az login
echo ~zabbix
mkdir -p ~zabbix/.kube/
cp /root/.kube/config ~zabbix/.kube/
chown zabbix:zabbix ~zabbix -R

Test more one time:

                sudo -H  -u zabbix bash -c "kubectl get pods"

And finally create a host and associate a template.

Only registered users can post comments. Please, login or signup.

Start blogging about your favorite technologies and get more readers

Join other developers and claim your FAUN account now!




Total Hits