Using the ExecuteScript processor

The ExecuteScript processor runs an external stateless script on each processor run, allowing simpler integration. Learn how to use it to integrate custom code into a MiNiFi C++ agent.

When using the ExecuteScript processor, you need to add a Python script on the agents' file systems, and point the ExecuteScript processor to use that script. For more information on how you can send files to agents to be used on the agents, see Using Asset Push command. On each execution, the Python script is evaluated, and its onTrigger function is called to receive any incoming flow files and to produce the output.

This is an example script that reverses the content of flow files:

#!/usr/bin/env python
                import codecs
                import time
                
                
                class ReadCallback:
                def process(self, input_stream):
                self.content = codecs.getreader('utf-8')(input_stream).read()
                return len(self.content)
                
                
                class WriteReverseStringCallback:
                def __init__(self, content):
                self.content = content
                
                def process(self, output_stream):
                reversed_content = self.content[::-1]
                output_stream.write(reversed_content.encode('utf-8'))
                return len(reversed_content)
                
                
                def onTrigger(context, session):
                flow_file = session.get()
                if flow_file is not None:
                read_callback = ReadCallback()
                session.read(flow_file, read_callback)
                session.write(flow_file, WriteReverseStringCallback(read_callback.content))
                flow_file.addAttribute('python_timestamp', str(int(time.time())))
                session.transfer(flow_file, REL_SUCCESS)