Project

General

Profile

Bug #1522 » nt-http-count.lua

Simple lua script - Edward Fjellskål, 07/28/2015 03:52 PM

 
function init (args)
local needs = {}
needs["protocol"] = "http"
return needs
end

name = "nt-http-count.log"

function setup (args)
filename = SCLogPath() .. "/" .. name
file = assert(io.open(filename, "a"))
SCLogInfo("NetworkTotal HTTP Test Count Log File: " .. filename)
end

function deinit (args)
SCLogInfo("NetworkTotal HTTP Test Count closing log file")
file:close(file)
end

http = 0

function log (args)
http = http + 1
local http_host = HttpGetRequestHost()
if http_host == nil then
http_host = "<unknown host>"
else
http_host = string.gsub(http_host, "%c", ".")
end

local http_ua = HttpGetRequestHeader("User-Agent")
if http_ua == nil then
http_ua = "<unknown useragent>"
else
http_ua = string.gsub(http_ua, "%c", ".")
end

local ts = SCPacketTimeString()

file:write(ts .. " [**] " .. http_host .. " [**] " .. http_ua .. " [**] " .. http .. "\n")
file:flush()
end
    (1-1/1)