Ejemplo n.º 1
0
 def handle(self, line):
     line = line.strip('\r\n ')
     try:
         key, ts, message = line.split(':', 2)
         ts = int(ts)
     except ValueError, e:
         log.warning('%s: Malformed line: %s %r' % (self, e, line))
         return
Ejemplo n.º 2
0
 def handle(self, fd):
     while True:
         line = fd.readline()
         line = line.strip('\r\n ')
         if not line:
             break
         try:
             key, ts, message = line.split(':', 2)
             ts = int(ts)
         except ValueError, e:
             log.warning('%s: Malformed line: %s %r' % (self, e, line))
             fd.write('ERR %s\n' % str(e))
             fd.flush()
             continue
         self.process(key, ts, message)
Ejemplo n.º 3
0
 def run(self):
     log.debug('%s: Spawning %s' % (self, self.command))
     self.proc = subprocess.Popen(self.command, shell=True, bufsize=0,
                                  stdout=subprocess.PIPE)
     while True:
         line = self.proc.stdout.readline()
         if not line:
             break
         self.process(self.key, int(time.time()), line.rstrip('\r\n '))
     
     ret = self.proc.wait()
     if ret != 0:
         log.warning('%s: Exited with return code %i' % (self,
             ret))
     else:
         log.info('%s: Exited with return code %i' % (self, ret))
Ejemplo n.º 4
0
    def run(self):
        self.open_socket()
        while self.running:
            try:
                m = self.socket.recv_multipart()
            except zmq.ZMQError, e:
                break

            if len(m) != 3:
                log.warning('%s: Wrong number of parts in message: %r' % \
                    (self, m))
                continue
            else:
                key, ts, message = m
                try:
                    ts = int(ts)
                except ValueError, e:
                    log.warning('%s: Malformed line: %s' % (self, e))
                    continue
                self.process(key, int(ts), message)
Ejemplo n.º 5
0
    def handle(self, packet):
        match = self.pattern.match(packet)
        if match is None:
            log.warning('%s: Unable to parse packet: %r' % (self, packet))
            return
        msg = match.groupdict()

        prival = int(msg['prival'])
        severity = self.severities[prival % 8]
        facility = self.facilities[prival / 8]
        appname = msg['appname']
        if appname.find('[') != -1:
            appname = appname.split('[', 1)[0]
        key = '%s.%s.%s' % (appname, facility, severity)

        ts = time.strptime(msg['timestamp'], '%b %d %H:%M:%S')
        ts = int(time.mktime((time.gmtime().tm_year, ts.tm_mon, ts.tm_mday,
            ts.tm_hour, ts.tm_min, ts.tm_sec, -1, -1, -1)))

        self.process(key, ts, msg['message'])