![]() |
Kea 3.1.1
|
LegalLogMgr abstract class. More...
#include <legal_log_mgr.h>
Public Member Functions | |
LegalLogMgr (const isc::db::DatabaseConnection::ParameterMap parameters) | |
Constructor. | |
virtual | ~LegalLogMgr ()=default |
Destructor. | |
virtual void | close ()=0 |
Closes the store. | |
virtual struct tm | currentTimeInfo () const |
Returns the current local date and time. | |
virtual std::string | getNowString () const |
Returns the current date and time as string. | |
virtual std::string | getNowString (const std::string &format) const |
Returns the current date and time as a string using a specific strftime format string. | |
virtual isc::db::DatabaseConnection::ParameterMap | getParameters () const |
Return backend parameters. | |
isc::dhcp::ExpressionPtr | getRequestFormatExpression () |
Gets request extended format expression for custom logging. | |
isc::dhcp::ExpressionPtr | getResponseFormatExpression () |
Gets response extended format expression for custom logging. | |
std::string | getTimestampFormat () |
Gets the timestamp format used for logging. | |
virtual std::string | getType () const =0 |
Return backend type. | |
virtual bool | isUnusable () |
Flag which indicates if the forensic log backend has at least one unusable connection. | |
virtual struct timespec | now () const |
Returns the current system time. | |
virtual void | open ()=0 |
Opens the store. | |
virtual void | setParameters (isc::db::DatabaseConnection::ParameterMap parameters) |
Sets backend parameters. | |
void | setRequestFormatExpression (const std::string &extended_format) |
Sets request extended format expression for custom logging. | |
void | setResponseFormatExpression (const std::string &extended_format) |
Sets response extended format expression for custom logging. | |
void | setTimestampFormat (const std::string ×tamp_format) |
Sets the timestamp format used for 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 Public Member Functions | |
static std::string | genDurationString (const uint32_t secs) |
Translates seconds into a text string of days, hours, minutes and seconds. | |
static std::string | getLogPath (bool reset=false, const std::string explicit_path="") |
Fetches the supported legal log file path. | |
static std::string | getTimeString (const struct timespec &time, const std::string &format) |
Returns a time as string. | |
static void | parseConfig (const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map) |
Parse database specification. | |
static void | parseDatabase (const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map) |
Parse database specification. | |
static void | parseExtraParameters (const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map) |
Parse extra parameters which are not related to backend connection. | |
static void | parseFile (const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map) |
Parse file specification. | |
static void | parseSyslog (const isc::data::ConstElementPtr ¶meters, isc::db::DatabaseConnection::ParameterMap &map) |
Parse syslog specification. | |
static std::string | validatePath (const std::string logpath) |
Validates a log path against the supported path for legal log files. | |
static std::string | vectorDump (const std::vector< uint8_t > &bytes) |
Creates a string from a vector of printable bytes. | |
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. | |
LegalLogMgr abstract class.
Definition at line 39 of file legal_log_mgr.h.
|
inline |
Constructor.
parameters | A data structure relating keywords and values concerned with the manager configuration. |
Definition at line 45 of file legal_log_mgr.h.
Referenced by isc::legal_log::LegalSyslog::LegalSyslog(), isc::legal_log::RotatingFile::RotatingFile(), currentTimeInfo(), and now().
|
virtualdefault |
Destructor.
Derived destructors do call the close method.
|
pure virtual |
Closes the store.
Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.
|
virtual |
Returns the current local date and time.
This is exposed primarily to simplify testing.
Definition at line 226 of file legal_log_mgr.cc.
References LegalLogMgr(), currentTimeInfo(), and now().
Referenced by currentTimeInfo(), getType(), isc::legal_log::RotatingFile::open(), and isc::legal_log::RotatingFile::rotate().
|
static |
Translates seconds into a text string of days, hours, minutes and seconds.
The output string will have the following format:
"{<d> day(s) }<h> hrs <m> min <s> secs" Examples:
0 hrs 0 min 30 secs 2 hrs 11 min 50 secs 1 day 1 hrs 0 min 0 secs 60 days 0 hrs 0 min 10 secs
secs | Number of seconds to convert |
Definition at line 294 of file legal_log_mgr.cc.
Referenced by addDuration(), genLease4Entry(), and genLease6Entry().
|
static |
Fetches the supported legal log file path.
The first call to this function with no arguments will set the default legal log path to either the value of LEGAL_LOG_DIR or the environment variable KEA_LEGAL LOG_DIR if it is defined. Subsequent calls with no arguments will simply return this value.
reset | recalculate when true, defaults to false. |
explicit_path | set default log path to this value. This is for testing purposes only. |
Definition at line 391 of file legal_log_mgr.cc.
Referenced by isc::legal_log::RotatingFile::apply(), and validatePath().
|
virtual |
Returns the current date and time as string.
Returns the current local date and time as a string. The date and time is formatted according to the hook's timestamp_format parameter, or "%Y-%m-%d %H:%M:%S %Z" by default if not configured otherwise. The maximum length of the result is 128 bytes.
LegalLogMgrError | if the result string is larger than 128 bytes. |
Definition at line 241 of file legal_log_mgr.cc.
References getNowString().
Referenced by getNowString().
|
virtual |
Returns the current date and time as a string using a specific strftime format string.
Returns the current local date and time as a string based on the given format. Maximum length of the result is 128 bytes.
format | Desired format for the string. Permissible formatting is that supported by strftime plus the 'Q' extra format which adds the microseconds subunits. The default is: "%Y-%m-%d %H:%M:%S %Z". |
LegalLogMgrError | if the result string is larger than 128 bytes. |
Definition at line 247 of file legal_log_mgr.cc.
References getTimeString(), and now().
|
inlinevirtual |
Return backend parameters.
Returns the backend parameters
Definition at line 348 of file legal_log_mgr.h.
|
inline |
Gets request extended format expression for custom logging.
Definition at line 310 of file legal_log_mgr.h.
|
inline |
Gets response extended format expression for custom logging.
Definition at line 322 of file legal_log_mgr.h.
|
inline |
Gets the timestamp format used for logging.
Definition at line 339 of file legal_log_mgr.h.
|
static |
Returns a time as string.
Returns the time as a string based on the given format. Maximum length of the result is 128 bytes.
time | Time to format. |
format | Desired format for the string. Permissible formatting is that supported by strftime plus the 'Q' extra format which adds the microseconds subunits. The default is: "%Y-%m-%d %H:%M:%S %Z". |
LegalLogMgrError | if the result string is larger than 128 bytes. |
Definition at line 253 of file legal_log_mgr.cc.
References isc_throw.
Referenced by getNowString().
|
pure virtual |
Return backend type.
Returns the type of the backend (e.g. "mysql", "logfile" etc.)
Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.
References currentTimeInfo(), and now().
|
inlinevirtual |
Flag which indicates if the forensic log backend has at least one unusable connection.
Definition at line 366 of file legal_log_mgr.h.
|
virtual |
Returns the current system time.
This is exposed primarily to simplify testing.
Definition at line 234 of file legal_log_mgr.cc.
References LegalLogMgr(), and now().
Referenced by currentTimeInfo(), getNowString(), getType(), and now().
|
pure virtual |
Opens the store.
Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.
|
static |
Parse database specification.
Parse the configuration and check that the various keywords are consistent.
parameters | The library parameters. |
map | The parameter map used by LegalLogMgr objects. |
Definition at line 45 of file legal_log_mgr.cc.
References parseDatabase(), parseExtraParameters(), parseFile(), and parseSyslog().
Referenced by load().
|
static |
Parse database specification.
Code adapted from isc::dhcp::DbAccessParser::parse
Parse the configuration and check that the various keywords are consistent.
parameters | The library parameters. |
map | The parameter map used by LegalLogMgr objects. |
Definition at line 58 of file legal_log_mgr.cc.
References isc_throw, isc::util::ReconnectCtl::onFailActionFromText(), isc::util::ReconnectCtl::onFailActionToText(), isc::db::DatabaseConnection::redactedAccessString(), and isc::util::SERVE_RETRY_CONTINUE.
Referenced by parseConfig().
|
static |
Parse extra parameters which are not related to backend connection.
parameters | The library parameters. | |
[out] | map | The parameter map. |
Definition at line 211 of file legal_log_mgr.cc.
Referenced by parseConfig().
|
static |
Parse file specification.
Parse the configuration and check that the various keywords are consistent.
parameters | The library parameters. | |
[out] | map | The parameter map. |
Definition at line 164 of file legal_log_mgr.cc.
References isc::dhcp::dhcpsrv_logger, isc_throw, isc::dhcp::LEGAL_LOG_PATH_SECURITY_WARNING, LOG_WARN, validatePath(), and isc::Exception::what().
Referenced by parseConfig().
|
static |
Parse syslog specification.
Parse the configuration and check that the various keywords are consistent.
parameters | The library parameters. | |
[out] | map | The parameter map. |
Definition at line 143 of file legal_log_mgr.cc.
References isc_throw.
Referenced by parseConfig().
|
inlinevirtual |
Sets backend parameters.
Sets the backend parameters
parameters | Parameters of the backend. |
Definition at line 357 of file legal_log_mgr.h.
void isc::dhcp::LegalLogMgr::setRequestFormatExpression | ( | const std::string & | extended_format | ) |
Sets request extended format expression for custom logging.
extended_format | The request extended format expression. |
Definition at line 348 of file legal_log_mgr.cc.
References isc::eval::EvalContext::expression_, isc::dhcp::CfgMgr::instance(), isc::eval::EvalContext::PARSER_STRING, isc::eval::EvalContext::parseString(), isc::dhcp::Option::V4, and isc::dhcp::Option::V6.
void isc::dhcp::LegalLogMgr::setResponseFormatExpression | ( | const std::string & | extended_format | ) |
Sets response extended format expression for custom logging.
extended_format | The response extended format expression. |
Definition at line 361 of file legal_log_mgr.cc.
References isc::eval::EvalContext::expression_, isc::dhcp::CfgMgr::instance(), isc::eval::EvalContext::PARSER_STRING, isc::eval::EvalContext::parseString(), isc::dhcp::Option::V4, and isc::dhcp::Option::V6.
void isc::dhcp::LegalLogMgr::setTimestampFormat | ( | const std::string & | timestamp_format | ) |
Sets the timestamp format used for logging.
timestamp_format | Desired format for the string. Permissible formatting is the one supported by strftime plus the 'Q' extra format which adds the microseconds subunits. The default is: "%Y-%m-%d %H:%M:%S %Z". |
Definition at line 374 of file legal_log_mgr.cc.
|
static |
Validates a log path against the supported path for legal log files.
logpath | path to validate. |
Definition at line 403 of file legal_log_mgr.cc.
References getLogPath().
Referenced by parseFile().
|
static |
Creates a string from a vector of printable bytes.
This assumes that str::isPrintable was called and returned true.
bytes | Vector of bytes to convert |
Definition at line 340 of file legal_log_mgr.cc.
Referenced by genLease4Entry(), genLease6Entry(), and handleLease4Cmds().
|
static |
Creates a string of hex digit pairs from a vector of bytes.
bytes | Vector of bytes to convert |
delimiter | String to use a delimiter, defaults to ":" |
Definition at line 324 of file legal_log_mgr.cc.
Referenced by genLease4Entry(), and genLease6Entry().
|
pure virtual |
Appends a string to the store with a timestamp and address.
text | String to append |
addr | Address or prefix |
LegalLogMgrError | if the write fails |
Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.