예제 #1
0
파일: monitor.py 프로젝트: thezpliu/runaway
def get_items(inf=0):
    zab = [zapi1, zapi2]
    resultlist = []
    for za in zab:
        try:
            for host in za.zabbix_host():
                hostinfo = {}
                hostinfo['iid'] = za.iid
                hostinfo['id'] = host['hostid']
                hostinfo['name'] = host['name']
                hostinfo['ip'] = host['interfaces'][0]['ip']
                if inf == 0:
                    for items in za.zabbix_itemid_get(host['hostid']):
                        hostinfo[items['key_']] = items['lastvalue']
                    resultlist.append(hostinfo)
                elif inf == 1:
                    eventlist = []
                    for event in za.zabbix_event_get(host['hostid']):
                        eventlist.append(event)
                    hostinfo['event'] = eventlist
                    resultlist.append(hostinfo)
        except Exception as e:
            logd.sys_log_save(e.message)
            continue
    return resultlist
예제 #2
0
파일: wcache.py 프로젝트: thezpliu/runaway
def svninfo_cache(sec):
	host = conf.svnConfig['host']
	repolist = conf.svnConfig['repolist']
	while True:
		for re in repolist:
			try:
				sd = getsvninfo(host,re)
				if 'error' in sd.keys():
					sd['Node Kind'] = 'error'
					sd['URL'] = 'error'
					sd['Last Changed Date'] = 'error'
					sd['Repository Root'] = 'error'
					sd['back'] = 'error'
					sd['Last Changed Author'] = 'error'
					sd['Path'] = re
					sd['Revision'] = 'error'
					sd['Last Changed Rev'] = 'error'
					sd['Repository UUID'] = 'error'
				rb2.p.hmset(re,sd)
        			rb2.p.expire(re,600)
			except Exception as e:
				logd.sys_log_save(e)
				pass
		try:
			x = rb2.p.execute()
		except Exception as e:
			logd.sys_log_save(e)
			pass
		time.sleep(sec)
예제 #3
0
파일: runtask.py 프로젝트: thezpliu/runaway
def sub_process():
	try:
    		signal.signal(signal.SIGCHLD, signal.SIG_IGN)
		#SIGCHLD信号是在子进程退出时或是状态发送变化时发送给父进程的。父进程会用wait或waitpid来处理这个信号,在处理之前子进程为僵尸状态
		#设置成signal.SIG_IGN 的意思是父进程不去管理子进程,子进程由系统init进程管理(wait)。
        	m = Process(target=monitor_cache, args=[5])
        	s = Process(target=svninfo_cache, args=[300])
        	n = Process(target=p4_cache, args=[300])
        	m.start()
        	s.start()
        	n.start()
    	except Exception as e:
		logd.sys_log_save(e.message)
예제 #4
0
파일: wcache.py 프로젝트: thezpliu/runaway
def p4_cache(sec):
	portlist = conf.p4Config['portlist']
	while True:
		for port in portlist:
			try:
				x,e = getp4info(port)
				if x:
					y = x.copy()
					last = time.localtime(float(y['time']))
					y['times'] = time.strftime('%Y-%m-%d %H:%M:%S',last)
					y['port'] = port
					y['path'] = ''
					y['desc'] = ''
					i18 = chardet.detect(y['client'])
					if i18['encoding'] != 'ascii':
						ilog = i18['encoding'] + '--' + y['client'] + '--' + y['port']
						y['client'] = y['client'].decode('ISO-8859-1')
						logd.sys_log_save(ilog)
					if x == e:
						y['back'] = 'yes'
					else:
						if e:
							y['back'] = e['change']
						else:
							y['back'] = 'error'
				else:
					y["status"] = "error"
					y["changeType"] = "error"
					y["times"] = "error"
					y["client"] = "error"
					y["user"] = "******"
					y["time"] = "error"
					y["path"] = "error"
					y["port"] = port
					y["change"] = "error"
					y["desc"] = "error"
					if e:
						y["back"] = e["change"]
					else:
						y["back"] = "error"
				rb3.p.hmset(port,y)
        			rb3.p.expire(port,600)
			except Exception as e:
				logd.sys_log_save(e)
				pass
		try:
			rb3.p.execute()
		except:
			pass
		time.sleep(sec)
예제 #5
0
파일: wcache.py 프로젝트: thezpliu/runaway
def monitor_cache(sec):
	while True:
		g = get_item()
		if g:
			for i in g:
				name = i['id']
				if rb1.r.hexists(name,'netin'):
					if int(i['netin']) > 9999999:
						innum = str(format( float(i['netin']) / float(1048576),'.1f')) + ' MB'
					else:
						innum = str(format(float(i['netin']) / float(1024),'.1f')) + ' KB'
					if int(i['netout']) > 9999999:
						outnum = str(format(float(i['netout']) / float(1048576),'.1f')) + ' MB'
					else:
						outnum = str(format(float(i['netout']) / float(1024),'.1f')) + ' KB'
					i['network'] = innum + ' / '  + outnum
					if name == '101050':
						logd.sys_log_save("innum:"+str(innum),1)
						logd.sys_log_save("outnum:"+str(outnum),1)
						logd.sys_log_save("netin:"+str(i['netin']),1)
						logd.sys_log_save("netout:"+str(i['netout']),1)
				rb1.p.hmset(name,i)
        			rb1.p.expire(name,30)
			x = rb1.p.execute()
			logd.sys_log_save('get zabbix info success',1)
			time.sleep(sec)
		else:
			logd.sys_log_save('get zabbix info faild')
			time.sleep(2)