#! /usr/bin/env python
import sys
import main_backuper as mainscr


def f_main():
    conf, errorcode = mainscr.conf_read()
    hosts, errorcode = mainscr.hosts_read(conf["hosts"])
    inp = []
    for host in hosts:
        if host[2] == "up" :
            inp.append(host[0])
    f_json_print(inp)


def f_json_print(inp):
    first = True
    print("{")
    print("\t\"data\":[")
    for key in inp:
        if not first:
            sys.stdout.write(",")
        else:
            first = False
        sys.stdout.write("\n\t\t{\"{#HOST}\":\"" + key + "\"}")
    print("\n\t]")
    print("}")


if __name__ == '__main__':
    f_main()