mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Jan_31_2024-Dev
This commit is contained in:
0
core/logging/cef_stream.cc
Executable file → Normal file
0
core/logging/cef_stream.cc
Executable file → Normal file
0
core/logging/debug_stream.cc
Executable file → Normal file
0
core/logging/debug_stream.cc
Executable file → Normal file
0
core/logging/file_stream.cc
Executable file → Normal file
0
core/logging/file_stream.cc
Executable file → Normal file
15
core/logging/fog_stream.cc
Executable file → Normal file
15
core/logging/fog_stream.cc
Executable file → Normal file
@@ -38,7 +38,7 @@ FogStream::sendLog(const Report &log)
|
||||
ctx.registerValue<bool>("Obfuscate log field", true);
|
||||
|
||||
LogRest rest(log);
|
||||
i_msg->sendObjectWithPersistence(rest, I_Messaging::Method::POST, fog_log_uri, "", true, MessageTypeTag::LOG);
|
||||
i_msg->sendAsyncMessage(HTTPMethod::POST, fog_log_uri, rest, MessageCategory::LOG);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -49,16 +49,13 @@ FogStream::sendLog(const LogBulkRest &logs, bool persistence_only)
|
||||
|
||||
auto fog_log_uri = getConfigurationWithDefault<string>("/api/v1/agents/events/bulk", "Logging", "Fog Log URI");
|
||||
if (!persistence_only) {
|
||||
i_msg->sendObjectWithPersistence(logs, I_Messaging::Method::POST, fog_log_uri, "", true, MessageTypeTag::LOG);
|
||||
i_msg->sendAsyncMessage(HTTPMethod::POST, fog_log_uri, logs, MessageCategory::LOG);
|
||||
} else {
|
||||
i_msg->sendObjectWithPersistence(
|
||||
logs,
|
||||
I_Messaging::Method::POST,
|
||||
i_msg->sendAsyncMessage(
|
||||
HTTPMethod::POST,
|
||||
fog_log_uri,
|
||||
"",
|
||||
false,
|
||||
MessageTypeTag::LOG,
|
||||
true
|
||||
logs,
|
||||
MessageCategory::LOG
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@@ -32,31 +32,21 @@ K8sSvcStream::~K8sSvcStream()
|
||||
{
|
||||
}
|
||||
|
||||
string
|
||||
K8sSvcStream::genHeader()
|
||||
{
|
||||
return "X-Tenant-Id: " + Singleton::Consume<I_AgentDetails>::by<LoggingComp>()->getTenantId();
|
||||
}
|
||||
|
||||
void
|
||||
K8sSvcStream::sendLog(const Report &log)
|
||||
{
|
||||
auto svc_host = getConfigurationWithDefault(default_host, "Logging", "K8sSvc Log host");
|
||||
auto K8sSvc_log_uri = getConfigurationWithDefault(default_log_uri, "Logging", "K8sSvc Log URI");
|
||||
LogRest rest(log);
|
||||
Flags<MessageConnConfig> conn_flags;
|
||||
conn_flags.setFlag(MessageConnConfig::EXTERNAL);
|
||||
|
||||
bool ok = i_msg->sendNoReplyObject(
|
||||
rest,
|
||||
I_Messaging::Method::POST,
|
||||
svc_host,
|
||||
80,
|
||||
conn_flags,
|
||||
MessageMetadata rest_req_md(svc_host, 80);
|
||||
rest_req_md.insertHeader("X-Tenant-Id", Singleton::Consume<I_AgentDetails>::by<LoggingComp>()->getTenantId());
|
||||
bool ok = i_msg->sendSyncMessageWithoutResponse(
|
||||
HTTPMethod::POST,
|
||||
K8sSvc_log_uri,
|
||||
genHeader(),
|
||||
nullptr,
|
||||
MessageTypeTag::LOG
|
||||
rest,
|
||||
MessageCategory::LOG,
|
||||
rest_req_md
|
||||
);
|
||||
|
||||
if (!ok) {
|
||||
@@ -76,19 +66,15 @@ K8sSvcStream::sendLog(const LogBulkRest &logs, bool persistence_only)
|
||||
|
||||
auto svc_host = getConfigurationWithDefault(default_host, "Logging", "K8sSvc Log host");
|
||||
auto K8sSvc_log_uri = getConfigurationWithDefault(default_bulk_uri, "Logging", "K8sSvc Bulk Log URI");
|
||||
Flags<MessageConnConfig> conn_flags;
|
||||
conn_flags.setFlag(MessageConnConfig::EXTERNAL);
|
||||
|
||||
bool ok = i_msg->sendNoReplyObject(
|
||||
logs,
|
||||
I_Messaging::Method::POST,
|
||||
svc_host,
|
||||
80,
|
||||
conn_flags,
|
||||
MessageMetadata rest_req_md(svc_host, 80);
|
||||
rest_req_md.insertHeader("X-Tenant-Id", Singleton::Consume<I_AgentDetails>::by<LoggingComp>()->getTenantId());
|
||||
bool ok = i_msg->sendSyncMessageWithoutResponse(
|
||||
HTTPMethod::POST,
|
||||
K8sSvc_log_uri,
|
||||
genHeader(),
|
||||
nullptr,
|
||||
MessageTypeTag::LOG
|
||||
logs,
|
||||
MessageCategory::LOG,
|
||||
rest_req_md
|
||||
);
|
||||
|
||||
if (!ok) {
|
||||
|
0
core/logging/log_generator.cc
Executable file → Normal file
0
core/logging/log_generator.cc
Executable file → Normal file
1
core/logging/log_streams.h
Executable file → Normal file
1
core/logging/log_streams.h
Executable file → Normal file
@@ -90,7 +90,6 @@ public:
|
||||
void sendLog(const LogBulkRest &logs, bool persistance_only) override;
|
||||
|
||||
private:
|
||||
std::string genHeader();
|
||||
I_Messaging *i_msg = nullptr;
|
||||
};
|
||||
|
||||
|
5
core/logging/logging.cc
Executable file → Normal file
5
core/logging/logging.cc
Executable file → Normal file
@@ -98,7 +98,7 @@ public:
|
||||
addStream(StreamType type) override
|
||||
{
|
||||
if (streams_preperation.find(type) != streams_preperation.end()) {
|
||||
dbgWarning(D_REPORT)
|
||||
dbgDebug(D_REPORT)
|
||||
<< "Cannot add second instance of the same stream. Stream type: "
|
||||
<< TagAndEnumManagement::convertToString(type);
|
||||
return false;
|
||||
@@ -119,7 +119,7 @@ public:
|
||||
{
|
||||
string log_type = TagAndEnumManagement::convertToString(type);
|
||||
if (streams_preperation.find(type) != streams_preperation.end()) {
|
||||
dbgWarning(D_REPORT)
|
||||
dbgDebug(D_REPORT)
|
||||
<< "Cannot add second instance of the same stream. Stream type: "
|
||||
<< log_type;
|
||||
return false;
|
||||
@@ -319,6 +319,7 @@ LoggingComp::preload()
|
||||
registerExpectedConfiguration<string>("Logging", "Log file name");
|
||||
registerExpectedConfiguration<string>("Logging", "Log file line separator");
|
||||
registerExpectedConfiguration<string>("Logging", "Fog Log URI");
|
||||
registerExpectedConfiguration<string>("Logging", "K8sSvc Log host");
|
||||
registerExpectedConfiguration<string>("Logging", "Syslog IP");
|
||||
registerExpectedConfiguration<uint>("Logging", "Syslog port");
|
||||
registerExpectedConfiguration<string>("Logging", "CEF IP");
|
||||
|
0
core/logging/logging_metric.h
Executable file → Normal file
0
core/logging/logging_metric.h
Executable file → Normal file
@@ -3,5 +3,5 @@ link_directories(${BOOST_ROOT}/lib)
|
||||
add_unit_test(
|
||||
logging_ut
|
||||
"logging_ut.cc"
|
||||
"logging;singleton;connkey;rest;report;agent_details;event_is;metric;version;-lboost_regex;"
|
||||
"logging;singleton;messaging;connkey;rest;report;agent_details;event_is;metric;version;-lboost_regex;"
|
||||
)
|
||||
|
100
core/logging/logging_ut/logging_ut.cc
Executable file → Normal file
100
core/logging/logging_ut/logging_ut.cc
Executable file → Normal file
@@ -166,12 +166,14 @@ public:
|
||||
|
||||
Debug::setUnitTestFlag(D_REPORT, Debug::DebugLevel::DEBUG);
|
||||
Debug::setNewDefaultStdout(&capture_debug);
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(DoAll(SaveArg<1>(&body), Return(string())));
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).WillRepeatedly(SaveArg<2>(&body));
|
||||
}
|
||||
|
||||
~LogTest()
|
||||
{
|
||||
is_domain = false;
|
||||
@@ -273,9 +275,9 @@ public:
|
||||
return Singleton::Consume<Config::I_Config>::from(config)->loadConfiguration(str_stream);
|
||||
}
|
||||
|
||||
StrictMock<MockMainLoop> mock_mainloop;
|
||||
StrictMock<MockMessaging> mock_fog_msg;
|
||||
StrictMock<MockSocketIS> mock_socket_is;
|
||||
StrictMock<MockMainLoop> mock_mainloop;
|
||||
StrictMock<MockMessaging> mock_msg;
|
||||
StrictMock<MockSocketIS> mock_socket_is;
|
||||
|
||||
ostringstream capture_debug;
|
||||
LoggingComp log_comp;
|
||||
@@ -738,11 +740,13 @@ TEST_F(LogTest, FogBulkLogs)
|
||||
{
|
||||
loadFakeConfiguration(true);
|
||||
string local_body;
|
||||
string res("[{\"id\": 1, \"code\": 400, \"message\": \"yes\"}]");
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(DoAll(SaveArg<1>(&local_body), Return(res)));
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).WillRepeatedly(SaveArg<2>(&local_body));
|
||||
|
||||
Tags tag1 = Tags::POLICY_INSTALLATION;
|
||||
Tags tag2 = Tags::ACCESS_CONTROL;
|
||||
@@ -799,9 +803,12 @@ TEST_F(LogTest, OfflineK8sSvcTest)
|
||||
string local_body;
|
||||
string res("[{\"id\": 1, \"code\": 400, \"message\": \"yes\"}]");
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
sendMessage(_, _, _, "open-appsec-tuning-svc", _, _, "/api/v1/agents/events", _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(DoAll(SaveArg<1>(&local_body), Return(res)));
|
||||
mock_msg,
|
||||
sendSyncMessage(_, "/api/v1/agents/events", _, MessageCategory::LOG, _)
|
||||
).WillRepeatedly(DoAll(
|
||||
SaveArg<2>(&local_body),
|
||||
Return(HTTPResponse(HTTPStatusCode::HTTP_OK, res))
|
||||
));
|
||||
|
||||
string str1(
|
||||
"{\n"
|
||||
@@ -846,9 +853,12 @@ TEST_F(LogTest, OfflineK8sSvcBulkLogs)
|
||||
string local_body;
|
||||
string res("[{\"id\": 1, \"code\": 400, \"message\": \"yes\"}]");
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
sendMessage(_, _, _, "open-appsec-tuning-svc", _, _, "/api/v1/agents/events/bulk", _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(DoAll(SaveArg<1>(&local_body), Return(res)));
|
||||
mock_msg,
|
||||
sendSyncMessage(_, "/api/v1/agents/events/bulk", _, MessageCategory::LOG, _)
|
||||
).WillRepeatedly(DoAll(
|
||||
SaveArg<2>(&local_body),
|
||||
Return(HTTPResponse(HTTPStatusCode::HTTP_OK, res))
|
||||
));
|
||||
|
||||
Tags tag1 = Tags::POLICY_INSTALLATION;
|
||||
Tags tag2 = Tags::ACCESS_CONTROL;
|
||||
@@ -1123,15 +1133,19 @@ TEST(LogTestInstanceAwareness, LogGenInstanceAwareness)
|
||||
ConfigComponent config;
|
||||
StrictMock<MockMainLoop> mock_mainloop;
|
||||
StrictMock<MockTimeGet> mock_timer;
|
||||
StrictMock<MockMessaging> mock_fog_msg;
|
||||
StrictMock<MockSocketIS> mock_socket_is;
|
||||
StrictMock<MockMessaging> mock_msg;
|
||||
AgentDetails agent_details;
|
||||
LoggingComp log_comp;
|
||||
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(Return(string()));
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).Times(AnyNumber());
|
||||
|
||||
EXPECT_CALL(mock_socket_is, genSocket(_, _, _, _)).WillRepeatedly(Return(1));
|
||||
EXPECT_CALL(mock_socket_is, closeSocket(_)).Times(AnyNumber());
|
||||
EXPECT_CALL(mock_mainloop, doesRoutineExist(_)).WillRepeatedly(Return(true));
|
||||
@@ -1225,14 +1239,17 @@ TEST(LogTestWithoutComponent, RegisterBasicConfig)
|
||||
ConfigComponent config;
|
||||
NiceMock<MockMainLoop> mock_mainloop;
|
||||
NiceMock<MockTimeGet> mock_timer;
|
||||
StrictMock<MockMessaging> mock_fog_msg;
|
||||
StrictMock<MockAgentDetails> mock_agent_details;
|
||||
StrictMock<MockMessaging> mock_msg;
|
||||
EXPECT_CALL(mock_agent_details, getOrchestrationMode()).WillRepeatedly(Return(OrchestrationMode::ONLINE));
|
||||
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(Return(string()));
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).Times(AnyNumber());
|
||||
|
||||
LoggingComp log_comp;
|
||||
log_comp.preload();
|
||||
@@ -1269,14 +1286,17 @@ TEST(LogTestWithoutComponent, RegisterAdvancedConfig)
|
||||
ConfigComponent config;
|
||||
NiceMock<MockMainLoop> mock_mainloop;
|
||||
NiceMock<MockTimeGet> mock_timer;
|
||||
StrictMock<MockMessaging> mock_fog_msg;
|
||||
StrictMock<MockAgentDetails> mock_agent_details;
|
||||
StrictMock<MockMessaging> mock_msg;
|
||||
EXPECT_CALL(mock_agent_details, getOrchestrationMode()).WillRepeatedly(Return(OrchestrationMode::ONLINE));
|
||||
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(Return(string()));
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).Times(AnyNumber());
|
||||
|
||||
LoggingComp log_comp;
|
||||
log_comp.preload();
|
||||
@@ -1340,10 +1360,14 @@ TEST_F(LogTest, BulkModification)
|
||||
{
|
||||
string local_body;
|
||||
string res("[{\"id\": 1, \"code\": 400, \"message\": \"yes\"}]");
|
||||
EXPECT_CALL(
|
||||
mock_fog_msg,
|
||||
mockSendPersistentMessage(_, _, _, _, _, _, MessageTypeTag::LOG)
|
||||
).WillRepeatedly(DoAll(SaveArg<1>(&local_body), Return(res)));
|
||||
|
||||
EXPECT_CALL(mock_msg, sendAsyncMessage(
|
||||
_,
|
||||
_,
|
||||
_,
|
||||
MessageCategory::LOG,
|
||||
_
|
||||
)).WillRepeatedly(SaveArg<2>(&local_body));
|
||||
|
||||
logger->addGeneralModifier(changeOne);
|
||||
logger->addGeneralModifier(changeTwo);
|
||||
|
0
core/logging/syslog_stream.cc
Executable file → Normal file
0
core/logging/syslog_stream.cc
Executable file → Normal file
Reference in New Issue
Block a user