end
function log(args)
+ ts = SCPacketTimeString()
sid, rev, gid = SCRuleIds()
ipver, srcip, dstip, proto, sp, dp = SCPacketTuple()
msg = SCRuleMsg()
if class == nil then
class = "unknown"
end
- ts = args['ts'];
print (ts .. " [**] [" .. gid .. ":" .. sid .. ":" .. rev .. "] " ..
msg .. " [**] [Classification: " .. class .. "] [Priority: " ..
lua_settable(luastate, -3);
}
+/** \internal
+ * \brief fill lua stack with header info
+ * \param luastate the lua state
+ * \param p packet
+ * \retval cnt number of data items placed on the stack
+ *
+ * Places: ts (string)
+ */
+static int LuaCallbackTimeStringPushToStackFromPacket(lua_State *luastate, const Packet *p)
+{
+ char timebuf[64];
+ CreateTimeString(&p->ts, timebuf, sizeof(timebuf));
+ lua_pushstring (luastate, timebuf);
+ return 1;
+}
+
+/** \internal
+ * \brief Wrapper for getting tuple info into a lua script
+ * \retval cnt number of items placed on the stack
+ */
+static int LuaCallbackPacketTimeString(lua_State *luastate)
+{
+ const Packet *p = LuaStateGetPacket(luastate);
+ if (p == NULL)
+ return LuaCallbackError(luastate, "internal error: no packet");
+
+ return LuaCallbackTimeStringPushToStackFromPacket(luastate, p);
+}
+
/** \internal
* \brief fill lua stack with header info
* \param luastate the lua state
int LogLuaRegisterFunctions(lua_State *luastate)
{
/* registration of the callbacks */
+ lua_pushcfunction(luastate, LuaCallbackPacketTimeString);
+ lua_setglobal(luastate, "SCPacketTimeString");
lua_pushcfunction(luastate, LuaCallbackTuple);
lua_setglobal(luastate, "SCPacketTuple");
+
lua_pushcfunction(luastate, LuaCallbackTupleFlow);
lua_setglobal(luastate, "SCFlowTuple");
lua_pushcfunction(luastate, LuaCallbackLogPath);
LuaStateSetPacketAlert(td->lua_ctx->luastate, (PacketAlert *)pa);
/* prepare data to pass to script */
- lua_newtable(td->lua_ctx->luastate);
+ //lua_newtable(td->lua_ctx->luastate);
- LogLuaPushTableKeyValueString(td->lua_ctx->luastate, "ts", timebuf);
-
- int retval = lua_pcall(td->lua_ctx->luastate, 1, 0, 0);
+ int retval = lua_pcall(td->lua_ctx->luastate, 0, 0, 0);
if (retval != 0) {
SCLogInfo("failed to run script: %s", lua_tostring(td->lua_ctx->luastate, -1));
}