Пример #1
0
    def doCheck(self):
        logging.debug("Checking: %s" % self.name)
        try:
            con = httplib2.Http()
            start = time.time()
            resp, cont = con.request(self.url)
            self.loadtime = (time.time() - start) * 1000
        except httplib2.ServerNotFoundError:
            self.status = WebPage.OFFLINE
            logging.debug("OFFLINE by not found")
            return
        except socket.error:
            self.status = WebPage.OFFLINE
            logging.deubg("OFFLINE by socket error")
            return

        if resp["status"] == "200":
            self.status = WebPage.WRONG_ANSWER
            if self.criteria.search(cont) or not self.criteria:
                self.status = WebPage.ONLINE
        else:
            logging.debug("OFFLINE by status number: %s" % (resp["status"]))
            self.status = WebPage.OFFLINE
Пример #2
0
def process_ceilometer_message(sample,data):
    logging.debug("%s",sample)
    #logging.info("%s",sample)
    if len(sub_info) < 1:
        #print  "No subscription exists"
        return
    for obj in sub_info:
         #import pdb;pdb.set_trace()
         msg_list = []
         if type(obj.subscription_info) is list:
             for info in obj.subscription_info:
                 msg_list.append(fnmatch.fnmatch(sample['counter_name'],info))
         else :
             msg_list.append(fnmatch.fnmatch(sample['counter_name'],obj.subscription_info))
         try:
             if reduce(operator.or_, msg_list):
                 kafka_publisher = None
                 if obj.scheme == "kafka" :
		    parse_target=netutils.urlsplit(obj.target)
	            try :
		        kafka_publisher=kafka_broker.KafkaBrokerPublisher(parse_target)
                    except Exception as e:
                        logging.error("* Error in connecting kafka broker:%s",e.__str__())
                       # return False
                        continue 
                 host = obj.ipaddress
                 port = int(obj.portno)
                 l=[]
                 logging.debug("* -------------------------------------------------------")
                 if obj.sub_info_filter is None:
                     try:
                         if obj.scheme == "udp" :
                              logging.debug("* Sending data without query over UDP for host:%s and port:%s",host,port)
                              logging.info("* Sending data without query over UDP for host:%s and port:%s",host,port)
                              udp = socket.socket(socket.AF_INET, # Internet
                                                   socket.SOCK_DGRAM) # UDP
                              udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) 
                              udp.sendto(data,(host,port))
                              #return True
                              continue
                         elif obj.scheme == "kafka" :
                              logging.debug("* Sending data over kafka for host:%s and port:%s and topec:%s",host,port,kafka_publisher.topic)
                              logging.info("* Sending data over kafka for host:%s and port:%s and topec:%s",host,port,kafka_publisher.topic)
                              kafka_publisher._send(sample)  
                              #return True
                              continue                                  
                     except Exception as e:
                          logging.error ("Unable to send sample over UDP/kafka for %s and %s,%s",host,port,e.__str__())
                          ret_str = ("Unable to send sample over UDP for %s and %s,%s ")%(host,port,e.__str__())
                          #return False
                          continue 
                 for i in range(len(obj.sub_info_filter)):
                     if obj.sub_info_filter[i]['op'] in COMPARATORS:
                          op = COMPARATORS[obj.sub_info_filter[i]['op']]
                          logging.debug("* obj.sub_info_filter[i]['value']:%s",obj.sub_info_filter[i]['value'])
                          logging.debug("* obj.sub_info_filter[i]['field']:%s",obj.sub_info_filter[i]['field'])
                          l.append(op(obj.sub_info_filter[i]['value'],sample[obj.sub_info_filter[i]['field']]))
                          logging.info("* Logical and of Query %s",l)
                     else:
                          logging.deubg("* Not a valid operator ignoring app_id:%s",obj.app_id)
                          l.append(False)
                          logging.info("* Logical and of Query %s",l)
                     if reduce(operator.and_, l):
                         try:
                             if obj.scheme == "udp" :
                                  logging.debug("* Sending data over UDP for host:%s and port:%s",host,port)
                                  udp = socket.socket(socket.AF_INET, # Internet
                                                       socket.SOCK_DGRAM) # UDP
                                  udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
                                  udp.sendto(data,(host,port))
                                  #return True
                                  continue
                             elif obj.scheme == "kafka" :
                                  logging.debug("* Sending data over kafka for host:%s and port:%s and topec:%s",host,port,kafka_publisher.topic)
                                  kafka_publisher._send(sample)  
                                  #return True
                                  continue                                  
                         except Exception:
                             logging.error ("Unable to send sample over UDP/Kafka for %s and %s ",host,port)
                             ret_str = ("Unable to send sample over UDP/Kafka for %s and %s ")%(host,port)
                             #return False
                             continue   
                     else :
		           logging.warning("* No Notification found with the given subscription")
                           continue
             else :
                  logging.warning("* No valid subscrition found for %s",obj.app_id)
                  continue
         except Exception as e:
             logging.error("Key_Error:%s ",e.__str__())
             ret_str = ("Key_Error:%s \n")%e.__str__()
             #return False
             continue
Пример #3
0
def read_notification_from_ceilometer(host,port):
     UDP_IP = host 
     UDP_PORT = port
 
     logging.debug("* Sarting UDP Client on ip:%s , port:%d",UDP_IP,UDP_PORT) 
     udp = socket.socket(socket.AF_INET, # Internet
                          socket.SOCK_DGRAM) # UDP
     udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

     udp.bind((UDP_IP, UDP_PORT))
     
     while True:
            #print thread.get_ident() 
            #logging.debug("thread.get_ident():%s", thread.get_ident()) 
            data, source = udp.recvfrom(64 * units.Ki)
            sample = msgpack.loads(data, encoding='utf-8')
            #logging.debug("* -------------------------------------------------------")
            logging.debug("%s",sample)
            #print(sample)
            for obj in sub_info:
                msg_list = []
                if obj.scheme == "udp" :
                    if type(obj.subscription_info) is list:
                        for info in obj.subscription_info:
                            msg_list.append(fnmatch.fnmatch(sample['counter_name'],info))
                    else :
                        msg_list.append(fnmatch.fnmatch(sample['counter_name'],obj.subscription_info)) 
                    try:  
                        if reduce(operator.or_, msg_list): 
                            host = obj.ipaddress
                            port = int(obj.portno)
                            l=[]
                            #logging.debug("* -------------------------------------------------------")
                            if obj.sub_info_filter is None:
                                try:  
                                    logging.debug("* Sending data without query over UDP for host:%s and port:%s",host,port) 
                                    udp.sendto(data,(host,port))
                                except Exception as e:
                                    logging.error ("Unable to send sample over UDP for %s and %s,%s",host,port,e.__str__())
                                    ret_str = ("Unable to send sample over UDP for %s and %s,%s")%(host,port,e.__str__())
                                continue 
                            for i in range(len(obj.sub_info_filter)):
                                if obj.sub_info_filter[i]['op'] in COMPARATORS:
                                    op = COMPARATORS[obj.sub_info_filter[i]['op']]
                                    logging.debug("* obj.sub_info_filter[i]['value']:%s",obj.sub_info_filter[i]['value'])
                                    logging.debug("* obj.sub_info_filter[i]['field']:%s",obj.sub_info_filter[i]['field'])
                                    l.append(op(obj.sub_info_filter[i]['value'],sample[obj.sub_info_filter[i]['field']]))
                                    logging.info("* Logical and of Query %s",l)    
                                else:
                                    logging.deubg("* Not a valid operator ignoring app_id:%s",obj.app_id)
                                    l.append(False)
                                    logging.info("* Logical and of Query %s",l)    
                            if reduce(operator.and_, l):
                                try:  
                                    logging.debug("* Sending data over UDP for host:%s and port:%s",host,port) 
                                    udp.sendto(data,(host,port))
                                except Exception:
                                    logging.error ("Unable to send sample over UDP for %s and %s ",host,port)
                                    ret_str = ("Unable to send sample over UDP for %s and %s ")%(host,port)
                            else :
                                 logging.warning("* No Notification found with the given subscription")
                        else :
                            logging.warning("* No valid subscrition found for %s",obj.app_id)
                    except Exception as e:
                       logging.error("Key_Error:%s ",e.__str__())
                       ret_str = ("Key_Error:%s \n")% e.__str__()
Пример #4
0
def read_notification_from_ceilometer(host, port):
    UDP_IP = host
    UDP_PORT = port

    logging.debug("* Sarting UDP Client on ip:%s , port:%d", UDP_IP, UDP_PORT)
    udp = socket.socket(
        socket.AF_INET,  # Internet
        socket.SOCK_DGRAM)  # UDP
    udp.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

    udp.bind((UDP_IP, UDP_PORT))

    while True:
        #print thread.get_ident()
        #logging.debug("thread.get_ident():%s", thread.get_ident())
        data, source = udp.recvfrom(64 * units.Ki)
        sample = msgpack.loads(data, encoding='utf-8')
        #logging.debug("* -------------------------------------------------------")
        logging.debug("%s", sample)
        #print(sample)
        for obj in sub_info:
            msg_list = []
            if obj.scheme == "udp":
                if type(obj.subscription_info) is list:
                    for info in obj.subscription_info:
                        msg_list.append(
                            fnmatch.fnmatch(sample['counter_name'], info))
                else:
                    msg_list.append(
                        fnmatch.fnmatch(sample['counter_name'],
                                        obj.subscription_info))
                try:
                    if reduce(operator.or_, msg_list):
                        host = obj.ipaddress
                        port = int(obj.portno)
                        l = []
                        #logging.debug("* -------------------------------------------------------")
                        if obj.sub_info_filter is None:
                            try:
                                logging.debug(
                                    "* Sending data without query over UDP for host:%s and port:%s",
                                    host, port)
                                udp.sendto(data, (host, port))
                            except Exception as e:
                                logging.error(
                                    "Unable to send sample over UDP for %s and %s,%s",
                                    host, port, e.__str__())
                                ret_str = (
                                    "Unable to send sample over UDP for %s and %s,%s"
                                ) % (host, port, e.__str__())
                            continue
                        for i in range(len(obj.sub_info_filter)):
                            if obj.sub_info_filter[i]['op'] in COMPARATORS:
                                op = COMPARATORS[obj.sub_info_filter[i]['op']]
                                logging.debug(
                                    "* obj.sub_info_filter[i]['value']:%s",
                                    obj.sub_info_filter[i]['value'])
                                logging.debug(
                                    "* obj.sub_info_filter[i]['field']:%s",
                                    obj.sub_info_filter[i]['field'])
                                l.append(
                                    op(obj.sub_info_filter[i]['value'], sample[
                                        obj.sub_info_filter[i]['field']]))
                                logging.info("* Logical and of Query %s", l)
                            else:
                                logging.deubg(
                                    "* Not a valid operator ignoring app_id:%s",
                                    obj.app_id)
                                l.append(False)
                                logging.info("* Logical and of Query %s", l)
                        if reduce(operator.and_, l):
                            try:
                                logging.debug(
                                    "* Sending data over UDP for host:%s and port:%s",
                                    host, port)
                                udp.sendto(data, (host, port))
                            except Exception:
                                logging.error(
                                    "Unable to send sample over UDP for %s and %s ",
                                    host, port)
                                ret_str = (
                                    "Unable to send sample over UDP for %s and %s "
                                ) % (host, port)
                        else:
                            logging.warning(
                                "* No Notification found with the given subscription"
                            )
                    else:
                        logging.warning("* No valid subscrition found for %s",
                                        obj.app_id)
                except Exception as e:
                    logging.error("Key_Error:%s ", e.__str__())
                    ret_str = ("Key_Error:%s \n") % e.__str__()