Tina,

My apologies - I was conflating ExecuteScript with ExecuteStreamCommand.
In ExecuteStream, the contents of the FlowFile are not read from StdIn but 
rather
you'd want to use the session to read the contents. So in Groovy we'd do 
something like:

import org.apache.nifi.processors.script.ExecuteScript
def flowFile = session.get()
def in = session.read(flowFile)
def totalDisconnections = 0
def totalConnections = 0

try {
// Here, 'in' is the InputStream that contains the data
finally {
in.close()
}

flowFile = session.putAttribute("TOTAL_DISCONNECTIONS", totalDisconnections)
flowFile = session.putAttribute("TOTAL_CONNECTIONS", totalConnections)
session.transfer(flowFile, ExecuteScript.REL_SUCCESS)

Sorry, I am not familiar enough with Python to provide any sort of meaningful 
suggestions on what
to do there.

Thanks
-Mark



On Nov 10, 2017, at 4:01 PM, tzhu 
<[email protected]<mailto:[email protected]>> wrote:

Hi Mark,

This is the script I'm using currently:

import sys
TOTAL_DISCONNECTIONS = 0
TOTAL_CONNECTIONS = 0
flowFile = sys.stdin
if (flowFile != None):
   for line in flowFile:
       if "Lost connection to server" in line:
           TOTAL_DISCONNECTIONS += 1
       if "Established connection to server" in line:
            TOTAL_CONNECTIONS += 1
attrMap = {"TOTAL_DISCONNECTIONS":TOTAL_DISCONNECTIONS,
          "TOTAL_CONNECTIONS":TOTAL_CONNECTIONS}
flowFile = session.putAllAttributes(flowFile, attrMap)



Does it make sense to you? The error message says "filereader" object is not
iterable. So what is in flowFile now? How should I access the content in
filwFile?

Thanks,

Tina



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/

Reply via email to