Zabbix custom user key and parameter userparameters monitor script output

Source: Internet
Author: User

Zabbix pre-defined some key in the template, but the usual situation does not meet our needs. Fortunately, Zabbix provides a way to customize the key, so we have the flexibility to monitor the various data we want to monitor. Defining a configuration file

The zabbix-agent configuration file path installed through Yum is/etc/zabbix/zabbix_agentd.conf.
Around 255 lines of this file, we can find the following code:

1 Include=/etc/Zabbix/zabbix_agentd. D/

Our custom configuration can be put into this directory.
We can create a custom file to define the key we need:

1 Vim /etc/Zabbix/zabbix_agent. D/userparameter_script. conf

This content is added to the file:

1234 # This file monitors custom script output values # format is userparameter=<key>,<command> userparameter=script. Date,date

Restart zabbix-agent after saving.

Test gets the value of the custom key

Use the Zabbix_get tool on Zabbix-server to get the custom values.

12 shell> zabbix_get -s 100.10.1.2 - k script.date fri apr 24 14:41:18 cst 2015

Gets the result of executing date in the example above, stating that the configuration was successful.

Create a script

Start by creating a new script directory to hold our scripts and name the script kucun.sh, and I'll use Zabbix to monitor the inventory tables in the database and use inventory data to paint.

12 mkdir -p /etc/< Span class= "crayon-v" >zabbix/script/ vim< Span class= "crayon-h" > /etc/ zabbix/script/< Span class= "crayon-v" >kucun.sh

We define the script and enter a store number to check the number of items in this store that are less than N.
If you execute the query manually, the query is as follows:

12 Shell> /etc/Zabbix/script/kucun. Sh bj001 - 2

An output of 2 means that there are 2 items with a quantity less than 30.
Here's what the script says:

12345678 #!/bin/bashshop_id=$1 number=$2 dbhost="100.10.1.2" dbuser="Monitor" dbpasswd="+" SQL="SELECT COUNT (*) from lsp_cus.menu WHERE shop_no = \" $shop _id\ "and date = Unix_timestamp (Date_format ( Now (), '%y-%m-%d ')) and Num-sale < \ "\" " MySQL -h$dbhost -u$dbuser -p$dbpasswd -Ne "$sql"

Create a key using the results of a script query

Re-edit

1 Vim /etc/Zabbix/zabbix_agent. D/userparameter_script. conf

File modified to:

123 # this file monitors custom script output values # format userparameter=<key>,<command> userparameter=script .kucun[*],/etc/ zabbix/script/< Span class= "crayon-v" >kucun.sh $1 $2

Query by Zabbix-server

Use the Zabbix_get tool on the Zabbix server to query store number 001, inventory less than 30 of the number of items.

12 Shell> zabbix_get -s 100.10.1.2 -k script. Kucun[001,+] -

Can see the success.

Some explanations for the methods used above

Userparameter=key[*],command
Key is a unique value, and [*] represents the parameter.
command is to execute commands or scripts, Key's [*] inside the parameter one by one corresponds to $9, altogether 9 parameters. $ A represents a script command. The maximum returned result data is 512KB.
The parameter prohibits the use of the following characters: \ ' "' *? [ ] { } ~ $ ! &; () <> | # @

Command-line arguments for scripts can be searched by search engines for related articles.

Transfer from http://www.qiansw.com/zabbix-user-parameters-key-script.html

Some pits------

If you have a problem, check/var/log/zabbix first.

Permissions Issue Configuration

$vi/etc/zabbix/zabbix_agentd.conf Allowroot Properties

Failed to start after modification $setenforce 0 turn off SELinux

$/etc/selinux/config selinux=disabled

Zabbix custom user key and parameter userparameters monitor script output

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.