zabbix_agent
was installed on the nodes, user parameters were configured, templates were made, the data was successfully transferred to Zabbix. For the second system - Cacti, the script found somewhere that zabbix_get
data zabbix_get
and used Data Queries was zabbix_get
. But something in this script soon broke down and Zabbix was left as the only working solution.fping
polling results from the servers under control, where the remote node is specified as a parameter, for example, ya.ru
or habrahabr.ru
. And the answer is the values of delays and losses. Accordingly, we can ping many other nodes from each server. The list of nodes should receive automatically.name
and description
- what is it and what is it intended for in order not to get confused: <name>Get fping stats</name> <description>Remote monitoring fping statistics</description>
<script_path>
- full path to the script file, you can use the variable |path_cacti|
: <script_path>|path_cacti|/scripts/query-fping-stat.sh</script_path>
<arg_index>
, <arg_num_indexes>
, <arg_query>
, <arg_get>
- the values of the parameters passed to the script, which determine its mode of operation and what values it returns. Only four modes, we do not invent anything complicated: <arg_index>index</arg_index> <arg_num_indexes>num_indexes</arg_num_indexes> <arg_query>query</arg_query> <arg_get>get</arg_get>
<arg_prepend>
- parameters that will be transferred first in the script command line. No other parameters will be automatically transferred to the script, except for those that determine its mode of operation, that is, we do not know for which server we perform our actions. Required additional arguments are defined here. It is also allowed to use variables : <arg_prepend>|host_hostname|</arg_prepend>
<output_delimeter>
- the delimiter character in the returned values. Nothing too convoluted - use a colon: <output_delimeter>:</output_delimeter>
|query__|
that can be used in graph labels and their values will be displayed in the general list of elements when you call Create Graphs for this Host as separate columns.name
- name, query_name
- the value that will be passed to the script and direction
- type is Input or Output .|query_host|
: <host> <name>host</name> <direction>input</direction> <query_name>host</query_name> </host>
<avg> <name>avg</name> <direction>output</direction> <query_name>avg</query_name> </avg> <max> <name>max</name> <direction>output</direction> <query_name>max</query_name> </max> <min> <name>min</name> <direction>output</direction> <query_name>min</query_name> </min> <loss> <name>loss</name> <direction>output</direction> <query_name>loss</query_name> </loss>
<interface> <name>Get fping stats</name> <description>Remote monitoring fping statistics</description> <script_path>|path_cacti|/scripts/query-fping-stat.sh</script_path> <arg_index>index</arg_index> <arg_query>query</arg_query> <arg_get>get</arg_get> <arg_num_indexes>num_indexes</arg_num_indexes> <arg_prepend>|host_hostname|</arg_prepend> <output_delimeter>:</output_delimeter> <fields> <host> <name>host</name> <direction>input</direction> <query_name>host</query_name> </host> <avg> <name>avg</name> <direction>output</direction> <query_name>avg</query_name> </avg> <max> <name>max</name> <direction>output</direction> <query_name>max</query_name> </max> <min> <name>min</name> <direction>output</direction> <query_name>min</query_name> </min> <loss> <name>loss</name> <direction>output</direction> <query_name>loss</query_name> </loss> </fields> </interface>
<script_path> <arg_prepend> <arg_index>
|host_hostname|
remind you, is specified in the template as |host_hostname|
: hosts="ya.ru habrahabr.ru" zabbix="/usr/local/bin/zabbix_get -s $1" case $2 in index) for host in $hosts; do echo $host; done ;; esac
<script_path> <arg_prepend> <arg_num_indexes>
numhosts=`echo $hosts | wc -w` case $2 in num_indexes) echo $numhosts ;; esac
<script_path> <arg_prepend> <arg_query> <query_name>
index output_delimeter <>
for each index and the specified data field, each with a new row. Since only one value is defined in the template, and our index is easily readable, so we use it as a result: case $2 in query) for host in $hosts do case $3 in host) echo $host:$host ;; esac done ;; esac
<script_path> <arg_prepend> <arg_get> <query_name>
Called for all data fields defined as Output . The output should be<>
for the specified field and index. What is simpler than in Data Input , where you need to output values in a formatted string, everything here is already defined in the template:
zabbix="/usr/local/bin/zabbix_get -s $1" get_ping () { res=`$zabbix -k ping[$1,$2]` if [ -z $res ] then res=-1 fi echo $res } case $2 in get) echo $(get_ping $4 $3) ;; esac
All code
#!/bin/sh hosts="ya.ru habrahabr.ru" numhosts=`echo $hosts | wc -w` zabbix="/usr/local/bin/zabbix_get -s $1" get_ping () { res=`$zabbix -k ping[$1,$2]` if [ -z $res ] then res=-1 fi echo $res } case $2 in index) for host in $hosts; do echo $host; done ;; num_indexes) echo $numhosts ;; query) for host in $hosts do case $3 in host) echo $host:$host ;; esac done ;; get) echo $(get_ping $4 $3) ;; esac exit 0
It remains to check - create Data Queries bind it to the site and perform a debug launch of Verbose Query .
Template without errors:
+ Found data query XML file at '/usr/local/cacti/resource/script_queries/fping-stat.xml' + XML file parsed ok.
Num_indexes mode, number of elements:
+ Executing script for num of indexes '/usr/local/cacti/scripts/query-fping-stat.sh server num_indexes' + Found number of indexes: 2
Index mode, a list of all items:
+ Executing script for list of indexes '/usr/local/cacti/scripts/query-fping-stat.sh server index' Index Count: 2 + Found index: ya.ru + Found index: habrahabr.ru
Query mode, Output values of all arguments for all elements:
+ Executing script query '/usr/local/cacti/scripts/query-fping-stat.sh server query host' + Found item [host='ya.ru'] index: ya.ru + Found item [host='habrahabr.ru'] index: habrahabr.ru
If everything works, then we act as always in Cacti, create a data template, graph templates . We connect together , it should be done directly in the created Data Queries . After that, we should get a list of available parameters automatically when using Create Graphs for this Host .
Now we create a graph, then a script call is added to Poller for each Input argument, each index and each node. When viewing the Poller Cache you can see, among other things, with what parameters the script is called:
Script: /usr/local/cacti/scripts/query-fping-stat.sh server get avg ya.ru
This means that you can enjoy the almost automatic addition of new graphs, and the sysadmin to continue to do more important things.PS Did you fix what was broken?When the text was completely ready, looking at the graphics, I realized that even a pretty altered last year's version does not fix the problem. On many other graphs that use standard Data Queries Script , some time after re-introducing the solution described, data is not removed and displayed several times a day. Perhaps a feature of the used infrastructure, or configuration errors. In any case, this does not cancel the convenience of the Data Queries , but the reason ...: “We will search” (c)
Source: https://habr.com/ru/post/211254/
All Articles