Skip to content

Instantly share code, notes, and snippets.

@taka3110
Last active July 16, 2019 07:05
Show Gist options
  • Save taka3110/0098a027f23dd8ba01e1603e07ca9081 to your computer and use it in GitHub Desktop.
Save taka3110/0098a027f23dd8ba01e1603e07ca9081 to your computer and use it in GitHub Desktop.
Script to notify when a large number of alerts are detected
#!/bin/bash
#
# File: more_than_alerts.sh
# Release Version : 1.0
# Created 2019/07/16
# Licens: MIT
# Auther [email protected]
# How to use:
# For zabbix server
# "chmod + x" and please add on your scripts directory.
# e.g. /etc/zabbix/scripts/more_than_alerts.sh
# mkdir /etc/zabbix/tmp/
# chown zabbix:zabbix /etc/zabbix/tmp/
# Please execute manually for the first time.
# bash /etc/zabbix/scripts/more_than_alerts.sh
# For Zabbix Agent Config
# UserParameter=MoreThanAlerts.key,/etc/zabbix/script/more_than_alerts.sh [MySQL username] [MySQL password]
# For Zabbix item
# MoreThanAlerts.key
#
##################################
# Base Infomation
##################################
# Settings
##################################
# Zabbix
##################################
# Filecheck
if [[ ! -e /etc/zabbix/tmp/alerts.tmp ]]; then
/usr/bin/touch /etc/zabbix/tmp/alerts.tmp
fi
# Get data from alerts table
ALERTS=`/usr/bin/mysql -u $1 -p$2 -ss -e "select count(*) from zabbix.alerts;"`
# Get last time data
OLDALERTS=`cat /etc/zabbix/tmp/alerts.tmp`
# Check the difference
NUMALERTS=`echo $(($ALERTS-$OLDALERTS));`
# For next check
echo $ALERTS > /etc/zabbix/tmp/alerts.tmp
# Show results
echo $NUMALERTS
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment