1 local socket
= require
"socket"
2 local arg
= {select(1, ...)}
3 local port
= tonumber(arg
[1] or os
.getenv("LUASNMP_TRAPDPORT")) or 6000
5 if _VERSION
> "5.1" then
6 local logger
= require
"logging.file"
10 log = logging
.file(arg
[2])
12 log:setLevel(arg
[3] or "INFO")
13 log:info("TRAPD capture start")
16 -- Collect input from snmptrapd and optionally write into logfile
17 -- We do not care about contents!
20 for s
in io
.lines() do
22 log:debug("captured: '".. s
.."'")
26 -- Send the string to luasnmp
29 local ip
= socket
.dns
.toip("localhost")
31 log:debug("sending input to "..ip
..":"..port
)
32 sk
:sendto(str
, ip
, port
)
35 log:error("cannot open udp socket")
40 -- Close the optional logfile.
42 log:info("TRAPD capture finished.")