/* Icinga 2 | (c) 2020 Icinga GmbH | GPLv2+ */ #ifndef ACCESSLOGGER_H #define ACCESSLOGGER_H #include "base/i2-base.hpp" #include "base/accesslogger-ti.hpp" #include "base/shared.hpp" #include "base/tlsstream.hpp" #include #include #include #include namespace icinga { class LogAccess { public: inline LogAccess( const AsioTlsStream& stream, const boost::beast::http::request& request, String user, const boost::beast::http::response& response ) : Stream(stream), Request(request), User(std::move(user)), Response(response) {} LogAccess(const LogAccess&) = delete; LogAccess(LogAccess&&) = delete; LogAccess& operator=(const LogAccess&) = delete; LogAccess& operator=(LogAccess&&) = delete; ~LogAccess(); const AsioTlsStream& Stream; const boost::beast::http::request& Request; String User; const boost::beast::http::response& Response; }; /** * A file logger that logs API access. * * @ingroup base */ class AccessLogger final : public ObjectImpl { friend LogAccess; public: typedef void FormatterFunc(const LogAccess& in, std::ostream& out); typedef std::function Formatter; DECLARE_OBJECT(AccessLogger); DECLARE_OBJECTNAME(AccessLogger); static void StatsFunc(const Dictionary::Ptr& status, const Array::Ptr& perfdata); protected: void OnAllConfigLoaded() override; void ValidateFormat(const Lazy& lvalue, const ValidationUtils& utils) override; void Register() override; void Unregister() override; private: Formatter ParseFormatter(const String& format); Formatter m_Formatter; }; } #endif /* ACCESSLOGGER_H */