Kea 3.1.1
legal_log_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2020-2025 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef LEGAL_LOG_MGR_H
8#define LEGAL_LOG_MGR_H
9
11
12#include <asiolink/io_service.h>
14#include <eval/token.h>
16
17#include <boost/shared_ptr.hpp>
18
19#include <fstream>
20#include <string>
21
22namespace isc {
23namespace dhcp {
24
27public:
28 LegalLogMgrError(const char* file, size_t line, const char* what) :
29 isc::Exception(file, line, what)
30 {}
31};
32
33class LegalLogMgr;
34
36typedef boost::shared_ptr<LegalLogMgr> LegalLogMgrPtr;
37
40public:
46 timestamp_format_("%Y-%m-%d %H:%M:%S %Z"),
47 parameters_(parameters) {
48 }
49
53 virtual ~LegalLogMgr() = default;
54
67 static std::string getLogPath(bool reset = false,
68 const std::string explicit_path = "");
69
76 static std::string validatePath(const std::string logpath);
77
122
154
172
186
199
201 virtual void open() = 0;
202
204 virtual void close() = 0;
205
211 virtual void writeln(const std::string& text, const std::string& addr) = 0;
212
218 virtual std::string getType() const = 0;
219
223 virtual struct tm currentTimeInfo() const;
224
228 virtual struct timespec now() const;
229
239 virtual std::string getNowString() const;
240
253 virtual std::string getNowString(const std::string& format) const;
254
267 static std::string getTimeString(const struct timespec& time, const std::string& format);
268
284 static std::string genDurationString(const uint32_t secs);
285
292 static std::string vectorHexDump(const std::vector<uint8_t>& bytes,
293 const std::string& delimiter = ":");
294
300 static std::string vectorDump(const std::vector<uint8_t>& bytes);
301
305 void setRequestFormatExpression(const std::string& extended_format);
306
311 return (request_expression_);
312 }
313
317 void setResponseFormatExpression(const std::string& extended_format);
318
323 return (response_expression_);
324 }
325
332 void setTimestampFormat(const std::string& timestamp_format);
333
339 std::string getTimestampFormat() {
340 return (timestamp_format_);
341 }
342
349 return (parameters_);
350 }
351
358 parameters_ = parameters;
359 }
360
366 virtual bool isUnusable() {
367 return (false);
368 }
369
370private:
371
373 isc::dhcp::ExpressionPtr request_expression_;
374
376 isc::dhcp::ExpressionPtr response_expression_;
377
379 std::string timestamp_format_;
380
383};
384
386typedef uint64_t ManagerID;
387
389typedef std::map<ManagerID, std::pair<isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr>> LegalLogMgrPool;
390
392enum class Action { ASSIGN, RELEASE };
393
398const std::string actionToVerb(Action action);
399
400} // namespace dhcp
401} // namespace isc
402
403#endif // LEGAL_LOG_MGR_H
This is a base class for exceptions thrown from the DNS library module.
Exception(const char *file, size_t line, const char *what)
Constructor for a given type for exceptions with file name and file line number.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
std::map< std::string, std::string > ParameterMap
Database configuration parameter map.
LegalLogMgrError(const char *file, size_t line, const char *what)
isc::dhcp::ExpressionPtr getResponseFormatExpression()
Gets response extended format expression for custom logging.
virtual struct tm currentTimeInfo() const
Returns the current local date and time.
void setRequestFormatExpression(const std::string &extended_format)
Sets request extended format expression for custom logging.
virtual bool isUnusable()
Flag which indicates if the forensic log backend has at least one unusable connection.
static void parseSyslog(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse syslog specification.
static void parseFile(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse file specification.
static std::string vectorHexDump(const std::vector< uint8_t > &bytes, const std::string &delimiter=":")
Creates a string of hex digit pairs from a vector of bytes.
virtual void setParameters(isc::db::DatabaseConnection::ParameterMap parameters)
Sets backend parameters.
virtual std::string getType() const =0
Return backend type.
virtual ~LegalLogMgr()=default
Destructor.
std::string getTimestampFormat()
Gets the timestamp format used for logging.
static void parseDatabase(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setResponseFormatExpression(const std::string &extended_format)
Sets response extended format expression for custom logging.
virtual void writeln(const std::string &text, const std::string &addr)=0
Appends a string to the store with a timestamp and address.
static std::string genDurationString(const uint32_t secs)
Translates seconds into a text string of days, hours, minutes and seconds.
static std::string validatePath(const std::string logpath)
Validates a log path against the supported path for legal log files.
virtual struct timespec now() const
Returns the current system time.
static std::string getTimeString(const struct timespec &time, const std::string &format)
Returns a time as string.
virtual void close()=0
Closes the store.
static std::string getLogPath(bool reset=false, const std::string explicit_path="")
Fetches the supported legal log file path.
virtual isc::db::DatabaseConnection::ParameterMap getParameters() const
Return backend parameters.
static std::string vectorDump(const std::vector< uint8_t > &bytes)
Creates a string from a vector of printable bytes.
LegalLogMgr(const isc::db::DatabaseConnection::ParameterMap parameters)
Constructor.
isc::dhcp::ExpressionPtr getRequestFormatExpression()
Gets request extended format expression for custom logging.
static void parseConfig(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse database specification.
void setTimestampFormat(const std::string &timestamp_format)
Sets the timestamp format used for logging.
static void parseExtraParameters(const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
Parse extra parameters which are not related to backend connection.
virtual void open()=0
Opens the store.
virtual std::string getNowString() const
Returns the current date and time as string.
boost::shared_ptr< const Element > ConstElementPtr
Definition data.h:29
boost::shared_ptr< LegalLogMgr > LegalLogMgrPtr
Defines a smart pointer to a LegalLogMgr.
const string actionToVerb(Action action)
Translates an Action into its corresponding verb.
boost::shared_ptr< Expression > ExpressionPtr
Definition token.h:31
std::map< ManagerID, std::pair< isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr > > LegalLogMgrPool
LegalLogMgr pool.
uint64_t ManagerID
Manger ID used by hook libraries to retrieve respective LegalLogMgr instance.
Action
Describe what kind of event is being logged.
Defines the logger used by the top-level component of kea-lfc.