osquery-1/osquery/logger/plugins/aws_firehose.h
Teddy Reed ce2ba6d9c8 Refactor logStatus and logger initialization (#2081)
The initialization of a logger plugin was confusing. The 'init' step was
introduced to allow a daemon to buffer status events before a logger plugin
is determined by external/remote configuration. The buffered statuses could
then be transferred via a medium other than Glog (the default). To determine
if Glog should continue to write statuses to the filesystem the 'init' method
returned a Status.

Logger plugins should now use a feature method override to select how status
logs should be handled.
2016-05-11 12:05:09 -07:00

67 lines
1.6 KiB
C++

/*
* 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/firehose/FirehoseClient.h>
#include <osquery/core.h>
#include <osquery/dispatcher.h>
#include <osquery/logger.h>
#include "osquery/logger/plugins/buffered.h"
namespace osquery {
DECLARE_uint64(aws_firehose_period);
class FirehoseLogForwarder : public BufferedLogForwarder {
private:
static const size_t kFirehoseMaxLogBytes;
static const size_t kFirehoseMaxRecords;
public:
FirehoseLogForwarder()
: BufferedLogForwarder("firehose",
std::chrono::seconds(FLAGS_aws_firehose_period),
kFirehoseMaxRecords) {}
Status setUp() override;
protected:
Status send(std::vector<std::string>& log_data,
const std::string& log_type) override;
private:
std::shared_ptr<Aws::Firehose::FirehoseClient> client_{nullptr};
FRIEND_TEST(FirehoseTests, test_send);
};
class FirehoseLoggerPlugin : public LoggerPlugin {
public:
FirehoseLoggerPlugin() : LoggerPlugin() {}
Status setUp() override;
protected:
void init(const std::string& name,
const std::vector<StatusLogLine>& log) override {}
Status logString(const std::string& s) override;
private:
std::shared_ptr<FirehoseLogForwarder> forwarder_{nullptr};
};
}