mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-30 11:44:29 +03:00
sync code
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "mock/mock_time_get.h"
|
||||
#include "mock/mock_rest_api.h"
|
||||
#include "agent_details.h"
|
||||
#include "mock/mock_encryptor.h"
|
||||
#include "mock/mock_messaging.h"
|
||||
#include "mock/mock_instance_awareness.h"
|
||||
#include "config.h"
|
||||
@@ -219,6 +220,7 @@ public:
|
||||
::Environment env;
|
||||
ConfigComponent conf;
|
||||
AgentDetails agent_details;
|
||||
StrictMock<MockEncryptor> mock_encryptor;
|
||||
NiceMock<MockMessaging> messaging_mock;
|
||||
stringstream debug_output;
|
||||
I_MainLoop::Routine routine;
|
||||
@@ -556,7 +558,7 @@ TEST_F(MetricTest, printPromeathus)
|
||||
cpu_event.notify();
|
||||
|
||||
string message_body;
|
||||
EXPECT_CALL(messaging_mock, sendSyncMessage(_, "/set-prometheus-data", _, _, _))
|
||||
EXPECT_CALL(messaging_mock, sendSyncMessage(_, "/add-metrics", _, _, _))
|
||||
.WillOnce(DoAll(SaveArg<2>(&message_body), Return(HTTPResponse())));
|
||||
routine();
|
||||
|
||||
@@ -564,44 +566,44 @@ TEST_F(MetricTest, printPromeathus)
|
||||
"{\n"
|
||||
" \"metrics\": [\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuMax\",\n"
|
||||
" \"type\": \"gauge\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuMax\",\n"
|
||||
" \"metric_type\": \"gauge\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"89\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuMin\",\n"
|
||||
" \"type\": \"gauge\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuMin\",\n"
|
||||
" \"metric_type\": \"gauge\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"89\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuAvg\",\n"
|
||||
" \"type\": \"gauge\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuAvg\",\n"
|
||||
" \"metric_type\": \"gauge\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"89\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuCurrent\",\n"
|
||||
" \"type\": \"gauge\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuCurrent\",\n"
|
||||
" \"metric_type\": \"gauge\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"89\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuCounter\",\n"
|
||||
" \"type\": \"gauge\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuCounter\",\n"
|
||||
" \"metric_type\": \"gauge\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"1\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"cpuTotalCounter\",\n"
|
||||
" \"type\": \"counter\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"cpuTotalCounter\",\n"
|
||||
" \"metric_type\": \"counter\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\"}\",\n"
|
||||
" \"value\": \"1\"\n"
|
||||
" }\n"
|
||||
@@ -636,7 +638,7 @@ TEST_F(MetricTest, printPromeathusMultiMap)
|
||||
HttpTransaction("/index.html", "POST", 40).notify();
|
||||
|
||||
string message_body;
|
||||
EXPECT_CALL(messaging_mock, sendSyncMessage(_, "/set-prometheus-data", _, _, _))
|
||||
EXPECT_CALL(messaging_mock, sendSyncMessage(_, "/add-metrics", _, _, _))
|
||||
.WillOnce(DoAll(SaveArg<2>(&message_body), Return(HTTPResponse())));
|
||||
routine();
|
||||
|
||||
@@ -644,25 +646,25 @@ TEST_F(MetricTest, printPromeathusMultiMap)
|
||||
"{\n"
|
||||
" \"metrics\": [\n"
|
||||
" {\n"
|
||||
" \"name\": \"request.total\",\n"
|
||||
" \"type\": \"counter\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"request.total\",\n"
|
||||
" \"metric_type\": \"counter\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\","
|
||||
"method=\\\"GET\\\",url=\\\"/index.html\\\"}\",\n"
|
||||
" \"value\": \"1\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"request.total\",\n"
|
||||
" \"type\": \"counter\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"request.total\",\n"
|
||||
" \"metric_type\": \"counter\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\","
|
||||
"method=\\\"POST\\\",url=\\\"/index.html\\\"}\",\n"
|
||||
" \"value\": \"1\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"name\": \"request.total\",\n"
|
||||
" \"type\": \"counter\",\n"
|
||||
" \"description\": \"\",\n"
|
||||
" \"metric_name\": \"request.total\",\n"
|
||||
" \"metric_type\": \"counter\",\n"
|
||||
" \"metric_description\": \"\",\n"
|
||||
" \"labels\": \"{agent=\\\"Unknown\\\",id=\\\"87\\\","
|
||||
"method=\\\"GET\\\",url=\\\"/index2.html\\\"}\",\n"
|
||||
" \"value\": \"1\"\n"
|
||||
@@ -1396,6 +1398,8 @@ TEST_F(MetricTest, testManyValuesOutOfOrder)
|
||||
TEST_F(MetricTest, basicAIOPSMetricTest)
|
||||
{
|
||||
EXPECT_CALL(timer, getWalltimeStr()).WillRepeatedly(Return(string("2016-11-13T17:31:24.087")));
|
||||
EXPECT_CALL(mock_encryptor, base64Encode(_)).WillRepeatedly(Return("compress and encode metric payload"));
|
||||
|
||||
CPUMetric cpu_mt;
|
||||
cpu_mt.init(
|
||||
"CPU usage",
|
||||
@@ -1452,14 +1456,14 @@ TEST_F(MetricTest, basicAIOPSMetricTest)
|
||||
" \"eventLevel\": \"Log\",\n"
|
||||
" \"eventLogLevel\": \"info\",\n"
|
||||
" \"eventAudience\": \"Internal\",\n"
|
||||
" \"eventAudienceTeam\": \"Agent Core\",\n"
|
||||
" \"eventAudienceTeam\": \"\",\n"
|
||||
" \"eventFrequency\": 5,\n"
|
||||
" \"eventTags\": [\n"
|
||||
" \"Informational\"\n"
|
||||
" ],\n"
|
||||
" \"eventSource\": {\n"
|
||||
" \"agentId\": \"Unknown\",\n"
|
||||
" \"issuingEngine\": \"Agent Core\",\n"
|
||||
" \"issuingEngine\": \"horizonTelemetryMetrics\",\n"
|
||||
" \"eventTraceId\": \"\",\n"
|
||||
" \"eventSpanId\": \"\",\n"
|
||||
" \"issuingEngineVersion\": \"\",\n"
|
||||
@@ -1469,92 +1473,7 @@ TEST_F(MetricTest, basicAIOPSMetricTest)
|
||||
" },\n"
|
||||
" \"eventData\": {\n"
|
||||
" \"eventObject\": {\n"
|
||||
" \"Metrics\": [\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpu.max\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"percrnt\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 89.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpuMin\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 89.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpuAvg\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 89.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpuCurrent\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 89.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpuCounter\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 1.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"cpuTotalCounter\",\n"
|
||||
" \"MetricType\": \"counter\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 1.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {},\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" \"records\": \"compress and encode metric payload\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
@@ -1595,8 +1514,68 @@ TEST_F(MetricTest, testAIOPSMapMetric)
|
||||
_,
|
||||
_
|
||||
)).WillRepeatedly(SaveArg<2>(&message_body));
|
||||
EXPECT_CALL(mock_encryptor, base64Encode(_)).WillRepeatedly(Return("compress and encode metric payload"));
|
||||
routine();
|
||||
|
||||
// aiops data example
|
||||
// " \"Metrics\": [\n"
|
||||
// " {\n"
|
||||
// " \"Timestamp\": \"2016-11-13T17:31:24Z\",\n"
|
||||
// " \"MetricName\": \"/index.html\",\n"
|
||||
// " \"MetricType\": \"Gauge\",\n"
|
||||
// " \"MetricUnit\": \"\",\n"
|
||||
// " \"MetricDescription\": \"\",\n"
|
||||
// " \"MetricValue\": 0.0,\n"
|
||||
// " \"ResourceAttributes\": {},\n"
|
||||
// " \"MetricAttributes\": {\n"
|
||||
// " \"key1\": \"value1\",\n"
|
||||
// " \"key2\": \"value2\"\n"
|
||||
// " },\n"
|
||||
// " \"AssetID\": \"Unknown\"\n"
|
||||
// " },\n"
|
||||
// " {\n"
|
||||
// " \"Timestamp\": \"2016-11-13T17:31:24Z\",\n"
|
||||
// " \"MetricName\": \"/index2.html\",\n"
|
||||
// " \"MetricType\": \"Gauge\",\n"
|
||||
// " \"MetricUnit\": \"\",\n"
|
||||
// " \"MetricDescription\": \"\",\n"
|
||||
// " \"MetricValue\": 0.0,\n"
|
||||
// " \"ResourceAttributes\": {},\n"
|
||||
// " \"MetricAttributes\": {\n"
|
||||
// " \"key1\": \"value1\",\n"
|
||||
// " \"key2\": \"value2\"\n"
|
||||
// " },\n"
|
||||
// " \"AssetID\": \"Unknown\"\n"
|
||||
// " },\n"
|
||||
// " {\n"
|
||||
// " \"Timestamp\": \"2016-11-13T17:31:24Z\",\n"
|
||||
// " \"MetricName\": \"/index.html\",\n"
|
||||
// " \"MetricType\": \"Counter\",\n"
|
||||
// " \"MetricUnit\": \"\",\n"
|
||||
// " \"MetricDescription\": \"\",\n"
|
||||
// " \"MetricValue\": 0.0,\n"
|
||||
// " \"ResourceAttributes\": {},\n"
|
||||
// " \"MetricAttributes\": {},\n"
|
||||
// " \"AssetID\": \"Unknown\"\n"
|
||||
// " },\n"
|
||||
// " {\n"
|
||||
// " \"Timestamp\": \"2016-11-13T17:31:24Z\",\n"
|
||||
// " \"MetricName\": \"/index2.html\",\n"
|
||||
// " \"MetricType\": \"Counter\",\n"
|
||||
// " \"MetricUnit\": \"\",\n"
|
||||
// " \"MetricDescription\": \"\",\n"
|
||||
// " \"MetricValue\": 0.0,\n"
|
||||
// " \"ResourceAttributes\": {},\n"
|
||||
// " \"MetricAttributes\": {},\n"
|
||||
// " \"AssetID\": \"Unknown\"\n"
|
||||
// " }\n"
|
||||
// " ]\n"
|
||||
// " }\n"
|
||||
// " }\n"
|
||||
// " }\n"
|
||||
// "}";
|
||||
|
||||
|
||||
string expected_message =
|
||||
"{\n"
|
||||
" \"log\": {\n"
|
||||
@@ -1608,14 +1587,14 @@ TEST_F(MetricTest, testAIOPSMapMetric)
|
||||
" \"eventLevel\": \"Log\",\n"
|
||||
" \"eventLogLevel\": \"info\",\n"
|
||||
" \"eventAudience\": \"Internal\",\n"
|
||||
" \"eventAudienceTeam\": \"Agent Core\",\n"
|
||||
" \"eventAudienceTeam\": \"\",\n"
|
||||
" \"eventFrequency\": 5,\n"
|
||||
" \"eventTags\": [\n"
|
||||
" \"Informational\"\n"
|
||||
" ],\n"
|
||||
" \"eventSource\": {\n"
|
||||
" \"agentId\": \"Unknown\",\n"
|
||||
" \"issuingEngine\": \"Agent Core\",\n"
|
||||
" \"issuingEngine\": \"horizonTelemetryMetrics\",\n"
|
||||
" \"eventTraceId\": \"\",\n"
|
||||
" \"eventSpanId\": \"\",\n"
|
||||
" \"issuingEngineVersion\": \"\",\n"
|
||||
@@ -1625,72 +1604,7 @@ TEST_F(MetricTest, testAIOPSMapMetric)
|
||||
" },\n"
|
||||
" \"eventData\": {\n"
|
||||
" \"eventObject\": {\n"
|
||||
" \"Metrics\": [\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"/index.html\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 25.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {\n"
|
||||
" \"url\": \"/index.html\"\n"
|
||||
" },\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"/index2.html\",\n"
|
||||
" \"MetricType\": \"gauge\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 20.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {\n"
|
||||
" \"url\": \"/index2.html\"\n"
|
||||
" },\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"/index.html\",\n"
|
||||
" \"MetricType\": \"counter\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 2.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {\n"
|
||||
" \"url\": \"/index.html\"\n"
|
||||
" },\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" },\n"
|
||||
" {\n"
|
||||
" \"Timestamp\": \"2016-11-13T17:31:24.087\",\n"
|
||||
" \"MetricName\": \"/index2.html\",\n"
|
||||
" \"MetricType\": \"counter\",\n"
|
||||
" \"MetricUnit\": \"\",\n"
|
||||
" \"MetricDescription\": \"\",\n"
|
||||
" \"MetricValue\": 1.0,\n"
|
||||
" \"ResourceAttributes\": {\n"
|
||||
" \"agent\": \"Unknown\",\n"
|
||||
" \"id\": \"87\"\n"
|
||||
" },\n"
|
||||
" \"MetricAttributes\": {\n"
|
||||
" \"url\": \"/index2.html\"\n"
|
||||
" },\n"
|
||||
" \"AssetID\": \"Unknown\"\n"
|
||||
" }\n"
|
||||
" ]\n"
|
||||
" \"records\": \"compress and encode metric payload\"\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
" }\n"
|
||||
|
Reference in New Issue
Block a user