Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

NIFI : Monitoring

avatar
Rising Star

Hi all,

I've read this tuto : Logging

So anybody has simple example of python script to write data from ExtracText processor to ExecuteScript processor ?

How extract flowfile name as argument to my script python ?

10809-logging-nifi.jpg

1 ACCEPTED SOLUTION

avatar
New Member

@mayki wogno user defined arguments aren't really sent to ExecuteScript. If the value of the `filename` attribute is needed, it can be retrieved from the flow file itself. Below is an example of how to retrieve the `filename` attribute, update the attribute, and send the flow file to a `success` relationship.

flowFile = session.get()
if (flowFile != None):
  filename = flowFile.getAttribute("filename")
  flowFile = session.putAttribute(flowFile, "filename", filename + "new_name")
  session.transfer(flowFile, REL_SUCCESS)

For an example that is a little more in depth, you can download a template from this gist.

For a deeper look into developing with NiFi, please see the developer's guide.

View solution in original post

2 REPLIES 2

avatar
Rising Star

@mayki wogno

It should already be available in your script, if you use this:

flowFile = session.get()
flowFile.getAttribute('filename')

This should return your filename in your executeScript.

avatar
New Member

@mayki wogno user defined arguments aren't really sent to ExecuteScript. If the value of the `filename` attribute is needed, it can be retrieved from the flow file itself. Below is an example of how to retrieve the `filename` attribute, update the attribute, and send the flow file to a `success` relationship.

flowFile = session.get()
if (flowFile != None):
  filename = flowFile.getAttribute("filename")
  flowFile = session.putAttribute(flowFile, "filename", filename + "new_name")
  session.transfer(flowFile, REL_SUCCESS)

For an example that is a little more in depth, you can download a template from this gist.

For a deeper look into developing with NiFi, please see the developer's guide.