示例#1
0
def init_hostname_certname(): 
    hosts = {
        'linux2233.puppet.com':'template_1',
        'windows2233.puppet.com':'template_1',
        'linux22101.zjz.com':'template_1',
    }
    #主机名对应的模板添加到redis
    for key,value in hosts.items():
        rediscli.set(key, value)

def run(result):    
    
    while True:
        data = result.parse_response()
        get_info = json.loads(data[2])
        if get_info['level'] == 3:
            print '\033[31m %s \033[0m' %(get_info,)
        elif get_info['level'] == 2:
            print '\033[33m %s \033[0m' %(get_info,)
        elif get_info['level'] == 1:
            print '\033[32m %s \033[0m' %(get_info,)
        print '============================'
        
if __name__ == '__main__':
    rediscli = RedisHelper()
    result = rediscli.subscribe()
    templates = init_template()
    init_hostname_certname()
    push_config_to_redis(rediscli,templates)
    run(result)
示例#2
0
#!/usr/bin/env python
#coding:utf-8
import time
import json
from backend.redisHelper import RedisHelper
from plugins import plugin_api

redis_cli = RedisHelper()
certname = 'linux2233.puppet.com'


#根据主机名获取模板名称 'linux2233.com -- > template_1'
template_name = redis_cli.get(certname)
print template_name
config = json.loads(redis_cli.get(template_name))

while True:
    for key,value in config.items():
        currenttime,interval,lasttime = time.time(),value['interval'],value['last_time']
        if (currenttime-lasttime) < interval:
            pass
        else:
            plugin_name = value['plugin_name']
            func = getattr(plugin_api, plugin_name)
            data = func()
            if key == 'load':
                get = data['load5']
                warm,error = value['load5']
                get = float(get)
                print get,warm,error
                if get>error: