Kea 3.3.1
legal_log_mgr.h
Go to the documentation of this file.
1// Copyright (C) 2020-2026 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
124
157
176
190
203
205 virtual void open() = 0;
206
208 virtual void close() = 0;
209
215 virtual void writeln(const std::string& text, const std::string& addr) = 0;
216
222 virtual std::string getType() const = 0;
223
227 virtual struct tm currentTimeInfo() const;
228
232 virtual struct timespec now() const;
233
243 virtual std::string getNowString() const;
244
257 virtual std::string getNowString(const std::string& format) const;
258
271 static std::string getTimeString(const struct timespec& time, const std::string& format);
272
288 static std::string genDurationString(const uint32_t secs);
289
295 static std::string vectorDump(const std::vector<uint8_t>& bytes);
296
300 void setRequestFormatExpression(const std::string& extended_format);
301
306 return (request_expression_);
307 }
308
312 void setResponseFormatExpression(const std::string& extended_format);
313
318 return (response_expression_);
319 }
320
327 void setTimestampFormat(const std::string& timestamp_format);
328
334 std::string getTimestampFormat() {
335 return (timestamp_format_);
336 }
337
344 return (parameters_);
345 }
346
353 parameters_ = parameters;
354 }
355
361 virtual bool isUnusable() {
362 return (false);
363 }
364
365private:
366
368 isc::dhcp::ExpressionPtr request_expression_;
369
371 isc::dhcp::ExpressionPtr response_expression_;
372
374 std::string timestamp_format_;
375
378};
379
381typedef uint64_t ManagerID;
382
384typedef std::map<ManagerID, std::pair<isc::db::DatabaseConnection::ParameterMap, LegalLogMgrPtr>> LegalLogMgrPool;
385
387enum class Action { ASSIGN, RELEASE };
388
393const std::string actionToVerb(Action action);
394
395} // namespace dhcp
396} // namespace isc
397
398#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.
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:30
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.