Subversion Repositories ALCASAR

Rev

Rev 2454 | Rev 2488 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2454 Rev 2474
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-activity_report.sh 2454 2017-12-09 18:59:31Z tom.houdayer $
2
# $Id: alcasar-activity_report.sh 2474 2017-12-30 02:00:04Z tom.houdayer $
3
#
3
#
4
# Create an activity report for ALCASAR every week (sunday at 5.35 pm --> see cron.d).
4
# Create an activity report for ALCASAR every week (sunday at 5.35 pm --> see cron.d).
5
# We read configuration files and logs to create cool charts.
5
# We read configuration files and logs to create cool charts.
6
# Written by Raphaël PION, Rexy & Tom HOUDAYER
6
# Written by Raphaël PION, Rexy & Tom HOUDAYER
7
 
7
 
-
 
8
CONF_FILE='/usr/local/etc/alcasar.conf'
8
# files
9
# files
9
DIR_TMP="/var/tmp"
10
DIR_TMP="/var/tmp"
10
TMP_AV="$DIR_TMP/av_count.txt"
11
TMP_AV="$DIR_TMP/av_count.txt"
11
TMP_BL="$DIR_TMP/bl_count.txt"
12
TMP_BL="$DIR_TMP/bl_count.txt"
12
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt"
13
TMP_BL_WEEK="$DIR_TMP/bl_count_week.txt"
Line 25... Line 26...
25
MAX_DAY_AGO=7
26
MAX_DAY_AGO=7
26
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
27
SECS_AGO=$(date --date="$MAX_DAY_AGO days ago" +"%s") #timestamp ago
27
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
28
STEP_TS=$((C_TS-$SECS_AGO)) #timestamp between current timestamp and SECS_AGO
28
 
29
 
29
# PRIVATE IP OF ALCASAR
30
# PRIVATE IP OF ALCASAR
30
PRIVATE_IP=$(cat /usr/local/etc/alcasar.conf | grep PRIVATE_IP | cut -d'=' -f2 | cut -d'/' -f1)
31
PRIVATE_IP=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2 | cut -d'/' -f1)
31
 
32
 
32
# COLOR for charts
33
# COLOR for charts
33
COLOR="'#ff0000','#3333cc','#009933','#993300','#1720EE','#D30229','#8D726D','#41C4E4','#8574F4','#A0BC1A','#BFDC1F','#5ADDC3','#B05744','#CD9319','#8CA39B','#D4AA1C','#A76752','#B03088','#445E87','#70424D','#D118C3','#46ABEF','#E9F197','#AEC0D4','#755C79','#94BBD7','#E2E9DC','#8B68D0','#F7EC7C','#1F16B8','#F4DA0A','#2EC17A','#E06483','#48B342','#F510CD','#9B2662','#180E98','#988FC1','#209E4E','#034240','#FDB142','#36B445','#CDD5C9','#6FA0DE','#EE2206','#204E19','#15FC93','#161ECE','#83D33B','#11A44A','#B7BF6C','#87274C','#B52C4F','#AD2805','#427E6C','#91341A','#191315','#FCB290','#13D3CD','#90F0E6','#C870C9','#AD2C14','#201D2A','#E4DB79','#90A919','#FE17FE','#09B35C','#88D950','#3440FC','#A9D42F','#E2DFAC','#DA69EC','#67430A','#43E94E','#5F7349','#22CF16','#CF038F','#0F6427','#F7AD0F','#C5E382','#DB49B6','#F760BF','#0BE701','#EF88D8','#79E6D7','#8A2D3D','#435A30','#A3C8AC','#99B118','#A929FF','#08A36D','#0A1654','#6F8283','#E1CA3E','#3E8577','#580FB6','#DB0E16','#386CBE','#FA0C43','#B713C9'"
34
COLOR="'#ff0000','#3333cc','#009933','#993300','#1720EE','#D30229','#8D726D','#41C4E4','#8574F4','#A0BC1A','#BFDC1F','#5ADDC3','#B05744','#CD9319','#8CA39B','#D4AA1C','#A76752','#B03088','#445E87','#70424D','#D118C3','#46ABEF','#E9F197','#AEC0D4','#755C79','#94BBD7','#E2E9DC','#8B68D0','#F7EC7C','#1F16B8','#F4DA0A','#2EC17A','#E06483','#48B342','#F510CD','#9B2662','#180E98','#988FC1','#209E4E','#034240','#FDB142','#36B445','#CDD5C9','#6FA0DE','#EE2206','#204E19','#15FC93','#161ECE','#83D33B','#11A44A','#B7BF6C','#87274C','#B52C4F','#AD2805','#427E6C','#91341A','#191315','#FCB290','#13D3CD','#90F0E6','#C870C9','#AD2C14','#201D2A','#E4DB79','#90A919','#FE17FE','#09B35C','#88D950','#3440FC','#A9D42F','#E2DFAC','#DA69EC','#67430A','#43E94E','#5F7349','#22CF16','#CF038F','#0F6427','#F7AD0F','#C5E382','#DB49B6','#F760BF','#0BE701','#EF88D8','#79E6D7','#8A2D3D','#435A30','#A3C8AC','#99B118','#A929FF','#08A36D','#0A1654','#6F8283','#E1CA3E','#3E8577','#580FB6','#DB0E16','#386CBE','#FA0C43','#B713C9'"
34
 
35
 
35
# Values to create new htdigest user to consult statistique of ACC
36
# Values to create new htdigest user to consult statistique of ACC
Line 80... Line 81...
80
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
81
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"../../../css/report.css\">" >> $HTML_REPORT
81
echo "<script src=\"../../../js/Chart.bundle.min.js\"></script>" >> $HTML_REPORT
82
echo "<script src=\"../../../js/Chart.bundle.min.js\"></script>" >> $HTML_REPORT
82
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
83
echo "<script src=\"../../../js/jquery.min.js\"></script>" >> $HTML_REPORT
83
echo "</head>" >> $HTML_REPORT
84
echo "</head>" >> $HTML_REPORT
84
echo "<body>" >> $HTML_REPORT
85
echo "<body>" >> $HTML_REPORT
85
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)</center></h1>" >> $HTML_REPORT
86
echo "<h1><center>Rapport d'activité de l'ALCASAR-$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)</center></h1>" >> $HTML_REPORT
86
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
87
echo "<i><p style=\"text-align: right;\">Date de création $(date +%F)</p></i>" >> $HTML_REPORT
87
echo "<font size=\"1\">" >> $HTML_REPORT
88
echo "<font size=\"1\">" >> $HTML_REPORT
88
 
89
 
89
######################TABINFO######################
90
######################TABINFO######################
90
echo "Create information about system and ALCASAR"
91
echo "Create information about system and ALCASAR"
Line 93... Line 94...
93
cat $MODEL_TABINFO | while read LINE_HTML
94
cat $MODEL_TABINFO | while read LINE_HTML
94
do
95
do
95
 
96
 
96
if [ $(echo $LINE_HTML | grep 'XXORGXX' | wc -l) -eq 1 ]
97
if [ $(echo $LINE_HTML | grep 'XXORGXX' | wc -l) -eq 1 ]
97
then
98
then
98
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep ORGANISM | cut -d'=' -f2)
99
	VALUE=$(grep ^ORGANISM= $CONF_FILE | cut -d'=' -f2-)
99
	echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
100
	echo ${LINE_HTML/XXORGXX/$VALUE} >> $HTML_REPORT
100
	
101
	
101
elif [ $(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l) -eq 1 ]
102
elif [ $(echo $LINE_HTML | grep 'XXINSTALLXX' | wc -l) -eq 1 ]
102
then
103
then
103
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep INSTALL_DATE | cut -d'=' -f2)
104
	VALUE=$(grep ^INSTALL_DATE= $CONF_FILE | cut -d'=' -f2)
104
	echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
105
	echo ${LINE_HTML/XXINSTALLXX/$VALUE} >> $HTML_REPORT
105
	
106
	
106
elif [ $(echo $LINE_HTML | grep 'XXAVERSIONXX' | wc -l) -eq 1 ]
107
elif [ $(echo $LINE_HTML | grep 'XXAVERSIONXX' | wc -l) -eq 1 ]
107
then
108
then
108
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep VERSION | cut -d'=' -f2)
109
	VALUE=$(grep ^VERSION= $CONF_FILE | cut -d'=' -f2)
109
	echo ${LINE_HTML/XXAVERSIONXX/$VALUE} >> $HTML_REPORT
110
	echo ${LINE_HTML/XXAVERSIONXX/$VALUE} >> $HTML_REPORT
110
	
111
	
111
elif [ $(echo $LINE_HTML | grep 'XXIP_PUBLICXX' | wc -l) -eq 1 ]
112
elif [ $(echo $LINE_HTML | grep 'XXIP_PUBLICXX' | wc -l) -eq 1 ]
112
then
113
then
113
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep PUBLIC_IP | cut -d'=' -f2)
114
	VALUE=$(grep ^PUBLIC_IP= $CONF_FILE | cut -d'=' -f2)
114
	echo ${LINE_HTML/XXIP_PUBLICXX/$VALUE} >> $HTML_REPORT
115
	echo ${LINE_HTML/XXIP_PUBLICXX/$VALUE} >> $HTML_REPORT
115
	
116
	
116
elif [ $(echo $LINE_HTML | grep 'XXIP_PRIVEXX' | wc -l) -eq 1 ]
117
elif [ $(echo $LINE_HTML | grep 'XXIP_PRIVEXX' | wc -l) -eq 1 ]
117
then
118
then
118
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep PRIVATE_IP | cut -d'=' -f2)
119
	VALUE=$(grep ^PRIVATE_IP= $CONF_FILE | cut -d'=' -f2)
119
	echo ${LINE_HTML/XXIP_PRIVEXX/$VALUE} >> $HTML_REPORT
120
	echo ${LINE_HTML/XXIP_PRIVEXX/$VALUE} >> $HTML_REPORT
120
	
121
	
121
elif [ $(echo $LINE_HTML | grep 'XXGWXX' | wc -l) -eq 1 ]
122
elif [ $(echo $LINE_HTML | grep 'XXGWXX' | wc -l) -eq 1 ]
122
then
123
then
123
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep 'GW=' | cut -d'=' -f2)
124
	VALUE=$(grep ^GW= $CONF_FILE | cut -d'=' -f2)
124
	echo ${LINE_HTML/XXGWXX/$VALUE} >> $HTML_REPORT
125
	echo ${LINE_HTML/XXGWXX/$VALUE} >> $HTML_REPORT
125
	
126
	
126
elif [ $(echo $LINE_HTML | grep 'XXDNS1XX' | wc -l) -eq 1 ]
127
elif [ $(echo $LINE_HTML | grep 'XXDNS1XX' | wc -l) -eq 1 ]
127
then
128
then
128
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep DNS1 | cut -d'=' -f2)
129
	VALUE=$(grep ^DNS1= $CONF_FILE | cut -d'=' -f2)
129
	echo ${LINE_HTML/XXDNS1XX/$VALUE} >> $HTML_REPORT
130
	echo ${LINE_HTML/XXDNS1XX/$VALUE} >> $HTML_REPORT
130
	
131
	
131
elif [ $(echo $LINE_HTML | grep 'XXDNS2XX' | wc -l) -eq 1 ]
132
elif [ $(echo $LINE_HTML | grep 'XXDNS2XX' | wc -l) -eq 1 ]
132
then
133
then
133
	VALUE=$(cat /usr/local/etc/alcasar.conf | grep DNS2 | cut -d'=' -f2)
134
	VALUE=$(grep ^DNS2= $CONF_FILE | cut -d'=' -f2)
134
	echo ${LINE_HTML/XXDNS2XX/$VALUE} >> $HTML_REPORT
135
	echo ${LINE_HTML/XXDNS2XX/$VALUE} >> $HTML_REPORT
135
	
136
	
136
elif [ $(echo $LINE_HTML | grep 'XXHOSTXX' | wc -l) -eq 1 ]
137
elif [ $(echo $LINE_HTML | grep 'XXHOSTXX' | wc -l) -eq 1 ]
137
then
138
then
138
	VALUE=$(hostname)
139
	VALUE=$(hostname)
Line 600... Line 601...
600
 
601
 
601
###################### ALCASAR : GLOBAL TRAFFIC ######################
602
###################### ALCASAR : GLOBAL TRAFFIC ######################
602
echo "Get Global traffic of the last 30 days"
603
echo "Get Global traffic of the last 30 days"
603
 
604
 
604
ROWS=""
605
ROWS=""
605
EXTIF=$(cat /usr/local/etc/alcasar.conf | grep '^EXTIF=' | cut -d'=' -f2)
606
EXTIF=$(grep ^EXTIF= $CONF_FILE | cut -d'=' -f2)
606
for day in $(vnstat --exportdb -i $EXTIF | grep '^d;' | sort -t";" -k3 -r); do
607
for day in $(vnstat --exportdb -i $EXTIF | grep '^d;' | sort -t";" -k3 -r); do
607
	day_datas=(${day//;/ })
608
	day_datas=(${day//;/ })
608
	day_date=${day_datas[2]}
609
	day_date=${day_datas[2]}
609
	day_rxMio=${day_datas[3]}
610
	day_rxMio=${day_datas[3]}
610
	day_txMio=${day_datas[4]}
611
	day_txMio=${day_datas[4]}