0

I have a simple script that opens a file (log file), parses through it looking for specific log entries/keywords and for each entry that matches it triggers an alert.

The problem that I am trying to solve is that I would like to modify the script to remember the alarms that were already sent when it was last run, so that if the script re-runs it won't keep sending an alert for previously sent alerts.

The coding language is Golang, what are the a valid approach to do this? A database sounds like overkill, but I don't know what other alternatives are out there?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If reading from a file being appended to, you could start reading after the last processed line: [How to read a file starting from a specific line number using Scanner?](http://stackoverflow.com/questions/34654514/how-to-read-a-file-starting-from-a-specific-line-number-using-scanner/34661512#34661512) – icza May 21 '17 at 05:55

1 Answers1

1

It depends on the nature of the log file: server log (classic) or transation log.
Even assuming the former, it depends on its Log Management (long term retention, rotation, ...)

Assuming a classic log files whose data are appended (not overwritten), a simple approach would be to generate in a file the line where the alert is found.
At the next run, if that line matches one stored in that special "flag" file, the alert would not be sent again.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks, this is an old school serve log (classic) file that seems to append data to the end of file with a specific date next to it, so your suggestion would totally work and I could check the line number and matching timestamp for the last entry. (ex: 2017/05/20 16:38:19.133) – TheLinuxGuy May 21 '17 at 15:48
  • 1
    @TheLinuxGuy Great! Don't for get to read http://stackoverflow.com/help/accepted-answer (for this question or your other questions without accepted answers) – VonC May 21 '17 at 15:50