Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge from rubo77/gluon-alfred-vis #1

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
6d7a249
Update README.md
rubo77 May 22, 2014
a15d23c
Added GEO coordinates
rubo77 Jun 5, 2014
16e1de7
list, graph and map linked to http://freifunk.in-kiel.de/ffmap/
rubo77 Jun 5, 2014
8683408
show all available info for each node
rubo77 Jul 22, 2014
3be450e
Merge remote-tracking branch 'origin/master' into more_info
rubo77 Jul 29, 2014
b7dfafb
Merge remote-tracking branch 'origin/master' into more_info
rubo77 Jul 29, 2014
45a538e
Added try catch block around each element from json string, in case i…
rubo77 Jul 30, 2014
b9d504b
pathon script that logs all nodes in folder and creates an alfred_off…
rubo77 Jul 30, 2014
a80c6f9
restructured bin and www for binaries and html pages
rubo77 Jul 30, 2014
37dcc88
added option to pass python path to bash file
rubo77 Jul 30, 2014
f7d1f09
clean up alfred-log.py, and make it directly executable
wklaebe Jul 30, 2014
d6936b5
* clean up update-json.sh
wklaebe Jul 30, 2014
6e697fa
correct minor f*up
wklaebe Jul 30, 2014
7b26912
exlracted function for each node in javascript
rubo77 Jul 30, 2014
76f2651
correct url to URL
wklaebe Jul 30, 2014
0c85dbf
Merge branch 'more_info' of git://github.com/ffnord/gluon-alfred-vis …
wklaebe Jul 30, 2014
661df8e
corrected offline node list alfred_offline.json
rubo77 Jul 30, 2014
ac864b2
add clarification that this page needs JavaScript
wklaebe Jul 30, 2014
47ca07b
Merge branch 'more_info' of git://github.com/ffnord/gluon-alfred-vis …
wklaebe Jul 30, 2014
12ec18a
added offline nodes to list with new column
rubo77 Jul 30, 2014
267180e
enhanced README and call with --help
rubo77 Jul 30, 2014
f0c986a
colspan="0" to always span whole colgroup
wklaebe Jul 30, 2014
240cc6c
reverted change in list.css and excluded to alfred.css, so list.css s…
rubo77 Jul 30, 2014
008252c
Tidied indentation
rubo77 Jul 30, 2014
578f1ba
* added date of latest check
rubo77 Jul 31, 2014
672cbf9
add modified time for offline nodes
rubo77 Jul 31, 2014
aff0e29
sarted: show legacy nodes #5
rubo77 Jul 31, 2014
75fd0c5
reordered ajax calls
rubo77 Aug 2, 2014
849017f
Added Legacy nodes.json to list
rubo77 Aug 3, 2014
7517cb8
add links to map from geo coords #6
rubo77 Aug 4, 2014
26e6b4a
only try to download node detail json for alfred-nodes
rubo77 Aug 4, 2014
6def6a4
show distribution instead of firmware on gateways
rubo77 Aug 4, 2014
4232964
more-info: Increment month of offline date by one.
sargon Aug 4, 2014
0e72bdb
fixed: offline vpn gateways crashed the alfred_offline generation
rubo77 Aug 5, 2014
4f341e5
Log legacy nodes also
rubo77 Aug 13, 2014
d390ab9
show how many are offline and how many legacy were online
rubo77 Aug 16, 2014
4cb0d6e
show how many legacy nodes are online
rubo77 Aug 16, 2014
f49cbd9
Link to wiki page of kiel
rubo77 Aug 17, 2014
ca89c17
started localisation for different communities
rubo77 Aug 17, 2014
66930b0
added nodeplot statistic
rubo77 Aug 17, 2014
a686e12
replace colons in link no nodes in luebeck links
rubo77 Aug 17, 2014
c9da228
if there are no offline nodes, ",".join(ons) must return {}
rubo77 Aug 17, 2014
147aa23
setTimeout set to 10s because sometimes it takes some time to load al…
rubo77 Aug 21, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
alfred.json
logs/*
*.json
logs/*
www/logs/*
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
gluon-alfred-vis
================
Lists all nodes in Freifunk by analysing alfred.json
Lists all nodes in Freifunk by analysing `alfred.json`

there has to be a file `alfred.json` in the root folder of this krepository
The file `alfred.json` will be regularly downloaded into the `www` folder of this repository by `cron` that calls the script `update-json.sh`. Therefore copy the `crontab` file into your `/etc/cron.d/` folder and adapt it to your needs.

The files `alfred-log.py` and `update-json.sh` from the `bin` folder have to stay in the same folder for example `/opt/ff/gluon-alfred-vis/bin/`.

+ *git repository:* https://github.com/ffnord/gluon-alfred-vis
+ *online version Kiel:* http://freifunk.discovibration.de/gluon-alfred-vis/www/alfred.html
+ *online version Hamburg:* http://freifunk.discovibration.de/ffhh/www/alfred.html
185 changes: 0 additions & 185 deletions alfred.html

This file was deleted.

55 changes: 55 additions & 0 deletions bin/alfred-log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
This script splits all nodes in single files under logs/nodes and creates an alfred_offline.json file

Syntax: python alfred-log.py < alfred.json
"""

import json, sys, os, datetime, time

# timestamp to be added in alfred_offline.json
timestamp = time.time()
h_datetime = datetime.datetime.fromtimestamp(timestamp).strftime('%d.%m %H:%M:%S')

try:
nodes=json.load(sys.stdin)
except:
sys.exit('No JSON object could be decoded')

folder='logs/nodes/'
hostnames=[]
# write all nodes in separate files under logs/nodes/
for i in nodes:
nodes[i]['last_seen_h']=h_datetime
nodes[i]['last_seen']=timestamp
with open(folder+nodes[i]['hostname'], 'w') as fp:
json.dump(nodes[i], fp)
fp.close()
hostnames.append(nodes[i]['hostname'])

ons=[]

# look for files not in the nodes array
for on_hostname in os.listdir('logs/nodes'):
if not (on_hostname in hostnames):
on_fp=open(folder+on_hostname,'r')
on_json=on_fp.read()
on=json.loads(on_json)
if not 'distribution' in on:
try:
ons.append('"%s":%s' % (on["network"]["mac"], on_json))
except:
print on
sys.exit('ERROR: ["network"]["mac"] not in JSON object')


# offline nodes (on):
offline=open('alfred_offline.json', 'w')
joined_ons=",".join(ons)
# if there are no offline nodes, ",".join(ons) should return {}
if joined_ons=='':
joined_ons='"0":{}'
offline.write('{"additional_data": {"datetime": "%s", "timestamp": "%s"}, %s}' % (h_datetime, timestamp, joined_ons))
offline.close()
38 changes: 38 additions & 0 deletions bin/nodes-log.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

"""
This script splits all nodes in single files under logs/nodes and creates an nodes_offline.json file

Syntax: python nodes-log.py < nodes.json
"""

import json, sys, os, datetime, time

# timestamp to be added in nodes_offline.json
timestamp = time.time()
h_datetime = datetime.datetime.fromtimestamp(timestamp).strftime('%d.%m %H:%M:%S')

try:
nodes_data=json.load(sys.stdin)
except:
sys.exit('No JSON object could be decoded')

nodes=nodes_data['nodes']

folder='logs/nodes_legacy/'
hostnames=[]
# write all online nodes in separate files under logs/nodes_legacy/
for i in range(0, len(nodes)):
if nodes[i]['flags']['online'] and 'flags' in nodes[i] and 'legacy' in nodes[i]['flags'] and nodes[i]['flags']['legacy']:
if nodes[i]['name']=='':
nodes[i]['name']=nodes[i]['id']
nodes[i]['last_seen_h']=h_datetime
nodes[i]['last_seen']=timestamp
with open(folder+nodes[i]['name'], 'w') as fp:
json.dump(nodes[i], fp)
fp.close()
hostnames.append(nodes[i]['name'])

ons=[]

44 changes: 44 additions & 0 deletions bin/update-json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

# This script downloads the latest alfred.json and optional legacy nodes.json, creates logs by date in the www folder of your allpplication under logs/
# and calls alfred-log.py that splits all nodes in single files under logs/nodes and creates an alfred_offline.json file

BINPATH="$1"
WWWPATH="$2"
URL="$3"
LEGACY_URL="$4"

# call this script regularly as a cron job to get the latest alfred.json file

if [ $# -ne 3 -a $# -ne 4 ] ; then
if [ "$1" != "--help" ]; then
echo "ERROR: wrong number of parameters"
echo
fi
echo "Syntax:"
echo "$0 /path/to/bin /path/to/www http://freifunk.path/to/.../alfred.json [http://freifunk.path/to/.../nodes.json]"
echo
echo "the fourth parameter for legacy nodes.json is optional"
echo
exit 1
fi

cd "${WWWPATH}"

# get the actual json file from $URL
curl -o alfred.json "$URL"

mkdir -p logs/nodes

# copy the new file to a backupped version by date for possible analysation use later
cp alfred.json logs/alfred_$(date +%y%m%d-%H%M%S).json

# call alfred-log.py to split all single nodes under logs/nodes
${BINPATH}/alfred-log.py < alfred.json

# optional download legacy nodes.json
if [ "$LEGACY_URL" != "" ]; then
curl -o nodes.json "$LEGACY_URL"
cp nodes.json logs/nodes_$(date +%y%m%d-%H%M%S).json
${BINPATH}/nodes-log.py < nodes.json
fi
2 changes: 2 additions & 0 deletions crontab
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# to download the alfred json file every 10 minutes:
*/10 * * * * www-data /opt/ff/gluon-alfred-vis/bin/update-json.sh /opt/ff/gluon-alfred-vis/bin /opt/ff/gluon-alfred-vis/www http://.../alfred.json > /dev/null
11 changes: 0 additions & 11 deletions update-json.sh

This file was deleted.

Loading