The Zabbix macro is an abstraction (abstraction) that replaces a set of text patterns according to a set of predefined rules, which are automatically replaced by the interpreter or compiler when it encounters a macro.
Zabbix saves the preset text pattern based on a macro, and replaces it with the text in it when it is called;
Zabbix has many built-in macros, such as {host.name}, {HOST. IP}, {TRIGGER. DESCRIPTION}, {trigger.name},
{TRIGGER. EVENTS. ACK}, etc.
Zabbix for greater flexibility, Zabbix also supports the use of user-defined macros at the Global, template, or host level;
User-defined macros use the special syntax format "{$MACRO}", which can be applied to information on the item keys and descriptions, trigger names and expressions, host interface Ip/dns and ports, and the SNMP protocol of the discovery mechanism. Macro names can only use uppercase letters, numbers, and underscores
ZABBIX macro Substitution Order: first, host-level macros, followed by macros in the current host-level template (directly linked to the host template), multiple-level templates sorted by their ID number, followed by a macro in level two templates, and so on; Finally, the global macro is checked. Zabbix if the macro used by a host definition cannot be found, it will not be replaced. To use user-defined macros, there are two ways to do this:
--Global macro: "Administrator-->general-->macros"
--Host or template-level macros: Edit the appropriate host or template properties to
Macros Use Example:
--Define a macro named {$NETINLIMIT} at the host level to define a reasonable number of inbound traffic accepted by the current host:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/89/57/wKioL1gQWaOx_z7DAAB8q0wxARs850.png "title=" Create a macro. png "alt=" Wkiol1gqwaox_z7daab8q0wxars850.png "/>
Then use this macro in the triggers of the host:
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/89/57/wKioL1gQWhWgdQ3nAACytOpURo8666.png "title=" Use the macro. png "alt=" Wkiol1gqwhwgdq3naacytopuro8666.png "/>
User-definable monitoring:
Why to customize key:
Sometimes we want to let the monitored side perform a zabbix without predefined detection, Zabbix's user-defined parameters feature provides this method. We can configure userparameter in the client config file zabbix_angentd.conf.
The syntax is as follows:
Userparameter=key,command
User-defined parameters contain a key and a command, the key must be the entire system unique, configured well, restart the client. Then configure the item and fill in the key's location with our custom key.
The script specified in the user-defined parameter is executed by the Zabbix agent, which can return up to 512KB of data.
User-defined Key instance:
Examples of commands for simple points:
Userparameter=ping,echo 1 If you call ping this key, you will receive a return value of 1.
Examples of more complex commands:
Userparameter=mysql.ping,mysqladmin-uroot Ping|grep-c Alive If return 1 means MySQL is running, if return 0 means MySQL hangs
Flexible and customizable key:
The following are flexible user-defined parameters:
Userparameter=key[*],command
Parameters |
description |
key |
the only. [*] indicates that multiple parameters can be passed inside |
command |
The script that needs to be executed, Key's [] inside parameter one by one corresponds to $9, altogether 9 parameters. $ A represents a script command. |
Precautions
1, if you need to use the command line inside of this variable, then you want to use two $$2, such as awk ' {print $$2} ', have encountered this problem before, constantly testing their script output is normal, but Zabbix can not get the data, it is here. In order to prevent and parameter conflict, so Zabbix made this rule.
2, Zabbix prohibit the use of some unsafe parameters, as follows:
\ ' "' *? [ ] { } ~ $ ! &; () < > | # @
3, starting from Zabbix 2.0, Zabbix return text data can be a space.
Example (1): Get the amount of memory space
(1) Configure the monitored End Agent configuration file as follows:
# vim/etc/zabbix/zabbix_agentd.conf Userparameter=memory.free,/usr/bin/free |awk '/^Mem:/{print $4} '
Restart Monitored agent service
# Service Zabbix-agent Restart
(2) The server uses the Shell method to obtain the monitored side of the custom monitoring item data
# zabbix_get-s 172.16.100.4-k "Memory.free" 297712
(3) added as monitored object
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/89/6D/wKiom1gSpHOBDIAEAADog5RD0rY543.png "title=" Memoryfree.png "alt=" Wkiom1gsphobdiaeaadog5rd0ry543.png "/>
Example (2): Custom key passes multiple parameters: monitor host memory information
(1) Configure the monitored End Agent configuration file as follows:
# vim/etc/zabbix/zabbix_agentd.conf Userparameter=memory.usage[*],/bin/cat/proc/meminfo | awk '/^$1:/{print $$2} '
Restart Monitored agent service
# Service Zabbix-agent Restart
(2) The server uses the Shell method to obtain the monitored side of the custom monitoring item data
# zabbix_get-s 172.16.100.4-k "Memory.usage[buffers" "55980# zabbix_get-s 172.16.100.4-k" Memory.usage[MemTotal] " 494224
(3) added as monitored object
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/6C/wKioL1gSxwPjlCVNAADp3StIY_c107.png "style=" float: none; "title=" Memoryfree1.png "alt=" Wkiol1gsxwpjlcvnaadp3stiy_c107.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/89/6E/wKiom1gSxwPBqV1kAADpzeBLLRg571.png "style=" float: none; "title=" Memoryfree2.png "alt=" Wkiom1gsxwpbqv1kaadpzebllrg571.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/89/6C/wKioL1gSxwOx1LMnAADrWiR0_JY115.png "style=" float: none; "title=" Memoryfree3.png "alt=" Wkiol1gsxwox1lmnaadrwir0_jy115.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/6E/wKiom1gSxwTQvc6jAADsVGSPGEA238.png "style=" float: none; "title=" Memoryfree4.png "alt=" Wkiom1gsxwtqvc6jaadsvgspgea238.png "/>
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/89/6C/wKioL1gSx8rys60JAAD0swjhxy0036.png "title=" Memoryfree5.png "alt=" Wkiol1gsx8rys60jaad0swjhxy0036.png "/>
Example: Using custom monitoring Nginx service
(1) The monitored End nginx service opens status
# vim/etc/nginx/conf.d/default.conf Location/status {stub_status on; Access_log off; Allow 172.16.0.0/16; Deny all; }
Restart Nginx Service test:
# service Nginx restart# Curl http://172.16.100.4/statusActive connections:1 Server accepts handled requests 2 2 2 Readin g:0 writing:1 waiting:0
(2) Configure the monitored End Agent configuration file as follows:
# vim /etc/zabbix/zabbix_agentd.d/nginx.confuserparameter=nginx.active[*],/usr/bin/curl -s "Http://$1:$2/status" | awk '/^active/ {print $NF} ' userparameter=nginx.reading[ *],/usr/bin/curl -s "Http://$1:$2/status" | grep ' Reading ' | cut -d " " -f2UserParameter=Nginx.writing[*],/usr/bin/curl -s " Http://$1:$2/status | grep ' Writing ' | cut -d -f4UserParameter=Nginx.waiting[*],/usr/bin/curl -s "Http://$1:$2/status" | grep ' Waiting ' | cut -d " " - f6userparameter=nginx.accepted[*],/usr/bin/curl -s "Http://$1:$2/status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$1} ' userparameter=nginx.handled[*],/usr/ bin/curl -s "Http://$1:$2/status" | awk '/^[ \t]+[0-9]+[ \t]+[0-9]+[ \ T]+[0-9]+/ {print $$2} ' userparameter=nginx.requests[*],/usr/bin/curl -s ' Http://$1:$2/status | awk '/^[ &NBSP;\T]+[0-9]+[&NBSP;\T]+[0-9]+[&NBSP;\T]+[0-9]+/&NBSP;{PRINT&NBSP;$$3} '
Restart Monitored agent service
# Service Zabbix-agent Restart
(3) The server uses the Shell method to obtain the monitored side of the custom monitoring item data
# zabbix_get-s 172.16.100.4-k "nginx.accepted[172.16.100.4,80]" 9# ab-n 1000-c [zabbix_get-s 172.16.100.4-k] Ngi NX.ACCEPTED[172.16.100.4,80] "1013
(4) added as monitored object
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M02/89/6E/wKioL1gS_9_T7bnEAADg5p1_FLU808.png "style=" float: none; "title=" Nginx001.png "alt=" Wkiol1gs_9_t7bneaadg5p1_flu808.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/89/70/wKiom1gS_9_AFKAIAADTMWIOTR4006.png "style=" float: none; "title=" Nginx002.png "alt=" Wkiom1gs_9_afkaiaadtmwiotr4006.png "/>
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/89/6E/wKioL1gS_9_QBs4bAADXHY2yySY612.png "style=" float: none; "title=" Nginx003.png "alt=" Wkiol1gs_9_qbs4baadxhy2yysy612.png "/>
650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M02/89/70/wKiom1gS_-DwiJ3BAAC438n-FQA216.png "style=" float: none; "title=" Nginx004.png "alt=" Wkiom1gs_-dwij3baac438n-fqa216.png "/>
Above Zabbix macro and Zabbix user custom monitoring.
This article is from the "Opensamlee" blog, make sure to keep this source http://gzsamlee.blog.51cto.com/9976612/1866779
ZABBIX macro usage and user-defined monitoring of automated operation and maintenance tools (iii)