summaryrefslogtreecommitdiffstats
path: root/retiolum/scripts/adv_graphgen/tinc_graphs/Services.py
blob: 227e5aba776c892e203a9b51e5bf5818f8a8e721 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os,sys
services_dir=os.environment.get("SERIVCES_DIR","/home/reaktor/nag.services")
def add_services(nodes):
    for k,v in nodes.items():
        n = nodes[k]
        try:
            with open("{0}/{1}".format(services_dir,k)) as f:
                n["services"] = []
                for line in f.readlines():
                    n["services"].append(line.strip())
        except Exception as e:
            n["services"] = ["Error: No Service File!"]
    return nodes
def main():
    import json,sys
    try:
        nodes = add_services(json.load(sys.stdin))
        print (json.dumps(nodes,indent=4))
    except:
        print("unable to parse json data from stdin")
        sys.exit(1)

if __name__ == "__main__":
    main()
# vim: set expandtab:ts=4:sw=4