Problem with RosieL_match_file() call from Python
Created by: yausteve-ibm
Hi, Jamie, I tried calling RosieL_match_file() from Python but did not get the expected result. Here's what I did:
-
Added the following to rosie-pattern-language/ffi/samples/python/rosie.py: def match_file(self, input, output, error, wholefileflag): return self._match_file(input, output, error, wholefileflag, self.rosie.rosie.rosieL_match_file)
def _match_file(self, input, output, error, wholefileflag, operation): input_file_string = to_cstr_ptr(self.rosie.rosie, input) output_file_string = to_cstr_ptr(self.rosie.rosie, output) error_file_string = to_cstr_ptr(self.rosie.rosie, error) flag_string = to_cstr_ptr(self.rosie.rosie, wholefileflag) r = operation(self.engine, input_file_string, output_file_string, error_file_string, flag_string); retvals = self.rosie.get_retvals(r) return retvals
-
In my python program "test.py" , I called match_file(): import os, json, sys import rosie ........ Rosie = rosie.initialize(ROSIE_HOME, ROSIE_HOME + "/ffi/librosie/librosie.so") engine = Rosie.engine() r = engine.load_manifest("$sys/MANIFEST") config = json.dumps( {'expression': 'linuxsys.matchall', 'encode':'json'} ) r = engine.configure(config) r = engine.match_file("testfile", "", "std.err", "true")
"testfile" has two lines: Aug 20 18:18:10 beatrice-desktop dhclient[1354]: DHCPREQUEST of 192.168.8.14 on enp0s31f6 to 192.168.8.1 port 67 (xid=0x2830f2c) Aug 20 20:14:09 beatrice-desktop dhclient[1354]: DHCPACK of 192.168.8.14 from 192.168.8.1
When I execute test.py, it seems to match only the first line and then stop. i.e. it didn't iterate through the rest of the file: $ python test.py {"linuxsys.matchall":{"subs":[{"linuxsys.log36":{"subs":[{"linuxsys.prefix":{"subs":[{"basic.datetime_patterns":{"subs":[{"datetime.shortdate":{"text":"Aug 20 ","pos":1}}],"text":"Aug 20 ","pos":1}},{"basic.datetime_patterns":{"subs":[{"datetime.simple_time":{"text":"18:18:10 ","pos":8}}],"text":"18:18:10 ","pos":8}},{"common.identifier_not_word":{"text":"beatrice-desktop","pos":17}}],"text":"Aug 20 18:18:10 beatrice-desktop","pos":1}},{"linuxsys.l5":{"text":"dhclient","pos":34}},{"basic.punctuation":{"text":"[","pos":42}},{"common.number":{"subs":[{"common.int":{"text":"1354","pos":43}}],"text":"1354","pos":43}},{"basic.punctuation":{"text":"]","pos":47}},{"basic.punctuation":{"text":":","pos":48}},{"common.maybe_identifier":{"text":"DHCPREQUEST","pos":50}},{"linuxsys.l6":{"text":"of","pos":62}},{"basic.network_patterns":{"subs":[{"network.ip_address":{"text":"192.168.8.14","pos":65}}],"text":"192.168.8.14","pos":65}},{"linuxsys.l7":{"text":"on","pos":78}},{"common.identifier_not_word":{"text":"enp0s31f6","pos":81}},{"linuxsys.l8":{"text":"to","pos":91}},{"basic.network_patterns":{"subs":[{"network.ip_address":{"text":"192.168.8.1","pos":94}}],"text":"192.168.8.1","pos":94}},{"linuxsys.l9":{"text":"port","pos":106}},{"common.number":{"subs":[{"common.int":{"text":"67","pos":111}}],"text":"67","pos":111}},{"basic.punctuation":{"text":"(","pos":114}},{"linuxsys.l10":{"text":"xid","pos":115}},{"basic.punctuation":{"text":"=","pos":118}},{"common.number":{"subs":[{"common.denoted_hex":{"subs":[{"common.hex":{"text":"2830f2c","pos":121}}],"text":"0x2830f2c","pos":119}}],"text":"0x2830f2c","pos":119}},{"basic.punctuation":{"text":")","pos":128}}],"text":"Aug 20 18:18:10 beatrice-desktop dhclient[1354]: DHCPREQUEST of 192.168.8.14 on enp0s31f6 to 192.168.8.1 port 67 (xid=0x2830f2c)","pos":1}}],"text":"Aug 20 18:18:10 beatrice-desktop dhclient[1354]: DHCPREQUEST of 192.168.8.14 on enp0s31f6 to 192.168.8.1 port 67 (xid=0x2830f2c)","pos":1}} Garbage collecting engine 118c5a0
When I use the CLI by "rosie linuxsys.matchall testfile", it matches all the lines: $ rosie linuxsys.matchall testfile Aug 20 18:18:10 beatrice-desktop dhclient [ 1354 ] : DHCPREQUEST of 192.168.8.14 on enp0s31f6 to 192.168.8.1 port 67 ( xid = 2830f2c ) Aug 20 20:14:09 beatrice-desktop dhclient [ 1354 ] : DHCPACK of 192.168.8.14 from 192.168.8.1
I expected when I set "wholefileflag" to true in r = engine.match_file("testfile", "", "std.err", "true"), it would iterate through all the lines of "testfile". Somehow, it didn't.
I can't figure out what I have missed. Appreciate your advice. Many thanks!