Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

import re 

from base_filter import BaseFilter 

 

 

class WordFilter(BaseFilter): 

    """ accepts only if line contains any of the words specified by --word  

    """ 

 

    filterArgs = [ 

        ('--word', {'action':'store', 'nargs':'*', 'help':'only output lines matching any of WORD'}), 

    ] 

 

    def __init__(self, mlogfilter): 

        BaseFilter.__init__(self, mlogfilter) 

 

        # extract all arguments passed into 'word' 

        if 'word' in self.mlogfilter.args and self.mlogfilter.args['word']: 

            self.words = self.mlogfilter.args['word'].split() 

            self.active = True 

        else: 

            self.active = False 

 

    def accept(self, logevent): 

        for word in self.words: 

            if re.search(word, logevent.line_str): 

                return True 

        return False