I want to log the alarms data to a flat file. I wrote a script, which I am calling on a profile configured on "on arrival" mode, and inside that script, I am using file.create function.
Unfortunately every time an alarm is received by NAS, the file.create function in the script gets invoked through the profile and the file is overwritten with the new alarm.
How to ensure the following ?
1) The file is opened in append mode.
2) Locking issue, if any, is taken care means if two or more than two alarms arrive at same time, both will try to append to the flat file at same time which might create data issues.
Also, how to provide data-time stamp in the name of the file in the format of "alarms_YYYYMMDDHHMM.txt" ?
You should use file.write() to write to an existing file. The whitepaper indicates that appends to the file. I am not sure about how to lock a file to which you need to write.
Check out timestamp.data() for getting values for the various fields of the date.
I referred the built in examples shipped with NAS for the file handling operations and it mentions the same thing as what I am also facing. The code screenshot where I am handling file operations are mentioned below.
fname = "/alarms.txt"
file.create ( fname )
file.write ( fname, " \"" .. current_alarm_nimid .. "\" \"" .. current_alarm_hostname .. "\" \"" .. current_alarm_source )
Try it without calling the file.create() function if you do not want a new file.
Thanks Keith, it worked as expected.