Пример #1
0
    def test_reformat_pattern(self):
        '''
        test reformat_pattern API.
        '''
        print("test_reformat_pattern")
        test_pattern = "(w:<name>) is (w:<attribute>)"
        matchpat = "(?P<name>\w+) is (?P<attribute>\w+)"
        rexpat = rex.reformat_pattern(test_pattern)
        self.failUnless(rexpat == matchpat)

        test_pattern = "(d:<number>),testst_-(w:<name>), xyz(W:<attr>),(<foo>)"
        matchpat = "(?P<number>\d+),testst_-(?P<name>\w+), " \
            "xyz(?P<attr>\W+),(?P<foo>.*)"

        rexpat = rex.reformat_pattern(test_pattern)
        self.failUnless(rexpat == matchpat)

        test_pattern = "(d:<number>), IP: (ip:<ipaddr>),.*"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)

        test_pattern = "(d:<number>), dec: (decimal:<number>)"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)

        test_pattern = "(measurement:<heat>), val=(measurement:<energy>)"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)
Пример #2
0
    def test_reformat_pattern(self):
        '''
        test reformat_pattern API.
        '''
        print("test_reformat_pattern")
        test_pattern = "(w:<name>) is (w:<attribute>)"
        matchpat = "(?P<name>\w+) is (?P<attribute>\w+)"
        rexpat = rex.reformat_pattern(test_pattern)
        self.failUnless(rexpat == matchpat)

        test_pattern = "(d:<number>),testst_-(w:<name>), xyz(W:<attr>),(<foo>)"
        matchpat = "(?P<number>\d+),testst_-(?P<name>\w+), " \
            "xyz(?P<attr>\W+),(?P<foo>.*)"

        rexpat = rex.reformat_pattern(test_pattern)
        self.failUnless(rexpat == matchpat)

        test_pattern = "(d:<number>), IP: (ip:<ipaddr>),.*"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)

        test_pattern = "(d:<number>), dec: (decimal:<number>)"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)

        test_pattern = "(measurement:<heat>), val=(measurement:<energy>)"
        rexpat = rex.reformat_pattern(test_pattern)
        print("rexpat: ", rexpat)
Пример #3
0
    def match_timestamp(self, pattern, teststr, isvalid=True):
        '''
        Generic function for timestamp match test.
        '''
        rexpat = rex.reformat_pattern(pattern)
        print "String: ", teststr
        print "REXPATTERN: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "matched: ", mobj.group(1)
Пример #4
0
    def match_timestamp(self, pattern, teststr, isvalid=True):
        '''
        Generic function for timestamp match test.
        '''
        rexpat = rex.reformat_pattern(pattern)
        print "String: ", teststr
        print "REXPATTERN: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "matched: ", mobj.group(1)
Пример #5
0
    def test_match_ipaddr_invalid(self):
        '''
        Match: invalid ipaddr pattern
        '''
        teststring = "13 06:25:06 m001d haproxy[37217]: 310.41.1.4344:43238 xy"
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "Matched: ", mobj.group(0)
Пример #6
0
    def test_match_decimal(self):
        '''
        Match a decimal pattern
        '''
        teststring = "avg=43.43, 90.43, time=44.290 val=0.43"
        pattern = "avg=(decimal:<average>), (decimal:<val2>), time=(decimal:<time>) val=(decimal:<val3>)"

        rexpat = rex.reformat_pattern(pattern)

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "matched: ", mobj.groups(0)
            print "avg: ", mobj.group('average')
Пример #7
0
    def test_match_ipaddr_invalid(self):
        '''
        Match: invalid ipaddr pattern
        '''
        teststring = "13 06:25:06 m001d haproxy[37217]: 310.41.1.4344:43238 xy"
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "Matched: ", mobj.group(0)
Пример #8
0
    def test_match_decimal(self):
        '''
        Match a decimal pattern
        '''
        teststring = "avg=43.43, 90.43, time=44.290 val=0.43"
        pattern = "avg=(decimal:<average>), (decimal:<val2>), time=(decimal:<time>) val=(decimal:<val3>)"

        rexpat = rex.reformat_pattern(pattern)

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "matched: ", mobj.groups(0)
            print "avg: ", mobj.group('average')
Пример #9
0
    def test_match_measurement_compile(self):
        '''
        Match a measurement pattern.
        <vaule>KB, <value>KB/sec
        '''
        teststring = "read : io=144KB, bw=98KB/s, iops=741, runt= 10007msec"
        pattern = "read.*io=(measurement:<io>),.*bw=(measurement:<bw>),.*" \
            "iops=(d:<iops>),.*runt= (measurement:<runtime>)"

        rexpat = rex.reformat_pattern(pattern, compile=True)
        mobj = rexpat.match(teststring)
        if mobj:
            print "matched: ", mobj.groups(0)
            print "iops: ", mobj.group('io'), mobj.group('io_unit')
            print "bw: ", mobj.group('bw'), mobj.group('bw_unit')
Пример #10
0
    def test_match_ipaddr(self):
        '''
        Match ipaddr pattern
        '''
        teststring = "13 06:25:06 m001d haproxy[37217]: 10.163.41.1:55238 "
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "Matched: ", mobj.group(0)
            print "ipaddr: ", mobj.group('ipaddr')
            print "port: ", mobj.group('port')
Пример #11
0
    def test_match_ts2(self):
        '''
        Test the timestamp match functionality.
        '''
        teststr = "2015-11-13 Fri 12:47:01:041.992 PST  gngsvm001d [Thread 140217231050496, Pid 41480]"
        pattern = ".*(ts2:<timestamp>)"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "Matched: ", mobj.group(1)
            print "year: ", mobj.group(2)
            print "month: ", mobj.group(3)
Пример #12
0
    def test_match_ipaddr(self):
        '''
        Match ipaddr pattern
        '''
        teststring = "13 06:25:06 m001d haproxy[37217]: 10.163.41.1:55238 "
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststring)
        if mobj:
            print "Matched: ", mobj.group(0)
            print "ipaddr: ", mobj.group('ipaddr')
            print "port: ", mobj.group('port')
Пример #13
0
    def test_match_measurement_compile(self):
        '''
        Match a measurement pattern.
        <vaule>KB, <value>KB/sec
        '''
        teststring = "read : io=144KB, bw=98KB/s, iops=741, runt= 10007msec"
        pattern = "read.*io=(measurement:<io>),.*bw=(measurement:<bw>),.*" \
            "iops=(d:<iops>),.*runt= (measurement:<runtime>)"

        rexpat = rex.reformat_pattern(pattern, compile=True)
        mobj = rexpat.match(teststring)
        if mobj:
            print "matched: ", mobj.groups(0)
            print "iops: ", mobj.group('io'), mobj.group('io_unit')
            print "bw: ", mobj.group('bw'), mobj.group('bw_unit')
Пример #14
0
    def test_match_ts2(self):
        '''
        Test the timestamp match functionality.
        '''
        teststr = "2015-11-13 Fri 12:47:01:041.992 PST  gngsvm001d [Thread 140217231050496, Pid 41480]"
        pattern = ".*(ts2:<timestamp>)"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "Matched: ", mobj.group(1)
            print "year: ", mobj.group(2)
            print "month: ", mobj.group(3)
Пример #15
0
    def test_ipaddr_parse(self):
        '''
        Test parsing ip addr.
        '''
        fhandle = open("test_data/haproxy_output.txt", "r")
        data = fhandle.read()

        # Get the ipaddress and port no from the output.
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        for mobj in re.finditer(rexpat, data):
            print "IP ADDR: %s, PORT: %s" % \
                (mobj.group(1), mobj.group(2))
Пример #16
0
    def test_ipaddr_parse(self):
        '''
        Test parsing ip addr.
        '''
        fhandle = open("test_data/haproxy_output.txt", "r")
        data = fhandle.read()

        # Get the ipaddress and port no from the output.
        pattern = ".* (ip:<ipaddr>):(d:<port>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        for mobj in re.finditer(rexpat, data):
            print "IP ADDR: %s, PORT: %s" % \
                (mobj.group(1), mobj.group(2))
Пример #17
0
    def test_match_ts1(self):
        '''
        Test the timestamp match functionality
        '''
        teststr = "2015-11-13 06:38:04.571 23441 INFO nova.openstack.common.service [-] Child 28349 killed by signal 9"
        pattern = ".*(ts1:<timestamp>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "Matched: ", mobj.group(0)
            print "year: ", mobj.group(2)
            print "Month: ", mobj.group(3)
            print "date: ", mobj.group(4)
            print "hour: ", mobj.group(5)
            print "min: ", mobj.group(6)
            print "sec: ", mobj.group(7)
            print "msec: ", mobj.group(8)
Пример #18
0
    def test_match_ts1(self):
        '''
        Test the timestamp match functionality
        '''
        teststr = "2015-11-13 06:38:04.571 23441 INFO nova.openstack.common.service [-] Child 28349 killed by signal 9"
        pattern = ".*(ts1:<timestamp>).*"

        rexpat = rex.reformat_pattern(pattern)
        print "REXPAT: ", rexpat

        mobj = re.match(rexpat, teststr)
        if mobj:
            print "Matched: ", mobj.group(0)
            print "year: ", mobj.group(2)
            print "Month: ", mobj.group(3)
            print "date: ", mobj.group(4)
            print "hour: ", mobj.group(5)
            print "min: ", mobj.group(6)
            print "sec: ", mobj.group(7)
            print "msec: ", mobj.group(8)