2016-04-25 23:19:51 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <aws/kinesis/KinesisClient.h>
|
|
|
|
|
|
|
|
#include <osquery/core.h>
|
|
|
|
#include <osquery/dispatcher.h>
|
|
|
|
#include <osquery/logger.h>
|
|
|
|
|
|
|
|
#include "osquery/logger/plugins/buffered.h"
|
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
|
|
|
DECLARE_uint64(aws_kinesis_period);
|
|
|
|
|
|
|
|
class KinesisLogForwarder : public BufferedLogForwarder {
|
|
|
|
private:
|
|
|
|
static const size_t kKinesisMaxLogBytes;
|
|
|
|
static const size_t kKinesisMaxRecords;
|
2017-04-04 16:54:56 +00:00
|
|
|
static const size_t kKinesisMaxRetryCount;
|
|
|
|
static const size_t kKinesisInitialRetryDelay;
|
2016-04-25 23:19:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
KinesisLogForwarder()
|
|
|
|
: BufferedLogForwarder("kinesis",
|
|
|
|
std::chrono::seconds(FLAGS_aws_kinesis_period),
|
|
|
|
kKinesisMaxRecords) {}
|
|
|
|
Status setUp() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
Status send(std::vector<std::string>& log_data,
|
|
|
|
const std::string& log_type) override;
|
|
|
|
|
|
|
|
private:
|
2016-06-15 22:29:59 +00:00
|
|
|
std::string partition_key_;
|
2016-04-25 23:19:51 +00:00
|
|
|
std::shared_ptr<Aws::Kinesis::KinesisClient> client_{nullptr};
|
|
|
|
|
|
|
|
FRIEND_TEST(KinesisTests, test_send);
|
|
|
|
};
|
|
|
|
|
|
|
|
class KinesisLoggerPlugin : public LoggerPlugin {
|
|
|
|
public:
|
|
|
|
KinesisLoggerPlugin() : LoggerPlugin() {}
|
|
|
|
|
|
|
|
Status setUp() override;
|
|
|
|
|
2017-04-04 16:54:56 +00:00
|
|
|
bool usesLogStatus() override {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-11 19:05:09 +00:00
|
|
|
private:
|
|
|
|
void init(const std::string& name,
|
2017-04-04 16:54:56 +00:00
|
|
|
const std::vector<StatusLogLine>& log) override;
|
2016-04-25 23:19:51 +00:00
|
|
|
|
|
|
|
Status logString(const std::string& s) override;
|
|
|
|
|
2017-04-04 16:54:56 +00:00
|
|
|
/// Log a status (ERROR/WARNING/INFO) message.
|
|
|
|
Status logStatus(const std::vector<StatusLogLine>& log) override;
|
|
|
|
|
2016-04-25 23:19:51 +00:00
|
|
|
private:
|
|
|
|
std::shared_ptr<KinesisLogForwarder> forwarder_{nullptr};
|
|
|
|
};
|
|
|
|
}
|