Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

NIFI : Monitoring

Solved Go to solution
Highlighted

NIFI : Monitoring

Explorer

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

Accepted Solutions
Highlighted

Re: NIFI : Monitoring

Explorer

@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

Re: NIFI : Monitoring

Contributor

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

Highlighted

Re: NIFI : Monitoring

Explorer

@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

Don't have an account?
Coming from Hortonworks? Activate your account here