mirror of
https://github.com/openappsec/openappsec.git
synced 2025-09-29 19:24:26 +03:00
Feb 10 2025 dev (#255)
* sync code * sync code * code sync * code sync --------- Co-authored-by: Ned Wright <nedwright@proton.me> Co-authored-by: Daniel Eisenberg <danielei@checkpoint.com>
This commit is contained in:
@@ -42,6 +42,9 @@ unsigned int getFailOpenTimeout();
|
||||
int isFailOpenHoldMode();
|
||||
unsigned int getFailOpenHoldTimeout();
|
||||
|
||||
unsigned int getHoldVerdictPollingTime();
|
||||
unsigned int getHoldVerdictRetries();
|
||||
|
||||
unsigned int getMaxSessionsPerMinute();
|
||||
int isFailOpenOnSessionLimit();
|
||||
|
||||
|
@@ -36,6 +36,7 @@ public:
|
||||
virtual Maybe<std::string> getFogDomain() const = 0;
|
||||
virtual std::string getTenantId() const = 0;
|
||||
virtual std::string getProfileId() const = 0;
|
||||
virtual std::string getRegisteredServer() const = 0;
|
||||
|
||||
// Agent Details
|
||||
virtual Maybe<std::string> getProxy() const = 0;
|
||||
@@ -43,6 +44,7 @@ public:
|
||||
virtual void setAgentId(const std::string &_agent_id) = 0;
|
||||
virtual std::string getAgentId() const = 0;
|
||||
virtual void setOrchestrationMode(OrchestrationMode _orchstration_mode) = 0;
|
||||
virtual void setRegisteredServer(const std::string &_server) = 0;
|
||||
virtual OrchestrationMode getOrchestrationMode() const = 0;
|
||||
virtual std::string getAccessToken() const = 0;
|
||||
virtual void loadAccessToken() = 0;
|
||||
|
@@ -75,9 +75,16 @@ public:
|
||||
port_num(_port_num),
|
||||
conn_flags(_conn_flags),
|
||||
should_buffer(_should_buffer),
|
||||
is_to_fog(_is_to_fog)
|
||||
is_to_fog(_is_to_fog),
|
||||
should_send_access_token(true)
|
||||
{}
|
||||
|
||||
const bool &
|
||||
shouldSendAccessToken() const
|
||||
{
|
||||
return should_send_access_token;
|
||||
}
|
||||
|
||||
const std::string &
|
||||
getHostName() const
|
||||
{
|
||||
@@ -90,6 +97,12 @@ public:
|
||||
return port_num;
|
||||
}
|
||||
|
||||
void
|
||||
setShouldSendAccessToken(const bool &_should_send_access_token)
|
||||
{
|
||||
should_send_access_token = _should_send_access_token;
|
||||
}
|
||||
|
||||
void
|
||||
setConnectioFlag(MessageConnectionConfig flag)
|
||||
{
|
||||
@@ -300,6 +313,7 @@ private:
|
||||
bool is_to_fog = false;
|
||||
bool is_rate_limit_block = false;
|
||||
uint rate_limit_block_time = 0;
|
||||
bool should_send_access_token = true;
|
||||
};
|
||||
|
||||
#endif // __MESSAGING_METADATA_H__
|
||||
|
@@ -20,11 +20,13 @@ public:
|
||||
MOCK_CONST_METHOD0(getFogDomain, Maybe<std::string>());
|
||||
MOCK_CONST_METHOD0(getTenantId, std::string());
|
||||
MOCK_CONST_METHOD0(getProfileId, std::string());
|
||||
MOCK_CONST_METHOD0(getRegisteredServer, std::string());
|
||||
|
||||
// Agent Details
|
||||
MOCK_CONST_METHOD0(getProxy, Maybe<std::string>());
|
||||
MOCK_METHOD1(setProxy, void(const std::string&));
|
||||
MOCK_METHOD1(setAgentId, void(const std::string&));
|
||||
MOCK_METHOD1(setRegisteredServer, void(const std::string&));
|
||||
MOCK_CONST_METHOD0(getAgentId, std::string());
|
||||
MOCK_METHOD0(loadAccessToken, void());
|
||||
MOCK_CONST_METHOD0(getAccessToken, std::string());
|
||||
|
@@ -73,6 +73,7 @@ public:
|
||||
Maybe<std::string> getOpenSSLDir() const;
|
||||
std::string getClusterId() const;
|
||||
OrchestrationMode getOrchestrationMode() const;
|
||||
std::string getRegisteredServer() const;
|
||||
bool isOpenAppsecAgent() const;
|
||||
std::string getAccessToken() const;
|
||||
void loadAccessToken();
|
||||
@@ -86,6 +87,7 @@ public:
|
||||
void setOpenSSLDir(const std::string &_openssl_dir) { openssl_dir = _openssl_dir; }
|
||||
void setSSLFlag(const bool _encrypted_connection) { encrypted_connection = _encrypted_connection; }
|
||||
void setOrchestrationMode(OrchestrationMode _orchstration_mode) { orchestration_mode = _orchstration_mode; }
|
||||
void setRegisteredServer(const std::string &_server) { server = _server; }
|
||||
bool getSSLFlag() const { return encrypted_connection; }
|
||||
|
||||
bool readAgentDetails();
|
||||
@@ -117,6 +119,7 @@ private:
|
||||
uint16_t fog_port = 0;
|
||||
bool encrypted_connection = false;
|
||||
OrchestrationMode orchestration_mode = OrchestrationMode::ONLINE;
|
||||
std::string server = "Unknown";
|
||||
bool is_proxy_configured_via_settings = false;
|
||||
std::map<ProxyProtocol, ProxyData> proxies;
|
||||
|
||||
|
@@ -48,6 +48,7 @@
|
||||
#include "intelligence_comp_v2.h"
|
||||
#include "messaging.h"
|
||||
#include "env_details.h"
|
||||
#include "metric/metric_scraper.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_COMP_IS);
|
||||
|
||||
@@ -216,6 +217,7 @@ class ComponentListCore
|
||||
Version,
|
||||
Buffer,
|
||||
ShellCmd,
|
||||
MetricScraper,
|
||||
GenericMetric,
|
||||
Messaging,
|
||||
MainloopComponent,
|
||||
|
@@ -153,6 +153,7 @@ DEFINE_FLAG(D_COMPONENT, D_ALL)
|
||||
DEFINE_FLAG(D_SDWAN, D_COMPONENT)
|
||||
DEFINE_FLAG(D_SDWAN_POLICY, D_SDWAN)
|
||||
DEFINE_FLAG(D_SDWAN_DATA, D_SDWAN)
|
||||
DEFINE_FLAG(D_SDWAN_FEATURE_FLAG, D_SDWAN)
|
||||
DEFINE_FLAG(D_LOGGER_SDWAN, D_SDWAN)
|
||||
DEFINE_FLAG(D_SDWAN_API, D_SDWAN)
|
||||
DEFINE_FLAG(D_REVERSE_PROXY, D_COMPONENT)
|
||||
|
@@ -59,10 +59,11 @@ class GenericMetric
|
||||
Singleton::Consume<I_Messaging>,
|
||||
Singleton::Consume<I_RestApi>,
|
||||
Singleton::Consume<I_Encryptor>,
|
||||
public Listener<AllMetricEvent>
|
||||
public Listener<AllMetricEvent>,
|
||||
public Listener<MetricScrapeEvent>
|
||||
{
|
||||
public:
|
||||
enum class Stream { FOG, DEBUG, PROMETHEUS, AIOPS, COUNT };
|
||||
enum class Stream { FOG, DEBUG, AIOPS, COUNT };
|
||||
|
||||
void
|
||||
init(
|
||||
@@ -72,7 +73,8 @@ public:
|
||||
std::chrono::seconds _report_interval,
|
||||
bool _reset,
|
||||
ReportIS::Audience _audience = ReportIS::Audience::INTERNAL,
|
||||
bool _force_buffering = false
|
||||
bool _force_buffering = false,
|
||||
const std::string &_asset_id = ""
|
||||
);
|
||||
|
||||
template <typename Value>
|
||||
@@ -96,6 +98,7 @@ public:
|
||||
void resetMetrics();
|
||||
void upon(const AllMetricEvent &) override;
|
||||
std::string respond(const AllMetricEvent &event) override;
|
||||
std::vector<PrometheusData> respond(const MetricScrapeEvent &event) override;
|
||||
std::string getListenerName() const override;
|
||||
|
||||
std::string getMetricName() const;
|
||||
@@ -113,9 +116,10 @@ private:
|
||||
friend class MetricCalc;
|
||||
void addCalc(MetricCalc *calc);
|
||||
|
||||
std::vector<PrometheusData> getPromMetricsData();
|
||||
|
||||
void handleMetricStreamSending();
|
||||
void generateLog();
|
||||
void generatePrometheus();
|
||||
void generateDebug();
|
||||
void generateAiopsLog();
|
||||
|
||||
@@ -127,10 +131,12 @@ private:
|
||||
ReportIS::Audience audience;
|
||||
std::chrono::seconds report_interval;
|
||||
std::vector<MetricCalc *> calcs;
|
||||
std::vector<MetricCalc *> prometheus_calcs;
|
||||
Flags<Stream> active_streams;
|
||||
bool reset;
|
||||
bool force_buffering = false;
|
||||
Context ctx;
|
||||
std::string asset_id;
|
||||
};
|
||||
|
||||
#include "metric/counter.h"
|
||||
|
@@ -25,6 +25,9 @@
|
||||
#include "customized_cereal_map.h"
|
||||
#include "compression_utils.h"
|
||||
#include "i_encryptor.h"
|
||||
#include "event.h"
|
||||
|
||||
USE_DEBUG_FLAG(D_METRICS);
|
||||
|
||||
class GenericMetric;
|
||||
|
||||
@@ -32,13 +35,35 @@ enum class MetricType { GAUGE, COUNTER };
|
||||
|
||||
struct PrometheusData
|
||||
{
|
||||
template <typename Archive>
|
||||
void
|
||||
serialize(Archive &ar)
|
||||
{
|
||||
try {
|
||||
ar(cereal::make_nvp("metric_name", name));
|
||||
ar(cereal::make_nvp("metric_type", type));
|
||||
ar(cereal::make_nvp("metric_description", description));
|
||||
ar(cereal::make_nvp("labels", label));
|
||||
ar(cereal::make_nvp("value", value));
|
||||
} catch (const cereal::Exception &e) {
|
||||
dbgTrace(D_METRICS) << "Error in serialize Prometheus data: " << e.what();
|
||||
}
|
||||
}
|
||||
|
||||
std::string name;
|
||||
std::string type;
|
||||
std::string desc;
|
||||
std::string description;
|
||||
std::string label;
|
||||
std::string value;
|
||||
};
|
||||
|
||||
class MetricScrapeEvent : public Event<MetricScrapeEvent, std::vector<PrometheusData>>
|
||||
{
|
||||
public:
|
||||
MetricScrapeEvent() {}
|
||||
|
||||
};
|
||||
|
||||
class AiopsMetricData
|
||||
{
|
||||
public:
|
||||
@@ -228,7 +253,10 @@ public:
|
||||
std::string getMetircDescription() const { return getMetadata("Description"); }
|
||||
std::string getMetadata(const std::string &metadata) const;
|
||||
virtual MetricType getMetricType() const { return MetricType::GAUGE; }
|
||||
virtual std::vector<PrometheusData> getPrometheusMetrics() const;
|
||||
virtual std::vector<PrometheusData> getPrometheusMetrics(
|
||||
const std::string &metric_name,
|
||||
const std::string &asset_id = ""
|
||||
) const;
|
||||
virtual float getValue() const = 0;
|
||||
virtual std::vector<AiopsMetricData> getAiopsMetrics() const;
|
||||
|
||||
@@ -240,7 +268,10 @@ public:
|
||||
|
||||
protected:
|
||||
void addMetric(GenericMetric *metric);
|
||||
std::map<std::string, std::string> getBasicLabels() const;
|
||||
std::map<std::string, std::string> getBasicLabels(
|
||||
const std::string &metric_name,
|
||||
const std::string &asset_id = ""
|
||||
) const;
|
||||
|
||||
template <typename Metadata, typename ... OtherMetadata>
|
||||
void
|
||||
|
@@ -55,12 +55,17 @@ class MetricMap : public MetricCalc
|
||||
}
|
||||
|
||||
std::vector<PrometheusData>
|
||||
getPrometheusMetrics(const std::string &label, const std::string &name) const
|
||||
getPrometheusMetrics(
|
||||
const std::string &metric_name,
|
||||
const std::string &label,
|
||||
const std::string &name,
|
||||
const std::string &asset_id
|
||||
) const
|
||||
{
|
||||
std::vector<PrometheusData> res;
|
||||
|
||||
for (auto &metric : inner_map) {
|
||||
auto sub_res = metric.second.getPrometheusMetrics();
|
||||
auto sub_res = metric.second.getPrometheusMetrics(metric_name, asset_id);
|
||||
for (auto &sub_metric : sub_res) {
|
||||
sub_metric.label += "," + label + "=\"" + metric.first + "\"";
|
||||
sub_metric.name = name;
|
||||
@@ -155,9 +160,9 @@ public:
|
||||
}
|
||||
|
||||
std::vector<PrometheusData>
|
||||
getPrometheusMetrics() const override
|
||||
getPrometheusMetrics(const std::string &metric_name, const std::string &asset_id) const override
|
||||
{
|
||||
return metric_map.getPrometheusMetrics(label, getMetricName());
|
||||
return metric_map.getPrometheusMetrics(metric_name, label, getMetricName(), asset_id);
|
||||
}
|
||||
|
||||
std::vector<AiopsMetricData>
|
||||
|
45
core/include/services_sdk/resources/metric/metric_scraper.h
Normal file
45
core/include/services_sdk/resources/metric/metric_scraper.h
Normal file
@@ -0,0 +1,45 @@
|
||||
// Copyright (C) 2022 Check Point Software Technologies Ltd. All rights reserved.
|
||||
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#ifndef __METRIC_SCRAPER_H__
|
||||
#define __METRIC_SCRAPER_H__
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <streambuf>
|
||||
|
||||
#include "singleton.h"
|
||||
#include "debug.h"
|
||||
#include "component.h"
|
||||
#include "event.h"
|
||||
#include "i_rest_api.h"
|
||||
#include "generic_metric.h"
|
||||
|
||||
class MetricScraper
|
||||
:
|
||||
public Component,
|
||||
Singleton::Consume<I_RestApi>
|
||||
{
|
||||
public:
|
||||
MetricScraper();
|
||||
~MetricScraper();
|
||||
|
||||
void init();
|
||||
|
||||
private:
|
||||
class Impl;
|
||||
std::unique_ptr<Impl> pimpl;
|
||||
};
|
||||
|
||||
#endif // __METRIC_SCRAPER_H__
|
Reference in New Issue
Block a user