Eliminare tutti i dati in Ntop

From RVM Wiki
Revision as of 16:32, 21 December 2023 by Gabriele.vivinetto (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

I dati di Ntop sono nei files in

/var/lib/ntopng

E nei Database di

  • Clickhouse
  • Influxdb

Questo script cancella tutto:

cat > /usr/local/sbin/clean_ntopng <<'EOFile'
#!/bin/bash

CLICKHOUSE_PASS=$1
CLICKHOUSE_OK=""

if [ -z "$CLICKHOUSE_PASS" ]
then
	echo -e "\nUsage: $0 clickhouse_password\n"
	echo "Look for -F=\"clickhouse;127.0.0.1;ntopng;default;clickhouse_password\""
	echo -e "in /etc/ntopng/ntopng.conf or in files inside /etc//ntopng/ntopng.conf.d\n"
	exit 127
fi

echo show tables | clickhouse-client -u default --password $CLICKHOUSE_PASS -d ntopng >/dev/null 2>&1
CLICKHOUSE_OK=$?

if [ $CLICKHOUSE_OK -ne 0 ]
then
	echo -e "\nClickhousepassword is wrong.\n"
	echo "Look for -F=\"clickhouse;127.0.0.1;ntopng;default;clickhouse_password\""
	echo -e "in /etc/ntopng/ntopng.conf or in files inside /etc//ntopng/ntopng.conf.d\n"
	exit 127
fi

echo "Stopping ntopng.service ..."
systemctl stop ntopng.service

for UNIT in $(systemctl list-units nprobe\* --all | grep nprobe | grep '\.service' | tr -s ' '| cut -f 2 --delimiter=' ')
do
	echo "Stopping $UNIT ..."
	systemctl stop $UNIT
done

echo "Cleaning /var/lib/ntopng/ ..."
rm -rf /var/lib/ntopng/*

for TBL in $(echo show tables | clickhouse-client -u default --password $CLICKHOUSE_PASS -d ntopng |grep -v '_view')
do
	echo "Truncating Clickhouse table $TBL ..."
	echo truncate table $TBL | clickhouse-client -u default --password $CLICKHOUSE_PASS -d ntopng
done


echo "Dropping InfluxDB measurements ..."
influx --execute 'show measurements' --database=ntopng | xargs -I{} influx --database=ntopng --execute 'drop measurement "{}"'

echo "Ststarting ntopng.service ..."
systemctl start ntopng.service
for UNIT in $(systemctl list-units nprobe\* --all | grep nprobe | grep '\.service' | tr -s ' '| cut -f 2 --delimiter=' ')
do
	echo "Starting $UNIT ..."
	systemctl start $UNIT
done
EOFile
chmod +x /usr/local/sbin/clean_ntopng

La password di clickhouse è nella configurazione di Ntop.

Eseguire lo script

/usr/local/sbin/clean_ntopng clickhouse_password