Hi, I'm using tshark and lua to extract datafields from diameter protocol in endless loop and saving them into log file. It works great. But now I need to create new logfile every 5 minutes. I can change io.output inside tap.packet functions but it's not accurate since it's called only when there is a packet. I check How to use a timer in lua, but I'm not able to combine it with my code. Please, can you help me? Thanks. btw To create 5min pcaps and process them it's not a option for me. My code (very simplified):
asked 04 Dec ‘12, 08:59 lojza |
2 Answers:
as it's said in the stackoverflow question, there are no real timers in Lua itself. So, the only way to implement it, is to call os.clock() within the tap.packet function and then change the file descriptor after 5 minutes. However: You said, that this is not accurate enough, so I guess it's not an option for you. There is a Lua module called winapi which allows you to create a real timer in Lua, by using the Win32 API.
The bad news: You can't use that module with Wireshark, as it's compiled with a different compiler version. And even if you compile it yourself, I'm not sure if the integration of Lua into Wireshark would allow to use that module! So, I'm sorry, but your options are kind of limited. You could use an external program to monitor your logfile. That program runs independently of tshark and checks the log file for modifications every second. If there is a change, it will extract the delta since the last change. Now, that external tool can write a new consolidated log file at every interval you need. Regards answered 04 Dec '12, 13:24 Kurt Knochner ♦ Actually, you can use the And yes, Wireshark Lua let you use practically any library as long as it's for the same version of Lua. The current Windows releases of Wireshark officially support Lua 5.1. (04 Dec '12, 17:40) helloworld nice! I did not test the gcc version of the library. @lojza: Now you have a solution. Use the test-timer.lua script as a starting point. Set a timer to 5 minutes. If the timer fires, change the file descriptor and you should get a new file every 5 minutes. (04 Dec '12, 18:21) Kurt Knochner ♦ |
I don't think a timer (or a concurrent task) is truly necessary here. If I understand correctly, you need the log to rollover every 5 minutes, but a rollover should only occur if you indeed have something to log (so checking the time in
In that timespan, you have 2 useful non-empty files. So, I think the answer from StackOverflow is the right one. answered 04 Dec '12, 18:33 helloworld |
Hello everybody, thank you for your help. Let me redefine my question: Only possibility to check the time (with
os.clock()
) is whentap.packet()
is called. Right?Just remark: I’m running under Linux and what stated helloworld is right, but I prefer new logfile exactly every 5 minutes (even empty) rather then non-empty files randomly generated (as packets arrive)
New idea: I’m thinking about definition of new “more busy” (tcp) tap and check time inside it. E.g.:
But maybe it brings more trouble then benefits. Thank you :-)
If you run on linux: Yes.
If you run on Windows: No (see winapi).
Yes, that's possible, but as you said, it will possibly cause other problems (resource consumption).
Ok. But I have to ask: how are empty files useful? If you need to track quiet time periods, there are simpler and more elegant ways of handling that (e.g., logging this fact in a file).
Your "new" idea's code snippet looks like the same idea suggested in StackOverflow (in that it just checks the time inside
tap.packet()
).It's just my approach (obsession) :-) Idea is same, but applied on tcp which occurs more frequently than diameter.