DX Unified Infrastructure Management

  • 1.  Open a file in append mode in LUA

    Posted Jun 10, 2011 08:01 PM

    Hi all,

     

    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" ?

     

    Regards,

    Amit Saxena



  • 2.  Re: Open a file in append mode in LUA

    Posted Jun 10, 2011 08:51 PM

    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.

     

    -Keith



  • 3.  Re: Open a file in append mode in LUA

    Posted Jun 10, 2011 10:50 PM

    Hi Keith,

     

    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.

     

    Please suggest.

     

    fname  = "/alarms.txt"
    
    file.create ( fname )
    file.write ( fname, " \"" .. current_alarm_nimid .. "\" \"" .. current_alarm_hostname .. "\" \"" .. current_alarm_source )

     

     

    Regards,

    Amit Saxena

     



  • 4.  Re: Open a file in append mode in LUA
    Best Answer

    Posted Jun 10, 2011 10:56 PM

    Try it without calling the file.create() function if you do not want a new file.

     

    -Keith



  • 5.  Re: Open a file in append mode in LUA

    Posted Jun 11, 2011 05:54 PM

     

    Thanks Keith, it worked as expected.

     

    Regards,

    Amit Saxena