英文:
Parse a log file remembering last run
问题
我有一个简单的脚本,它打开一个文件(日志文件),并解析其中的特定日志条目/关键字。对于每个匹配的条目,它会触发一个警报。
我想要解决的问题是,我希望修改脚本,以便在上次运行时记住已发送的警报,这样如果脚本重新运行,它就不会为已发送的警报再次发送警报。
编程语言是Golang,有哪些有效的方法可以实现这个功能?使用数据库似乎有点过头了,但我不知道还有其他什么选择?
英文:
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?
答案1
得分: 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论