Zabbix6.2: Monitor MySQL/MSSQL/Apache/Docker, custom monitoring items, SNMP Trap, scheduled reports, macros, ODBC connection database and other configuration methods

  • ZABBIX SNMP custom monitoring items

  1. Query the MIB reference provided by the device manufacturer or use MIB Brower to obtain the oid of the monitoring item
  2. Use snmpwalk to determine whether the snmp agent configuration is correct (this command can view multiple data items under a certain oid index)
  3. Obtain the data of a specific oid through snmpget (this command can only view one oid value) (sometimes it is necessary to add an oid index on the basis of snmpwalk), and record the oid
  4. Create the corresponding item on zabbix, select the device snmp interface for interface, the Key can be optional, and enter oid for SNMP OID. Note: The oid filled in ZABBIX must have a value that can be obtained using snmpget.

  • Using macros in topology map labels

ZABBIX6 version macro format: {?avg(/host/key,1h)}

For example:

DOWN:{?last(/USG6555E/net.if.out[ifHCOutOctets.5])}

UP: {?last(/USG6555E/net.if.in[ifHCInOctets.5])}

  • zabbix agent custom monitoring script

1. Modify the zabbix agent configuration file and add user parameters

#agentconfiguration file

vim /usr/local/zabbix/etc/zabbix_agentd.conf

#agent2configuration file

vim /etc/zabbix/zabbix_agent2.conf

#search

/UserParameter

#User parameter example

#CPU temperature (requires yum install lm_sensors)

UserParameter=get_temp_cpu[*],sensors|grep "Package id $1"|cut -c 17-20

#Power supply (requires yum install lm_sensors)

UserParameter=get_power,sensors|grep "power1: $1"|cut -c 14-19

#Execute python script

UserParameter=get_usg_log,sudo python /home/cgyxt/workspace/code/xtmonitor/usgtest.py

#Configure the parameters in the key value

UserParameter=cus.metrics[*],/etc/zabbix/scripts/ngx-status.sh $1

Note: When there are many user parameters, you can include in the agent main configuration file to reference the external user-defined configuration file, and put the UserParameter in the custom configuration file:

#Create /usr/local/etc/zabbix_agent2.userparams.conf and put UserParameter in it

#/etc/zabbix/zabbix_agent2.conf中:Include=/usr/local/etc/zabbix_agent2.userparams.conf

2. Restart zabbix agent

systemctl restart zabbix-agent2

3. Add monitoring items to the corresponding zabbix agent host in zabbix, and the key values ​​must be consistent with the agent configuration file.

Note: Solution to script execution timeout:
modify the configuration files of zabbix server and agent and set Timeout=30

#View configuration file information and filter out comment lines

egrep -v '^#|^$' /etc/zabbix/zabbix_agent2.conf

  • Use zabbix_get to directly obtain monitoring item values ​​in bash

zabbix_get -s 127.0.0.1 -p 10050 -k "vm.memory.size[pavailable]"

#If environment variables are not added or yum is not used to install zabbix_get,

/usr/local/zabbix/bin/zabbix_get -s 127.0.0.1 -p 10050 -k "vm.memory.size[pavailable]"

  • zabbix agent monitors docker

1.#Add zabbix user to the docker group and obtain docker monitoring permissions

usermod -aG docker zabbix

#View and verify that the zabbix user belongs to the group

[root@cgy ~]# groups zabbix

zabbix : zabbix docker

#test

zabbix_get -s 127.0.0.1  -k docker.info

2. Reference the docker by zabbix agent2 template in the host

  • zabbix agent monitors apache

1. Open the server-status monitoring interface of Apache and only allow local access.

vim /etc/httpd/conf/httpd.conf

<Location /server-status>

         SetHandler server-status

         Allow from 127.0.0.1

         Order allow,deny

</Location>

ExtendedStatus On

2. Reference the Apache by Zabbix agent template in the host. If the port does not use the default 80, modify {$APACHE.STATUS.PORT} in "Inheritance and Host Macros" in the host configuration.

  • zabbix agent monitors mysql

1. Log in to the mysql to be monitored and create a monitoring user

mysql -uroot -p

use mysql;

CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '<password>';

GRANT SELECT REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%';

2. Reference the mysql by zabbix agent2 template in the host. When referencing, modify the "inheritance and host macro" in the host configuration:

{$MYSQL.DSN}:127.0.0.1

{$MYSQL.PASSWORD}: database password

{$MYSQL.USER}: database user, fill in the zbx_monitor just created

  • Modify Web platform name

vim /var/www/html/zabbix/conf/zabbix.conf.php

$ZBX_SERVER_NAME                = 'newName';

  • zabbix connects to MSSQL through ODBC

#Install dependencies (ignored if installed)

yum -y install unixODBC unixODBC-devel   #安装ODBC

yum -y install freetds #Install freetds driver for connecting to MSSQL

#View ODBC configuration file location

odbcinst -j

Note: odbcinst.ini  is used to define the installed ODBC database driver; odbc.ini  is used to define the data source

#Add SQL Server driver FreeTDS in /etc/odbcinst.ini

vim /etc/odbcinst.ini

[FreeTDS]

Description = ODBC for SQL Server

Driver = /usr/lib64/libtdsodbc.so.0

Setup = /usr/lib64/libtdsS.so

FileUsage = 1

#View configured drivers

odbcinst -q -d

#Configure odbc connection information and add data source

vim /etc/odbc.ini

[mssql] #DSN name

Driver = FreeTDS #Driver name

Server = 10.16.0.16 #sql server host ip

Port = 1433

Database = datebasename # Monitored sqlserver database

TDS_Version = 8.0

#Check data source

odbcinst -q -s

#Create a user on the monitored SQL Server server and authorize it.

#Connect to database test on Zabbix

isql -v mssql database username and password

#Configuration is complete, you can monitor it through the ODBC template or add "database monitoring" monitoring items

(1)Monitoring through templates

(2) Query data through monitoring items

Select the host->Add monitoring item->Configure key value (there are three modes available here: select, get, discovery, choose according to your own needs. Name the key value for the first parameter, fill in the DSN name for the second parameter, and fill in the DSN name for the third parameter. Parameters can be left blank) -> Write the corresponding SQL statement in the SQL query.

  • ODBC connection to MySQL

#Install dependencies (ignored if installed)

yum -y install unixODBC unixODBC-devel   #安装ODBC

yum -y install mysql-connector-odbc #Install the mysql-connector driver for connecting to MySQL

#Add driver to ODBC configuration file

vim /etc/odbcinst.ini

According to the installed MySQL driver version, change libmyodbc5.so in the built-in MySQL driver to libmyodbc8a.so

(You can also use the built-in [MySQL ODBC 8.0 Unicode Driver] or [MySQL ODBC 8.0 ANSI Driver] driver without modifying the file.

[MySQL]

Description=ODBC for MySQL

Driver=/usr/lib/libmyodbc8a.so

Setup=/usr/lib/libodbcmyS.so

Driver64=/usr/lib64/libmyodbc8a.so

Setup64=/usr/lib64/libodbcmyS.so

FileUsage=1

#Add data source

vim /etc/odbc.ini

[my_Syslog]

Description     = Data source MySQL

Driver          = MySQL

Server          = 127.0.0.1

Host            = 127.0.0.1

Database        = Syslog

Port            = 3306

User            = zbx_monior

Password        =  <password>

CHARSET         = UTF8

#Connect to database test on Zabbix

isql -v my_Syslog database username and password

Note: The password has been configured in the data source, you can connect directly with the DSN name: isql -v my_Syslog

  • Use SNMP Trap to proactively report device alarms

#Install dependencies

yum install -y net-snmp net-snmp-libs net-snmp-utils net-snmp-perl mrtg snmptt

Method 1: Use the Perl script that comes with zabbix to receive SNMP Trap

#Copy the Perl script in the source directory and grant execution permissions

find / -name zabbix_trap_receiver.pl

cp /home/cgyxt/workspace/zabbix/zabbix-6.2.6/misc/snmptrap/zabbix_trap_receiver.pl /usr/bin

chmod a+x /usr/bin/zabbix_trap_receiver.pl

#Modify snmptrapd configuration file

find / -name snmptrapd.conf

vim /etc/snmp/snmptrapd.conf

authCommunity log,execute,net <snmp community name>

perl do "/usr/bin/zabbix_trap_receiver.pl"

#Modify Zabbix-server configuration file

vim /usr/local/zabbix/etc/zabbix_server.conf

StartSNMPTrapper=1 #Enable SNMPTrapper function

SNMPTrapperFile=/tmp/zabbix_traps.tmp #Specify the log file obtained by trap. The path must be the same as the path set in the zabbix_trap_receiver.pl script.

#Start service

systemctl enable snmptrapd

systemctl start snmptrapd

systemctl restart zabbix-server

#Open UDP162 port on the firewall, configure SNMP Trap type monitoring items on Zabbix

Method 2: Use snmptt to receive SNMP Trap

#Modify snmptrapd configuration file

vim /etc/snmp/snmptrapd.conf

authCommunity log,execute,net <snmp community name>

traphandle default /usr/sbin/snmptthandler

#snmptt.ini configuration modification

[root@Server ~]# vim /etc/snmp/snmptt.ini

date_time_format= %Y/%m/%d %H:%M:%S #Configure snmptt log time format 

mode = daemon #nmptt running mode

net_snmp_perl_enable = 1

translate_log_trap_oid = 2 #0: Display numeric OID, 1: Display OID name, 2: Display OID module name and its name

log_file = /var/log/snmptt/snmptt.log #Specify the transferred log file

snmptt_conf_files = <<END

/etc/snmp/snmptt.conf #Default formatted log configuration file

/etc/snmp/cisco.conf #Add other formatted trap log configuration files

END

#Modify snmptt configuration file and customize snmptrap formatting rules

vim /etc/snmp/snmptt.conf

#Default rule, when no other rules match, all trap information will be processed according to this rule

EVENT general .* "General event" Normal

FORMAT ZBXTRAP $aA $1

#Modify Zabbix-server configuration file

vim /usr/local/zabbix/etc/zabbix_server.conf

StartSNMPTrapper=1 #Enable SNMPTrapper function

SNMPTrapperFile=/var/log/snmptt/snmptt.log #Specify the log file obtained by trap

SNMPTrapFile file creation

touch /var/log/snmptt/snmptt.log

chown snmptt:snmptt /var/log/snmptt/snmptt.log

#Start service

systemctl enable snmptrapd

systemctl start snmptrapd

systemctl enable snmptt.service

systemctl start snmptt.service

systemctl restart zabbix-server

#Open UDP port 162 on the firewall, configure SNMP Trap type monitoring items on Zabbix

  • Use Zabbix to schedule reports and send dashboard PDF to email regularly

#Modify zabbix server configuration file

StartReportWriters=1

WebServiceURL=http://localhost:10053/report

#Start zabbix_web_service (temporary start)

zabbix_web_service -c /usr/local/zabbix/etc/zabbix_web_service.conf

#Create a guard file (for self-starting at boot)

vim /lib/systemd/system/zabbix-web-service.service

[Unit]

Description=Zabbix Web Service

After=syslog.target

After=network.target

[Service]

Environment="CONFFILE=/usr/local/zabbix/etc/zabbix_web_service.conf"

#EnvironmentFile=-/usr/local/zabbix/sbin/zabbix_web_service

Type=forking

Restart=on-failure

PIDFile=/tmp/zabbix_web_service.pid

KillMode=control-group

ExecStart=/usr/local/zabbix/sbin/zabbix_web_service -c $CONFFILE

ExecStop=/bin/kill -SIGTERM $MAINPID

RestartSec=10s

[Install]

WantedBy=multi-user.target

chmod 754 /lib/systemd/system/zabbix-web-service.service

#Start service

systemctl start zabbix-web-service.service

systemctl enable zabbix-web-service.service

#Create and test the planned report in Web page report > planned report

Guess you like

Origin blog.csdn.net/N71FS1/article/details/130049362