From c531e8f77cfcbe91b353ece306143439613f27cf Mon Sep 17 00:00:00 2001 From: Mats Klepsland Date: Fri, 13 Jan 2017 11:08:55 +0100 Subject: [PATCH] lua: add SCFlowHasAlerts function Add SCFlowHasAlerts() to check if a flow has alerts. Returns true on alerts, false otherwise. Example: has_alerts = SCFlowHasAlerts() if has_alerts then -- do something end --- src/util-lua-common.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/util-lua-common.c b/src/util-lua-common.c index f1c13a8a95..cb3d2dac4d 100644 --- a/src/util-lua-common.c +++ b/src/util-lua-common.c @@ -247,6 +247,37 @@ static int LuaCallbackFlowTimeString(lua_State *luastate) return r; } +/** \internal + * \brief fill lua stack with flow has alerts + * \param luastate the lua state + * \param flow flow + * \retval cnt number of data items placed on the stack + * + * Places alerts (bool) + */ +static int LuaCallbackHasAlertsPushToStackFromFlow(lua_State *luastate, const Flow *flow) +{ + lua_pushboolean(luastate, FlowHasAlerts(flow)); + + return 1; +} + +/** \internal + * \brief Wrapper for getting flow has alerts info into a lua script + * \retval cnt number of items placed on the stack + */ +static int LuaCallbackFlowHasAlerts(lua_State *luastate) +{ + int r = 0; + Flow *flow = LuaStateGetFlow(luastate); + if (flow == NULL) + return LuaCallbackError(luastate, "internal error: no flow"); + + r = LuaCallbackHasAlertsPushToStackFromFlow(luastate, flow); + + return r; +} + /** \internal * \brief fill lua stack with header info * \param luastate the lua state @@ -768,6 +799,8 @@ int LuaRegisterFunctions(lua_State *luastate) lua_setglobal(luastate, "SCFlowAppLayerProto"); lua_pushcfunction(luastate, LuaCallbackStatsFlow); lua_setglobal(luastate, "SCFlowStats"); + lua_pushcfunction(luastate, LuaCallbackFlowHasAlerts); + lua_setglobal(luastate, "SCFlowHasAlerts"); lua_pushcfunction(luastate, LuaCallbackStreamingBuffer); lua_setglobal(luastate, "SCStreamingBuffer");