예제 #1
0
def setup(settings = None):
    global env, _settings

    if env != None:
        return

    if settings == None:
        _settings = {"tags":False,"sizeoverview":False,"logfiles":False}
    else:
        _settings = settings['features']

    env = Environment(loader=FileSystemLoader('templates'))

    env.globals['hosts'] = hosts.getHostData()
    env.globals['hosts_json'] = json.dumps(env.globals['hosts'])
    env.globals['settings'] = _settings;
    hl = sorted( env.globals['hosts'].values() , key = lambda h : h['settings']['uiShortName'] )

    gs = {}
    hlf = []
    for h in hl:
        if h['host_group_id'] == None:
            hlf.append(h)
        else:
            if h['host_group_id'] in gs:
                continue
            else:
                gs[h['host_group_id']] = True
                hlf.append(h)

    env.globals['hostlist'] = hlf

    groups = {}

    for h in hosts.getHosts().values():
        if h['host_group_id'] > 0:
            if not (h['host_group_id'] in groups):
                groups[h['host_group_id']] = []

            groups[h['host_group_id']].append(h);

    for g in groups.keys():
        groups[g] = sorted(groups[g], key = lambda x : x['settings']['uiShortName'])

    env.globals['hostgroups'] = groups
    env.globals['groups'] = hosts.getGroups()
    env.globals['groups_json'] = json.dumps(hosts.getGroups())
예제 #2
0
파일: tplE.py 프로젝트: a1exsh/PGObserver
def setup(settings = None):
    global env, _settings
    hosts.resetHostsAndGroups()

    if settings == None:
        _settings = {"show_load":True, "show_wal":True, "show_top_sprocs":True, "show_db_size":True, "show_db_stats":True}
    else:
        _settings = settings['features']

    if env is None:
        env = Environment(loader=FileSystemLoader(os.path.join(os.path.dirname(__file__), 'templates')))

    env.globals['hosts'] = hosts.getHostData()
    env.globals['hosts_json'] = json.dumps(env.globals['hosts'])
    env.globals['settings'] = _settings
    hl = sorted( env.globals['hosts'].values() , key = lambda h : h['uishortname'] )

    gs = {}
    hlf = []
    for h in hl:
        if h['host_group_id'] == None:
            hlf.append(h)
        else:
            if h['host_group_id'] in gs:
                continue
            else:
                gs[h['host_group_id']] = True
                hlf.append(h)

    env.globals['hostlist'] = hlf

    groups = {}

    for h in hosts.getHosts().values():
        if not (h['host_group_id'] in groups):
            groups[h['host_group_id']] = []

        groups[h['host_group_id']].append(h)

    for g in groups.keys(): # TODO remove?
        groups[g] = sorted(groups[g], key = lambda x : x['uishortname'])

    env.globals['hostgroups'] = groups
    env.globals['groups'] = hosts.getGroups()
    env.globals['groups_json'] = json.dumps(hosts.getGroups())
예제 #3
0
def setup(settings=None):
    global env, _settings

    if env != None:
        return

    if settings == None:
        _settings = {"tags": False, "sizeoverview": False, "logfiles": False}
    else:
        _settings = settings['features']

    env = Environment(loader=FileSystemLoader('templates'))

    env.globals['hosts'] = hosts.getHostData()
    env.globals['settings'] = _settings
    hl = sorted(env.globals['hosts'].values(),
                key=lambda h: h['settings']['uiShortName'])

    gs = {}
    hlf = []
    for h in hl:
        if h['host_group_id'] == None:
            hlf.append(h)
        else:
            if h['host_group_id'] in gs:
                continue
            else:
                gs[h['host_group_id']] = True
                hlf.append(h)

    env.globals['hostlist'] = hlf

    groups = {}

    for h in hosts.getHosts().values():
        if h['host_group_id'] > 0:
            if not (h['host_group_id'] in groups):
                groups[h['host_group_id']] = []

            groups[h['host_group_id']].append(h)

    for g in groups.keys():
        groups[g] = sorted(groups[g],
                           key=lambda x: x['settings']['uiShortName'])

    env.globals['hostgroups'] = groups
    env.globals['groups'] = hosts.getGroups()