<html><head><style>body{font-family:Helvetica,Arial;font-size:13px}</style></head><body style="word-wrap:break-word;line-break:after-white-space"><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">Hi Steve,</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">I tried it but the problem still only shows up when it runs as a plugin.   Also, the script basically does some processing on the records and extracts certain data from records of interest, so it should run fine regardless of the input source.  It seems to fail immediately when run as a plugin.  Any other suggestions on troubleshooting the discepancy?</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto">PS.  I also read your very useful auditd tutorials over here - <a href="https://security-plus-data-science.blogspot.com/">https://security-plus-data-science.blogspot.com/</a> Thanks.</div><div id="bloop_customfont" style="font-family:Helvetica,Arial;font-size:13px;color:rgba(0,0,0,1.0);margin:0px;line-height:auto"><br></div> <div id="bloop_sign_1536326090174667776" class="bloop_sign"><div style="font-family:helvetica,arial;font-size:13px">-- <br>Osama Elnaggar<br></div></div> <br><p class="airmail_on">On September 7, 2018 at 10:57:05 PM, Steve Grubb (<a href="mailto:sgrubb@redhat.com">sgrubb@redhat.com</a>) wrote:</p> <blockquote type="cite" class="clean_bq"><span><div><div></div><div>On Friday, September 7, 2018 7:30:09 AM EDT Osama Elnaggar wrote:
<br>> Hi,
<br>>  
<br>> I'm working on a custom audispd plugin written in Python 3.  It’s a work in
<br>> progress and I’ve successfully run it numerous times as an audispd plugin.
<br>> However, I sometimes make modifications that result in the audispd plugin
<br>> failing and I end up with the following in /var/log/syslog
<br>>  
<br>> Sep  6 20:52:05 ubuntu-hypervisor audispd: plugin /usr/bin/python3
<br>> terminated unexpectedly
<br>> Sep  6 20:52:05 ubuntu-hypervisor audispd: plugin /usr/bin/python3 was
<br>> restarted
<br>> ...
<br>>  
<br>> This is repeated several times until audispd gives up and I see the
<br>> following message:
<br>>  
<br>> Sep  6 20:52:14 ubuntu-hypervisor audispd: plugin /usr/bin/python3 has
<br>> exceeded max_restarts
<br>>  
<br>> To troubleshoot, I modify my code to read from /var/log/audit/audit.log
<br>> instead.  I modify a single line (with fileinput.input() to read from
<br>> myfile as shown in the commented line below).
<br>>  
<br>> Here is the code snippet (a colorized easier to read version is available
<br>> here - <a href="https://pastebin.com/84Nxu3Rp">https://pastebin.com/84Nxu3Rp</a>):
<br>>  
<br>> # let us initialize the AuParser
<br>> aup = auparse.AuParser(auparse.AUSOURCE_FEED)
<br>>  
<br>> # we initalize the callback to be fn_process_event
<br>> aup.add_callback(fn_process_event, None, None)
<br>>  
<br>> myfile = "/var/log/audit/audit.log"
<br>>  
<br>> while True:
<br>>     try:
<br>>         # we read in line by line from stdin
<br>>         for line in fileinput.input():
<br>>         #for line in fileinput.input(myfile):
<br>>             aup.feed(line)
<br>>     except:
<br>>         logger.error("Fatal error in while loop", exc_info=True)
<br>>  
<br>> # we flush the feed when we quit
<br>> aup.flush_feed()
<br>>  
<br>> Any suggestions on how to troubleshoot these types of issues when reading
<br>> from a file works fine without issue but running it as a plugin fails as
<br>> shown in /var/log/syslog?  Thanks.
<br>
<br>All plugins have a requirement to take events from stdin. As long as it  
<br>expects strings (which is the way that auparse wants them), then all you have  
<br>to do is:
<br>
<br>ausearch --start boot --raw | ./plugin
<br>
<br>You can also save raw logs with ausearch and cat them into the plugin. This  
<br>is helpful when you get a problem down to a certain series of events and you  
<br>don't want to go through a thousand events before the problem sequence.
<br>
<br>-Steve
<br>
<br>
<br>
<br></div></div></span></blockquote></body></html>