2019-04-30 22:06:02 +03:00
|
|
|
/*
|
|
|
|
microsoft-oms-auditd-plugin
|
|
|
|
|
|
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
MIT License
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef AUOMS_EVENTACCUMULATOR_H
|
|
|
|
#define AUOMS_EVENTACCUMULATOR_H
|
|
|
|
|
|
|
|
#include "RawEventRecord.h"
|
2019-11-22 01:55:06 +03:00
|
|
|
#include "Metrics.h"
|
|
|
|
#include "Cache.h"
|
2019-04-30 22:06:02 +03:00
|
|
|
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
class RawEvent {
|
|
|
|
public:
|
|
|
|
static constexpr size_t MAX_EVENT_SIZE = 112*1024; // Prevent runaway accumulation of records for an event
|
|
|
|
static constexpr size_t MAX_EXECVE_ACCUM_SIZE = 96*1024; // Prevent runaway accumulation of records for an event
|
|
|
|
static constexpr size_t MAX_NUM_EXECVE_RECORDS = 12; // Make sure there will be room in event for PATH/CWD records that follow EXECVE records.
|
|
|
|
static constexpr size_t NUM_EXECVE_RH_PRESERVE = 3;
|
|
|
|
|
|
|
|
RawEvent() = delete;
|
2019-11-22 01:55:06 +03:00
|
|
|
explicit RawEvent(EventId event_id): _event_id(event_id), _num_execve_records(0), _num_dropped_records(0), _syscall_rec_idx(-1), _size(0), _execve_size(0) {}
|
|
|
|
|
|
|
|
inline EventId GetEventId() { return _event_id; }
|
2019-04-30 22:06:02 +03:00
|
|
|
|
|
|
|
// Returns true if the event is now complete;
|
|
|
|
bool AddRecord(std::unique_ptr<RawEventRecord> record);
|
|
|
|
|
|
|
|
int AddEvent(EventBuilder& builder);
|
|
|
|
|
|
|
|
private:
|
|
|
|
EventId _event_id;
|
|
|
|
std::vector<std::unique_ptr<RawEventRecord>> _records;
|
|
|
|
std::vector<std::unique_ptr<RawEventRecord>> _execve_records;
|
|
|
|
std::unordered_map<RecordType, int> _drop_count;
|
|
|
|
int _num_execve_records;
|
|
|
|
int _num_dropped_records;
|
2019-11-22 01:55:06 +03:00
|
|
|
int _syscall_rec_idx;
|
2019-04-30 22:06:02 +03:00
|
|
|
size_t _size;
|
|
|
|
size_t _execve_size;
|
|
|
|
};
|
|
|
|
|
|
|
|
class RawEventAccumulator {
|
|
|
|
public:
|
2019-11-22 01:55:06 +03:00
|
|
|
explicit RawEventAccumulator(const std::shared_ptr<EventBuilder>& builder, const std::shared_ptr<Metrics>& metrics): _builder(builder), _metrics(metrics) {
|
2020-08-24 20:10:32 +03:00
|
|
|
_bytes_metric = _metrics->AddMetric(MetricType::METRIC_BY_ACCUMULATION, "raw_data", "bytes", MetricPeriod::SECOND, MetricPeriod::HOUR);
|
|
|
|
_record_metric = _metrics->AddMetric(MetricType::METRIC_BY_ACCUMULATION, "raw_data", "records", MetricPeriod::SECOND, MetricPeriod::HOUR);
|
|
|
|
_event_metric = _metrics->AddMetric(MetricType::METRIC_BY_ACCUMULATION, "raw_data", "events", MetricPeriod::SECOND, MetricPeriod::HOUR);
|
2019-11-22 01:55:06 +03:00
|
|
|
}
|
2019-04-30 22:06:02 +03:00
|
|
|
|
|
|
|
int AddRecord(std::unique_ptr<RawEventRecord> record);
|
|
|
|
void Flush(long milliseconds);
|
|
|
|
|
|
|
|
private:
|
2020-06-10 23:09:59 +03:00
|
|
|
static constexpr size_t MAX_CACHE_ENTRY = 256;
|
2019-04-30 22:06:02 +03:00
|
|
|
std::mutex _mutex;
|
|
|
|
std::shared_ptr<EventBuilder> _builder;
|
2019-11-22 01:55:06 +03:00
|
|
|
std::shared_ptr<Metrics> _metrics;
|
|
|
|
std::shared_ptr<Metric> _bytes_metric;
|
|
|
|
std::shared_ptr<Metric> _record_metric;
|
|
|
|
std::shared_ptr<Metric> _event_metric;
|
|
|
|
Cache<EventId, std::shared_ptr<RawEvent>> _events;
|
2019-04-30 22:06:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //AUOMS_EVENTACCUMULATOR_H
|