diff --git a/ffluxbot/download_json_file.sh b/ffluxbot/download_json_file.sh new file mode 100755 index 0000000000000000000000000000000000000000..e5184f16c463a77e883ec977449e56d3e177010f --- /dev/null +++ b/ffluxbot/download_json_file.sh @@ -0,0 +1,5 @@ + +url=https://fflux-gw2.c3l.lu/data/nodes.json +pathtoscript=/home/scripts + +wget $url -P $pathtoscript/ffluxbot diff --git a/ffluxbot/ff_reachable_check_lists.sh b/ffluxbot/ff_reachable_check_lists.sh index 31f158fa0ec8aaf074ffccbdfa6cc241f36b256d..55556f90fe59f9987896b8b9b5e814ec887e0cea 100755 --- a/ffluxbot/ff_reachable_check_lists.sh +++ b/ffluxbot/ff_reachable_check_lists.sh @@ -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 diff --git a/ffluxbot/update_nodes_list.py b/ffluxbot/update_nodes_list.py new file mode 100755 index 0000000000000000000000000000000000000000..e71634bc75bcccca0210612a0d7d369d2cce71ae --- /dev/null +++ b/ffluxbot/update_nodes_list.py @@ -0,0 +1,32 @@ +#!/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)) +