The script to process the content of log file:
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
class PyStreamCallback(StreamCallback):
def __init__(self):
pass
def process(self, inputStream, outputStream):
text = IOUtils.toString(inputStream, StandardCharsets.UTF_8)
disconnected = text.count("Lost connection to server")
connected = text.count("Established connection to server")
newFile = 'INSERT INTO [TEST].[db_datawriter].[Test1] \
(TOTAL_DISCONNECTIONS,TOTAL_CONNECTIONS)\
VALUES (%d, %d)' % (disconnected, connected)
outputStream.write(newFile)
flowFile = session.get()
if(flowFile != None):
flowFile = session.write(flowFile, PyStreamCallback())
session.transfer(flowFile, REL_SUCCESS)
The new script I want to use to write the filename:
from org.apache.commons.io import IOUtils
from java.nio.charset import StandardCharsets
from org.apache.nifi.processor.io import StreamCallback
class PyStreamCallback(StreamCallback):
def __init__(self):
pass
def process(self, inputStream, outputStream):
fname = flowFile.getAttribute('filename')
newFile = 'INSERT INTO [TEST].[db_datawriter].[Test1] \
(CLIENT_NAME) VALUES (%d)' % fname
outputStream.write(newFile)
flowFile = session.get()
if(flowFile != None):
flowFile = session.write(flowFile, PyStreamCallback())
session.transfer(flowFile, REL_SUCCESS)
The error message in the second script shows:
<http://apache-nifi-developer-list.39713.n7.nabble.com/file/t792/error.jpg>
Any idea or help is appreciated!
--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/