[ZBXNEXT-3507] Dynamic Templates Created: 2016 Oct 20  Updated: 2016 Oct 24

Status: Need info
Project: ZABBIX FEATURE REQUESTS
Component/s: Documentation (D), Frontend (F), Server (S), Templates (T)
Affects Version/s: None
Fix Version/s: None

Type: New Feature Request Priority: Major
Reporter: Radek Lisowski Assignee: Unassigned
Resolution: Unresolved Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File dynamic-templates.png     XML File zbx_export_templates_os_disk.xml    

 Description   

Background

Since I started to use zabbix I am missing a feature to dynamically set items in templates.

Use cases

#. We have a template for a service like Redis server - it is ok, but what if we will use more than one instance? We would need to clone this template for each additional redis instance.

#. We have multiple servers with different partition layout. On some servers we have only one root partition ( /) which we want to monitor but on some others we have for example root partition( /), database partition(/mnt/database), and on some other we have additional parititon for log (/var/log). In all different cases we would need separate templates to configure it all.

#. In my particular case we have also occured to have multiple TCP ports to be monitored if they are working properly or missing. Our customers may want to define a new one (additional) so for each additional set of ports I would need multiple templates to use. Right this could be done with standard LLD and we could discover ports either from netstat or from configuration (this would be impossible in this case).

Limitations

I want to limit to minimum zabbix agent modifications (additional scripts, userparameters modification etc).

Solution

I have managed to find a solution for that problem. It is by using Low Level Discovery and specific MACROs layout. This required from me to extend MACRO length in database and frontend limitations in some cases, but I guess that more people may want to use this as a built-in feature. How it works is described on attached graph.

Example

We have a Macro in a format (I have used all available special characters I guess)

ROOT_PARTITION:/^1G^1^1^3600+DATABASE:/mnt/database^20G^1^1^3600

We are having autodiscovery key named:

custom.itemdiscovery[{$OURMACRO}]

. Zabbix agent uses a bash script to build up the response and response is in given format:

{#PARAM_NAME}: "ROOT_PARTITION"
{#PARAM_1}: "/"
{#PARAM_2}: "1G"
{#PARAM_3}: "1"
{#PARAM_4}: "1"
{#PARAM_5}: "3600"

So the format generally looks like:

PARAMETER_NAME:PARAM_1^PARAM_2

We can add multiple parameters by concatenating them with plus sign like:

PARAMETER_NAME:PARAM_1^PARAM_2+OTHER_PARAM:PARAM_1^PARAM_2

Drawbacks

It is still LLD. Trigger dependencies are hard, and items are discovered with given frequency. If it would be built in zabbix it could be generated automatically by server (without need zabbix-agent to respond to this query).

Expectations

I would like you to think about this as a new feature. I am not sure how it could be build into zabbix, don't want to suggest anything, because my way of thinking about it may be wrong. Do you have any suggestions, propositions or comments for this feature? It gives a lot of flexibility for Zabbix.

Attachements

userparameter_itemdiscovery.conf
UserParameter=custom.itemdiscovery[*],/etc/zabbix/scripts/itemdiscovery.sh $1
itemdiscovery.sh

#!/bin/bash


## CHECK IF ARGS
if [ $# -ne 1 ]; then
  echo "Not enough parameters"
  exit 1
fi

IN=$1

in_arr=$(echo -ne $IN | tr "+" "\n")

first=0

echo -ne "{\n"
echo -ne "\t\"data\":["

for x in $in_arr; do
  IFS=":" x_arr=($x)
  
  name=${x_arr[0]}
  params=${x_arr[1]}

  if [ $first -ne 0 ]; then
    echo -ne ",\n"
    echo -e "\t{"
  else
    echo -e "{"
  fi
  first=1

  echo -ne "\t\t\"{#PARAM_NAME}\":"
  echo -n  "\"$name\""
  i=0
  for param in $(echo $params | tr "^" ":"); do
    i=$((i+1))
    echo ","
    echo -ne "\t\t\"{#PARAM_$i}\":"
    echo -n "\"$param\""
  done
  echo ""
  echo -ne "\t}"
done

echo -ne "]\n"
echo -ne "}\n"

Please ask if something is unclear.



 Comments   
Comment by richlv [ 2016 Oct 20 ]

feature requests are in general expected to ask for a specific thing. could you please clarify what would be the exact functional need here ?

Comment by Radek Lisowski [ 2016 Oct 24 ]

I will try in next few days to create an example how I would see that implemented.

Generated at Sat Apr 27 08:20:54 EEST 2024 using Jira 9.12.4#9120004-sha1:625303b708afdb767e17cb2838290c41888e9ff0.