Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

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
Contributor

@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
Contributor

@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.