Created
April 7, 2019 20:27
-
-
Save ilyaevseev/b34927a5bd83a31c445a70906d3082ab to your computer and use it in GitHub Desktop.
Zabbix report wrong items, should be called from cron.daily
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
MAILTO="" # ..put here your email, empty = mail skipped | |
DIR="/var/log/zabbix-wrong-items" | |
LOG="$DIR/$(date +%Y-%m-%d).log" | |
mkdir -p "$DIR" | |
# MySQL under Debian/Ubuntu: | |
# mysql --defaults-file=/etc/mysql/debian.cnf -Bse '...' zabbix | |
sudo -u postgres -H env LANG=C psql -c " | |
SELECT h.name AS hostname, i.name AS itemname, i.key_, i.error | |
FROM hosts AS h JOIN items AS i | |
ON h.hostid = i.hostid | |
WHERE i.error<>'' AND i.status = 0 | |
ORDER BY h.name, i.key_" \ | |
zabbix > "$LOG" | |
# Disabled items: | |
# SELECT h.name AS hostname, i.name AS itemname, i.key_ FROM hosts AS h JOIN items AS i ON h.hostid = i.hostid WHERE i.state > 0 ORDER BY h.name, i.key_; | |
test "$MAILTO" = "" || | |
grep -q '^(0 rows)$' "$LOG" || | |
mail -E -s "Zabbix wrong items on $(hostname -f)" $MAILTO < "$LOG" | |
find "$DIR/" -type f -mtime +99 -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment