Created
October 17, 2018 21:49
-
-
Save coffnix/727805a0b70c546aa1a83ccb24ac08f4 to your computer and use it in GitHub Desktop.
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/bash | |
# Necessario configurar no /etc/crontab a seguinte linha: | |
# | |
# */30 * * * * zabbix /etc/zabbix/scripts/dnsbl.sh | |
# | |
########################################################## | |
# Debug | |
#set -x | |
VERSION="3.0" | |
# Informe todos os IPs que deverao ser monitorados no formato: | |
IP[0]="172.97.103.1" | |
IP[1]="172.97.103.52" | |
ZABBIX_SCRIPTS="/etc/zabbix/scripts" | |
HOUR=$(date +%H) | |
RBL_LIST="rbl_list.txt" | |
URL_RBL_LIST="https://area31.net.br/dnsbl/rbl_list.txt" | |
cd $ZABBIX_SCRIPTS | |
touch /etc/zabbix/scripts/rbl.out.tmp | |
if [ ! -f $RBL_LIST ] || [ $HOUR -eq 10 ]; then | |
wget --quiet $URL_RBL_LIST -O /tmp/rbl_list-${HOUR}.txt | |
if [ $? -eq 0 ]; then | |
RBL=$(cat /tmp/rbl_list-${HOUR}.txt) | |
ERROR_DOWNLOAD=0 | |
rm -f $RBL_LIST | |
mv /tmp/rbl_list-${HOUR}.txt $RBL_LIST | |
sed -i /dnsbl.net.au/d $RBL_LIST | |
else | |
sleep 30 | |
wget --quiet $URL_RBL_LIST -O /tmp/rbl_list-${HOUR}.txt | |
if [ $? -eq 0 ]; then | |
RBL=$(cat /tmp/rbl_list-${HOUR}.txt) | |
ERROR_DOWNLOAD=0 | |
rm -f $RBL_LIST | |
mv /tmp/rbl_list-${HOUR}.txt $RBL_LIST | |
sed -i /dnsbl.net.au/d $RBL_LIST | |
else | |
RBL="b.barracudacentral.org | |
bl.spamcop.net | |
dnsbl.sorbs.net | |
cbl.abuseat.org | |
pbl.spamhaus.org | |
xbl.spamhaus.org | |
sbl.spamhaus.org | |
spam.dnsbl.sorbs.net" | |
ERROR_DOWNLOAD=1 | |
fi | |
fi | |
else | |
RBL=$(cat $RBL_LIST) | |
ERROR_DOWNLOAD=0 | |
fi | |
rm -f $ZABBIX_SCRIPTS/rbl.out.tmp | |
o=0 | |
while [ $o -lt ${#IP[*]} ]; do | |
IP_CHECK=${IP[$o]} | |
W=$( echo ${IP[$o]} | cut -d. -f1 ) | |
X=$( echo ${IP[$o]} | cut -d. -f2 ) | |
Y=$( echo ${IP[$o]} | cut -d. -f3 ) | |
Z=$( echo ${IP[$o]} | cut -d. -f4 ) | |
for i in $RBL; do | |
RESULT="$( host -t a $Z.$Y.$X.$W.$i 2>&1 )" | |
if [ $? -eq 0 ]; then | |
echo "IP $IP[$o] listed at $i ($RESULT)" >> $ZABBIX_SCRIPTS/rbl.out.tmp | |
fi | |
done | |
let o=$o+1 | |
done | |
if [ ${#IP[*]} -eq 0 ]; then | |
echo "IP not configured in script." >> $ZABBIX_SCRIPTS/rbl.out.tmp | |
fi | |
if [ $ERROR_DOWNLOAD -eq 1 ]; then | |
## | |
wget --quiet $URL_RBL_LIST -O /tmp/rbl_list-${HOUR}.txt | |
if [ $? -eq 0 ]; then | |
RBL=$(cat /tmp/rbl_list-${HOUR}.txt) | |
ERROR_DOWNLOAD=0 | |
rm -f $RBL_LIST | |
mv /tmp/rbl_list-${HOUR}.txt $RBL_LIST | |
else | |
RBL="b.barracudacentral.org | |
bl.spamcop.net | |
dnsbl.sorbs.net | |
cbl.abuseat.org | |
pbl.spamhaus.org | |
xbl.spamhaus.org | |
sbl.spamhaus.org | |
spam.dnsbl.sorbs.net" | |
ERROR_DOWNLOAD=1 | |
fi | |
## | |
fi | |
if [ $ERROR_DOWNLOAD -eq 1 ]; then | |
if [ -s $RBL_LIST ]; then | |
echo "Download of $RBL_LIST fail." >> $ZABBIX_SCRIPTS/rbl.out | |
fi | |
fi | |
# Limpeza da lista | |
touch /etc/zabbix/scripts/rbl.out.tmp | |
sed -i /'has no A record'/d /etc/zabbix/scripts/rbl.out.tmp | |
mv /etc/zabbix/scripts/rbl.out.tmp /etc/zabbix/scripts/rbl.out | |
[ -s ${ZABBIX_SCRIPTS}/rbl.out ] || echo "none" > ${ZABBIX_SCRIPTS}/rbl.out | |
# Fim |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment