|
In many occasions you will need to read data from a file and process this information. RapidCMDB provides RSFileReader.groovy in the RS_HOME/RapidSuite/scripts directory to address this need. You can have your script :
The provided RSFileReader currently supports parsing each line for:
RSFileReader.groovy can be modified to alter behavior to handle more complex scenarios. Please review the code to get detailed information. Here are the methods it supports:
Typically, the scheduled script is configured to poll in short intervals, say, every second or 5 seconds. In this script, you can choose to get the lines appended to the file since the last polling of the file by using the getLines() method and implement custom parsing of these lines or you can use one of the line parsing methods provided with this class. Here is a sample scheduled script: // ************** FILE READER CONFIGURATION ************************** filePath = "c:\\temp\\input.txt"; tailMode = "true"; // true/false // ************** END OF FILE READER CONFIGURATION ****************** def fileReader = new RSFileReader(filePath, tailMode); def lines = fileReader.getLines(); def widths = [3, 5, 5]; for (line in lines){ println "DELIMITED VALUES: " + fileReader.getDelimitedValues(line, ","); println "FIXEDWIDTH VALUES: " + fileReader.getFixedWidthValues(line, widths); println "NAMEVALUE PAIRS: " + fileReader.getNameValueMap(line, "\\|", "="); } return lines.size(); |
Comments (0)
Anonymous says: