bin/pvl.irker-syslog
changeset 115 9772d43669fb
parent 113 49e13576d77c
child 119 40b5375d4a27
equal deleted inserted replaced
114:2e88e1d8e604 115:9772d43669fb
    74 
    74 
    75     log.info("Process syslog messages...")
    75     log.info("Process syslog messages...")
    76 
    76 
    77     # customized mainloop that supports irker.irk
    77     # customized mainloop that supports irker.irk
    78     while True :
    78     while True :
    79         if irker.irk.recv :
    79         # syslogs
    80             reading = (irker.irk, )
       
    81         else :
       
    82             reading = ()
       
    83 
       
    84         poll = syslog.poll(reading=reading) or () # timeout -> ()
       
    85 
       
    86         if irker.irk in poll :
       
    87             # irk
       
    88             try :
       
    89                 for msg in irker.irk :
       
    90                     log.info("irk: %s", msg)
       
    91 
       
    92             except EOFError :
       
    93                 # exit
       
    94                 log.error("irk: EOF")
       
    95                 return 1
       
    96 
       
    97         # syslogs, even on timeout
       
    98         for item in syslog :
    80         for item in syslog :
    99             match, rulepath, apply = rules.apply(item)
    81             match, rulepath, apply = rules.apply(item)
   100             
    82             
   101             log.debug("%s: %s: %s", item, rulepath, apply)
    83             log.debug("%s: %s: %s", item, rulepath, apply)
   102             
    84             
   113             
    95             
   114             if irker and target :
    96             if irker and target :
   115                 irker[target]('[' + tag + '] ' + text)
    97                 irker[target]('[' + tag + '] ' + text)
   116             else :
    98             else :
   117                 print tag, text
    99                 print tag, text
   118         
   100 
       
   101         # only poll if we have something to poll
       
   102         if syslog.poll :
       
   103             # can we poll irk?
       
   104             if irker.irk.recv :
       
   105                 reading = (irker.irk, )
       
   106             else :
       
   107                 reading = ()
       
   108             
       
   109             poll = syslog.select(syslog.poll, reading=reading) or () # timeout -> ()
       
   110 
       
   111             if irker.irk in poll :
       
   112                 # irk
       
   113                 try :
       
   114                     for msg in irker.irk :
       
   115                         log.info("irk: %s", msg)
       
   116 
       
   117                 except EOFError :
       
   118                     # exit
       
   119                     log.error("irk: EOF")
       
   120                     return 1
       
   121             
       
   122             # keep going
       
   123             continue
       
   124 
       
   125         else :
       
   126             break
       
   127        
   119     # done
   128     # done
   120     log.info("Exiting...")
   129     log.info("Exiting...")
   121     return 0
   130     return 0
   122 
   131 
   123 if __name__ == '__main__':
   132 if __name__ == '__main__':