Changeset - 4f1c48458236
[Not reviewed]
master
0 1 2
Max Wahl (Fantawams) - 6 years ago 2019-08-25 14:34:56
fantawams@c3l.lu
FF check script update to update nodes list ones a day and to include authentication files for xmpp account
3 files changed with 65 insertions and 15 deletions:
0 comments (0 inline, 0 general)
ffluxbot/download_json_file.sh
Show inline comments
 
new file 100755
 

	
 
url=https://fflux-gw2.c3l.lu/data/nodes.json
 
pathtoscript=/home/scripts
 

	
 
wget $url -P $pathtoscript/ffluxbot
ffluxbot/ff_reachable_check_lists.sh
Show inline comments
 
@@ -6,10 +6,13 @@ pingcount=2
 
interval=50
 
pathtoscript=/home/scripts
 
delaytime=15
 
jabberid=$(cat $pathtoscript/ffluxbot/JabberID.auth)
 
jabberpw=$(cat $pathtoscript/ffluxbot/JabberPW.auth)
 

	
 
#first check out of 3
 
#empty empty old list
 
cat /dev/null > nodes_NOK.txt
 
cat /dev/null > $pathtoscript/ffluxbot/nodes_NOK.txt
 
iplist=$(awk '{print $1}' $pathtoscript/ffluxbot/FFnodes.txt)
 
# do the check
 
while IFS= read -r ip; do
 
	#get node names
 
@@ -19,16 +22,16 @@ while IFS= read -r ip; do
 
		#do this
 
		echo "$node_name is Pingable"
 
	else
 
		#Els do this
 
		#Else do this
 
		echo "$node_name Not Pingable"
 
		echo "$ip" >> nodes_NOK.txt
 
		echo "$ip" >> $pathtoscript/ffluxbot/nodes_NOK.txt
 
	fi
 
done <$pathtoscript/ffluxbot/iplist.txt
 
done <<< "$iplist"
 
echo Â"Check 1 done"
 
sleep $delaytime
 
echo Â"Start Check 2"
 
cat /dev/null > nodes_NOK2.txt
 

	
 
cat /dev/null > $pathtoscript/ffluxbot/nodes_NOK2.txt
 
iplist2=$(awk '{print $1}' $pathtoscript/ffluxbot/nodes_NOK.txt)
 
#second check out of 3
 
while IFS= read -r ip2; do
 
	node_name=$(awk "/^$ip2/ "'{print $NF}' $pathtoscript/ffluxbot/FFnodes.txt)
 
@@ -37,14 +40,14 @@ while IFS= read -r ip2; do
 
		echo "$node_name is Pingable"
 
	else
 
		echo "$node_name Not Pingable"
 
		echo "$ip2" >> nodes_NOK2.txt
 
		echo "$ip2" >> $pathtoscript/ffluxbot/nodes_NOK2.txt
 
	fi
 
done <$pathtoscript/ffluxbot/nodes_NOK.txt
 
done <<< "$iplist2"
 
echo "Check 2 done"
 
sleep $delaytime
 
echo  "Start Check 3"
 
cat /dev/null > nodes_NOK3.txt
 

	
 
cat /dev/null > $pathtoscript/ffluxbot/nodes_NOK3.txt
 
iplist3=$(awk '{print $1}' $pathtoscript/ffluxbot/nodes_NOK2.txt)
 
#last check out of 3
 
while IFS= read -r ip3; do
 
        node_name=$(awk "/^$ip3/ "'{print $NF}' $pathtoscript/ffluxbot/FFnodes.txt)
 
@@ -53,14 +56,24 @@ while IFS= read -r ip3; do
 
                echo "$node_name is Pingable"
 
        else
 
                echo "$node_name Not Pingable"
 
                echo "$node_name with IPV6 $ip3 is not reachable" >> nodes_NOK3.txt
 
                echo "$node_name with IPV6 $ip3 is not reachable" >> $pathtoscript/ffluxbot/nodes_NOK3.txt
 
        fi
 
done <$pathtoscript/ffluxbot/nodes_NOK2.txt
 
done <<< "$iplist3"
 
echo "Check 3 done"
 

	
 
# prepare Text message
 
textmessage=$(cat nodes_NOK3.txt)
 
textmessage=$(cat $pathtoscript/ffluxbot/nodes_NOK3.txt)
 
echo "$textmessage"
 

	
 
python3 $pathtoscript/ffluxbot/send_client.py -d -j BotJID -p Botpassword -t fantawams@c3l.lu -m "$textmessage"
 
python3 $pathtoscript/ffluxbot/send_client.py -d -j BotJID -p Botpassword -t orimpe@c3l.lu -m "$textmessage"
 
# send the messages
 
python3 $pathtoscript/ffluxbot/send_client.py -d -j "$jabberid" -p "$jabberpw" -t fantawams@c3l.lu -m "$textmessage"
 
python3 $pathtoscript/ffluxbot/send_client.py -d -j "$jabberid" -p "$jabberpw" -t orimpe@c3l.lu -m "$textmessage"
 

	
 
# clean up
 
rm $pathtoscript/ffluxbot/nodes_NOK.txt
 
rm $pathtoscript/ffluxbot/nodes_NOK2.txt
 
rm $pathtoscript/ffluxbot/nodes_NOK3.txt
 
rm $pathtoscript/ffluxbot/FFnodes.txt
 
rm $pathtoscript/ffluxbot/nodes.json
 
rm $pathtoscript/ffluxbot/check.log
 
rm $pathtoscript/ffluxbot/download.log
ffluxbot/update_nodes_list.py
Show inline comments
 
new file 100755
 
#!/usr/bin/python3
 
# import json module
 
import json
 
import re
 
# import pprint module
 
from pprint import pprint
 
# read json file and create an python dictionary
 
with open('/home/scripts/ffluxbot/nodes.json') as f:
 
    data = json.load(f)
 

	
 
# print whole json file
 
# pprint (data)
 
# print specific value of speciifc item of json fle
 
#pprint (data["nodes"][0]["nodeinfo"])
 

	
 
# print keys
 
#x = data.keys()
 
#pprint (x)
 
regex = re.compile('fd4e.*')
 
#y = data.items()
 
#pprint (y)
 

	
 
#z = data.values()
 
#pprint (z)
 

	
 
# print hostnames and IPV6 addresses of all nodes
 
for each in data['nodes']:
 
    hostname = each['nodeinfo']['hostname']
 
    iplist = each['nodeinfo']['network']['addresses']
 
    IP = str(list(filter(regex.match,iplist))[0])
 
    print('{} {}'.format(IP, hostname))
 

	
0 comments (0 inline, 0 general)