83 lines
2.4 KiB
Bash
Executable File
83 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
DIR=`dirname $0`
|
|
DAT=`date "+%s"`
|
|
LOGFILE=$DIR/logs/$DAT-rotate_program.log
|
|
FLOWFILE=$DIR/data/$1
|
|
|
|
echo "-----" >> $LOGFILE
|
|
date >> $LOGFILE
|
|
echo "Neues File $FLOWFILE" >> $LOGFILE
|
|
|
|
echo "Hole exporter von DB" >> $LOGFILE
|
|
echo 'select * from exporter' | mysql -N -B -uroot -plunakoshix -Dnetflow > $DIR/tmp/$DAT-exporter
|
|
echo "exporter ..." >> $LOGFILE
|
|
|
|
################# durchlaufe exporter
|
|
|
|
while read EXP
|
|
do
|
|
|
|
################## ein exporter nach dem anderen
|
|
|
|
ID=$(echo $EXP | awk '{print $1}');
|
|
IP=$(echo $EXP | awk '{print $2}');
|
|
echo "" >> $LOGFILE
|
|
date >> $LOGFILE
|
|
echo "IP $IP" >> $LOGFILE
|
|
|
|
echo "flow-cat $FLOWFILE | flow-filter -e $IP | flow-print -f 5" >> $LOGFILE
|
|
flow-cat $FLOWFILE | flow-filter -e $IP | flow-print -f 5 > $DIR/tmp/$DAT-exporter-$IP
|
|
|
|
echo "schreibe $DIR/tmp/$DAT-exporter-$IP-insert" >> $LOGFILE
|
|
while read E
|
|
do
|
|
START=$(echo $E | awk '{print $1}')
|
|
if [[ $START =~ ^[0-9] ]]
|
|
then
|
|
ENDE=$(echo $E | awk '{print $2}')
|
|
SIF=$(echo $E | awk '{print $3}')
|
|
SIP=$(echo $E | awk '{print $4}')
|
|
SP=$(echo $E | awk '{print $5}')
|
|
DIF=$(echo $E | awk '{print $6}')
|
|
DIP=$(echo $E | awk '{print $7}')
|
|
DP=$(echo $E | awk '{print $8}')
|
|
P=$(echo $E | awk '{print $9}')
|
|
F=$(echo $E | awk '{print $10}')
|
|
PA=$(echo $E | awk '{print $11}')
|
|
O=$(echo $E | awk '{print $12}')
|
|
|
|
echo "insert into flows set flow_exporter='$ID',flow_src_if='$SIF',flow_src_ip='$SIP',flow_src_port='$SP',flow_dst_if='$DIF',flow_dst_ip='$DIP',flow_dst_port='$DP',flow_protocol='$P',flow_flag='$F',flow_packets='$PA',flow_octets='$O';" >> $DIR/tmp/$DAT-exporter-$IP-insert
|
|
else
|
|
continue
|
|
fi
|
|
done < $DIR/tmp/$DAT-exporter-$IP
|
|
|
|
######################### exporter erledigt
|
|
|
|
echo "schreiben beendet $DIR/tmp/$DAT-exporter-$IP-insert" >> $LOGFILE
|
|
|
|
echo "" >> $LOGFILE
|
|
echo "lösche flowfile $FLOWFILE" >> $LOGFILE
|
|
rm $FLOWFILE
|
|
|
|
echo "" >> $LOGFILE
|
|
echo "insert $DIR/tmp/$DAT-exporter-$IP-insert in DB" >> $LOGFILE
|
|
echo "mysql -uroot -plunakoshix -Dnetflow < $DIR/tmp/$DAT-exporter-$IP-insert" >> $LOGFILE
|
|
# mysql -uroot -plunakoshix -Dnetflow < $DIR/tmp/$DAT-exporter-$IP-insert >> $LOGFILE 2>&1 && rm $DIR/tmp/$DAT-exporter-$IP-insert
|
|
|
|
echo "" >> $LOGFILE
|
|
echo "lösche insert Datei $DIR/tmp/$DAT-exporter-$IP-insert" >> $LOGFILE
|
|
rm $DIR/tmp/$DAT-exporter-$IP-insert
|
|
|
|
done < $DIR/tmp/$DAT-exporter
|
|
|
|
######################## alle exporter erledigt
|
|
|
|
echo "ende" >> $LOGFILE
|
|
date >> $LOGFILE
|
|
|
|
|
|
|
|
|