Forum

Zabbix 5 (FreeBSD),...
 
Notifications
Clear all

Zabbix 5 (FreeBSD), MySQL template

1 Posty
1 Users
0 Reactions
410 Widok
0
Topic starter

and how to fix EXECUTE_STR() command:' mysql -h"" -P"" -sNX -e "show global status"' len:20 cmd_result:'sh: mysql: not found'

and other errors related to XML/JSON parsing

1 Answer
0
Topic starter

related zabbix 5 MySQL template files (not working) (I show the way to the solution, not the solution itself)

https://git.zabbix.com/projects/ZBX/repos/zabbix/browse/templates/db/mysql_agent2


1. Import template from above url into zabbix

2. edit /etc/rc.conf and add line (MySQL fix)

zabbix_agentd_paths="/usr/local/bin"

3. create request template for zabbix inside "/usr/local/etc/zabbix5/zabbix_agentd.conf.d" called template_db_mysql.conf

UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], python /usr/local/etc/zabbix5/zabbix_agentd.conf.d/mysqltojson.py
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT COALESCE(SUM(DATA_LENGTH + INDEX_LENGTH),0) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHE>
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h localhost  -P 3306 -sNX -e "show slave status"

4. create python parser file "SHOW GLOBAL STATUS" thath conferts output into json style. create file /usr/local/etc/zabbix5/zabbix_agentd.conf.d/mysqltojson.py

import MySQLdb
import json

conn = MySQLdb.connect(host = "localhost",user="__MY_USER__",password="__MY_PASSWORD__")

cursor = conn.cursor()
cursor.execute("SHOW GLOBAL STATUS")

rs = cursor.fetchall()
result = dict(rs)
print (json.dumps(result))

4.1 (install pip,  pkg install py39-pip and pip install mysqlclient)

4.2 (this is not ideal way for handling authentication for mysql user)

5. service zabbix_agentd restart

 

try now

Odpowiedź

Author Name

Author Email

Your question *

 
Preview 0 Revisions Saved
Share: