-
Notifications
You must be signed in to change notification settings - Fork 5
/
update_consob
executable file
·47 lines (37 loc) · 1.87 KB
/
update_consob
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
source config.sh
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Downloading Consob List" >> $LOGFILE
# TODO make your own script
if [ -e $CONSOB_DOWNLOAD_HELPER ] ; then
python $CONSOB_DOWNLOAD_HELPER -o lists/consob.new.tmp
else
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CONSOB Error: Helper $CONSOB_DOWNLOAD_HELPER not found. See README" >> $LOGFILE
exit
fi
CURL_RETURN=$?
if [ $CURL_RETURN != 0 ] ; then
SUBJECT="Error while fetching CONSOB lists"
TXT="download_consob.py on $(hostname --fqdn) have returned $CURL_RETURN when trying to parse the CMS"
if [ $ALERT_ENABLE == true ] && [ "x$NOC_EMAIL" != 'x' ] ; then
echo -e "Subject: $SUBJECT\nFrom:$FROM_EMAIL\n$TXT" | sendmail $NOC_EMAIL
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CONSOB Error: $TXT" >> $LOGFILE
echo "Warning: $TXT" >&2
exit 255
fi
cat lists/consob.new.tmp | tr '[:upper:]' '[:lower:]' | sort | uniq > $FILE_consob
rm lists/consob.new.tmp
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - CONSOB List Downloaded" >> $LOGFILE
if [ -e "$FILE_consob" ]; then
egrep '^[^#]' $FILE_consob | sed 's~http[s]*://~~g' | sort | uniq > lists/consob.new.tmp
mv lists/consob.new.tmp lists/consob.new
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Imported list of IP $FILE_consob" >> $LOGFILE
elif [ ! -e lists/consob.new ]; then
: > lists/consob.new
fi
# allow manual add of specific IPs if file exists (ex lista.consob-ip)
if [ -e $FILE_consob-ip ]; then
egrep '^[^#]' $FILE_consob-ip | sort | uniq > lists/consob-ip
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Imported list of IP $FILE_consob-ip" >> $LOGFILE
fi
test $LOGGING_ENABLE == true && echo "$(date '+%d/%m/%y %H:%M:%S') - Import consob Completed" >> $LOGFILE