Skip to content
Snippets Groups Projects
Verified Commit 3ecd239f authored by Florian Pritz's avatar Florian Pritz
Browse files

zabbix/mysql-userstats: Switch to handling each user on their own


Otherwise discovery rules don't seem to work for dependent items.

Signed-off-by: default avatarFlorian Pritz <bluewind@xinu.at>
parent 3bd07309
No related branches found
No related tags found
No related merge requests found
......@@ -5,8 +5,31 @@ use warnings;
use DBI;
use JSON;
my $config = $ARGV[0] // "$ENV{HOME}/.my.cnf";
my $config = $ARGV[0];
my $mode = $ARGV[1];
my $user = $ARGV[2];
if (!($mode eq "userstat" or $mode eq "discover")) {
print STDERR "mode is not userstat or discover\n";
die;
}
if ($mode eq "userstat" and not defined $user) {
print STDERR "userstat requires user to be defined\n";
die;
}
my $db = DBI->connect("DBI:mysql:mysql_read_default_file=$config");
$db->{FetchHashKeyName} = "NAME_lc";
print encode_json({user => $db->selectall_hashref("select * from information_schema.user_statistics", "user")});
if ($mode eq "userstat") {
$db->{FetchHashKeyName} = "NAME_lc";
print encode_json($db->selectrow_hashref("select * from information_schema.user_statistics where user = ?", undef, $user));
} elsif ($mode eq "discover") {
print encode_json({
data=> [
$db->selectall_arrayref("select user '#USERNAME' from information_schema.user_statistics", {Slice=>{}})
]
});
} else {
die "unhandeled mode";
}
......@@ -12,7 +12,8 @@ TLSPSKFile=/etc/zabbix/zabbix_agentd.psk
UserParameter=mysql.ping,mysqladmin --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" ping|grep alive|wc -l
UserParameter=mysql.version,mysql --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" -V
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | mysql --defaults-file="/etc/zabbix/zabbix_agentd.my.cnf" -N | awk '{print $$2}'
UserParameter=mysql.userstats,/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf"
UserParameter=mysql.userstats[*],/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" userstat '$1'
UserParameter=mysql.userstats_discover,/usr/local/bin/mysql-user-stats.pl "/etc/zabbix/zabbix_agentd.my.cnf" discover
UserParameter=systemd.unit.is-active[*],systemctl is-active --quiet '$1' && echo 1 || echo 0
UserParameter=systemd.unit.is-failed[*],systemctl is-failed --quiet '$1' && echo 1 || echo 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment