def data_handler(host_dic): graph_dic = {} alert_dic = {} for h, p_index_list in host_dic.items(): # p_index stands for policy_index in enabled_policy list alert_list = [] graph_dic[h.hostname] = [] # initialize the list for p_index in set(p_index_list): p = policy.enabled_policy[p_index] # find this host belongs to which policy if monitor_dic.has_key(h.hostname): # host needs to be monitored if len(monitor_dic[h.hostname]) == 0: alert_list.append({"ServerDown": "No data received from client,is the agent or the host down"}) # print "\033[31;1mno data from client, is it done?\033[0m",h.hostname break else: print "\033[46;1m%s\033[0m" % h.hostname for service, alert_index in p.services.items(): if alert_index.graph_index["index"] is not None: graph_dic[h.hostname].append(alert_index.graph_index) #'||||' try: s = alert_handle.handle(service, alert_index, monitor_dic[h.hostname][service]) if len(s) != 0: alert_list.append(s) except KeyError: alert_list.append({"NoValidServiceData": (service, "service not exist in client datat")}) else: # host not in database or not enalbed for monitoring print "\033[34;1mnot going to monitor server:\033[0m", h.hostname if hosts.monitored_hosts.has_key(h.hostname): customized_policy = hosts.monitored_hosts[h.hostname] print "*" * 50, "Customized" # ,customized_policy.services for service, alert_index in customized_policy.services.items(): try: s = alert_handle.handle(service, alert_index, monitor_dic[h.hostname][service]) if len(s) != 0: alert_list.append(s) except KeyError: alert_list.append({"NoValidServiceData": (service, "service not exist in client datat")}) # else: # print 'no customized policy',h alert_dic[h.hostname] = alert_list print "\033[41;1m*\033[0m" * 50, "ALert LIST\n" for host, alerts in alert_dic.items(): print "\033[31;1m%s\033[0m" % host for msg in alerts: print msg # for i in alerts:print i print "\033[42;1m graph list ----------\033[0m\n" for h, g in graph_dic.items(): print h if len(g) > 0: for s in g: print s
def data_handler(host_dic): graph_dic = {} alert_dic = {} for h,p_index_list in host_dic.items(): #p_index stands for templates.index in enabled_templates.list alert_list = [] graph_dic[h.hostname] = [] #initialize the list for p_index in set(p_index_list): p = templates.enabled_templates[p_index] #find this host belongs to which template if monitor_dic.has_key(h.hostname): #host needs to be monitored if len(monitor_dic[h.hostname]) == 0: alert_list.append({"ServerDown":"No data received from client,is the agent or the host down"} ) #print "\033[31;1mno data from client, is it done?\033[0m",h.hostname break else: print "\033[46;1m%s\033[0m" % h.hostname for service,alert_index in p.services.items(): try: s = alert_handle.handle(service,alert_index, monitor_dic[h.hostname][service]) if len(s) !=0: alert_list.append(s) except KeyError: alert_list.append({"NoValidServiceData":(service,"service not exist in client data")} ) else: #host not in database or not enalbed for monitoring print "\033[34;1mnot going to monitor server:\033[0m", h.hostname if hosts.monitored_hosts.has_key(h.hostname): customized_templates= hosts.monitored_hosts[h.hostname] #print "*"*50,'Customized'#,customized_templates.services for service,alert_index in customized_templates.services.items(): try: s = alert_handle.handle(service,alert_index, monitor_dic[h.hostname][service]) if len(s) !=0:alert_list.append(s) except KeyError: alert_list.append({"NoValidServiceData":(service,"service not exist in client data")} ) #else: #print 'no customized templates.,h alert_dic[h.hostname] = alert_list #print '\033[41;1m*\033[0m'*50,'ALert LIST\n' #for host,alerts in alert_dic.items(): # print '\033[31;1m%s\033[0m' %host # for msg in alerts:print msg #for i in alerts:print i alert_dic['TimeStamp'] = time.time() redis_connector.r['TempTriAquaeAlertList'] = json.dumps(alert_dic)
def data_handler(host_dic): graph_dic = {} alert_dic = {} for h, p_index_list in host_dic.items( ): #p_index stands for policy_index in enabled_policy list alert_list = [] graph_dic[h.hostname] = [] #initialize the list for p_index in set(p_index_list): p = policy.enabled_policy[ p_index] #find this host belongs to which policy if monitor_dic.has_key(h.hostname): #host needs to be monitored if len(monitor_dic[h.hostname]) == 0: alert_list.append({ "ServerDown": "No data received from client,is the agent or the host down" }) #print "\033[31;1mno data from client, is it done?\033[0m",h.hostname break else: print "\033[46;1m%s\033[0m" % h.hostname for service, alert_index in p.services.items(): if alert_index.graph_index['index'] is not None: graph_dic[h.hostname].append( alert_index.graph_index) #'||||' try: s = alert_handle.handle( service, alert_index, monitor_dic[h.hostname][service]) if len(s) != 0: alert_list.append(s) except KeyError: alert_list.append({ "NoValidServiceData": (service, "service not exist in client datat") }) else: #host not in database or not enalbed for monitoring print "\033[34;1mnot going to monitor server:\033[0m", h.hostname if hosts.monitored_hosts.has_key(h.hostname): customized_policy = hosts.monitored_hosts[h.hostname] print "*" * 50, 'Customized' #,customized_policy.services for service, alert_index in customized_policy.services.items(): try: s = alert_handle.handle(service, alert_index, monitor_dic[h.hostname][service]) if len(s) != 0: alert_list.append(s) except KeyError: alert_list.append({ "NoValidServiceData": (service, "service not exist in client datat") }) #else: # print 'no customized policy',h alert_dic[h.hostname] = alert_list print '\033[41;1m*\033[0m' * 50, 'ALert LIST\n' for host, alerts in alert_dic.items(): print '\033[31;1m%s\033[0m' % host for msg in alerts: print msg #for i in alerts:print i print '\033[42;1m graph list ----------\033[0m\n' for h, g in graph_dic.items(): print h if len(g) > 0: for s in g: print s