Kea: isc::dhcp::LegalLogMgr Class Reference

| Kea 3.2.0-git

isc::dhcp::LegalLogMgr Class Referenceabstract

LegalLogMgr abstract class. More...

`#include <legal_log_mgr.h>`

Inheritance diagram for isc::dhcp::LegalLogMgr:
[legend]

## 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 &timestamp_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 &parameters, isc::db::DatabaseConnection::ParameterMap &map)
| Parse database specification.
static void | parseDatabase (const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
| Parse database specification.
static void | parseExtraParameters (const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
| Parse extra parameters which are not related to backend connection.
static void | parseFile (const isc::data::ConstElementPtr &parameters, isc::db::DatabaseConnection::ParameterMap &map)
| Parse file specification.
static void | parseSyslog (const isc::data::ConstElementPtr &parameters, 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.

## Detailed Description

LegalLogMgr abstract class.

Definition at line 39 of file legal_log_mgr.h.

## Constructor & Destructor Documentation

## ◆ LegalLogMgr()

isc::dhcp::LegalLogMgr::LegalLogMgr | ( | const isc::db::DatabaseConnection::ParameterMap | parameters | ) |
| inline

Constructor.

Parameters

  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().

## ◆ ~LegalLogMgr()

virtual isc::dhcp::LegalLogMgr::~LegalLogMgr | ( |  | ) |
| virtualdefault

Destructor.

Derived destructors do call the close method.

## Member Function Documentation

## ◆ close()

virtual void isc::dhcp::LegalLogMgr::close | ( |  | ) |
| pure virtual

Closes the store.

Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.

## ◆ currentTimeInfo()

struct tm isc::dhcp::LegalLogMgr::currentTimeInfo | ( |  | ) | const
| virtual

Returns the current local date and time.

This is exposed primarily to simplify testing.

Definition at line 219 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().

Here is the call graph for this function:

## ◆ genDurationString()

string isc::dhcp::LegalLogMgr::genDurationString | ( | const uint32_t | secs | ) |
| 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

Parameters

  secs | Number of seconds to convert

Returns
  String containing the duration text

Definition at line 287 of file legal_log_mgr.cc.

Referenced by addDuration(), genLease4Entry(), and genLease6Entry().

## ◆ getLogPath()

std::string isc::dhcp::LegalLogMgr::getLogPath | ( | bool | reset = false,
|  | const std::string | explicit_path = "" )
| 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.

Parameters

  reset | recalculate when true, defaults to false.
  explicit_path | set default log path to this value. This is for testing purposes only.

Returns
  String containing the default log file path.

Definition at line 384 of file legal_log_mgr.cc.

Referenced by isc::legal_log::RotatingFile::apply(), and validatePath().

## ◆ getNowString() [1/2]

string isc::dhcp::LegalLogMgr::getNowString | ( |  | ) | const
| 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.

Returns
  std::string containing the formatted current date and time.

Exceptions

  LegalLogMgrError | if the result string is larger than 128 bytes.

Definition at line 234 of file legal_log_mgr.cc.

References getNowString().

Referenced by getNowString().

Here is the call graph for this function:

## ◆ getNowString() [2/2]

string isc::dhcp::LegalLogMgr::getNowString | ( | const std::string & | format | ) | const
| 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.

Parameters

  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".

Returns
  std::string containing the formatted current date and time.

Exceptions

  LegalLogMgrError | if the result string is larger than 128 bytes.

Definition at line 240 of file legal_log_mgr.cc.

References getTimeString(), and now().

Here is the call graph for this function:

## ◆ getParameters()

virtual isc::db::DatabaseConnection::ParameterMap isc::dhcp::LegalLogMgr::getParameters | ( |  | ) | const
| inlinevirtual

Return backend parameters.

Returns the backend parameters

Returns
  Parameters of the backend.

Definition at line 348 of file legal_log_mgr.h.

## ◆ getRequestFormatExpression()

isc::dhcp::ExpressionPtr isc::dhcp::LegalLogMgr::getRequestFormatExpression | ( |  | ) |
| inline

Gets request extended format expression for custom logging.

Returns
  The request extended format expression.

Definition at line 310 of file legal_log_mgr.h.

## ◆ getResponseFormatExpression()

isc::dhcp::ExpressionPtr isc::dhcp::LegalLogMgr::getResponseFormatExpression | ( |  | ) |
| inline

Gets response extended format expression for custom logging.

Returns
  The response extended format expression.

Definition at line 322 of file legal_log_mgr.h.

## ◆ getTimestampFormat()

std::string isc::dhcp::LegalLogMgr::getTimestampFormat | ( |  | ) |
| inline

Gets the timestamp format used for logging.

Returns
  The format for the string. Permissible formatting is the one supported by strftime plus the 'Q' extra format which adds the microseconds subunits.

Definition at line 339 of file legal_log_mgr.h.

## ◆ getTimeString()

string isc::dhcp::LegalLogMgr::getTimeString | ( | const struct timespec & | time,
|  | const std::string & | format )
| 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.

Parameters

  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".

Returns
  std::string containing the formatted current date and time

Exceptions

  LegalLogMgrError | if the result string is larger than 128 bytes.

Definition at line 246 of file legal_log_mgr.cc.

References isc_throw.

Referenced by getNowString().

## ◆ getType()

virtual std::string isc::dhcp::LegalLogMgr::getType | ( |  | ) | const
| pure virtual

Return backend type.

Returns the type of the backend (e.g. "mysql", "logfile" etc.)

Returns
  Type of the backend.

Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.

References currentTimeInfo(), and now().

Here is the call graph for this function:

## ◆ isUnusable()

virtual bool isc::dhcp::LegalLogMgr::isUnusable | ( |  | ) |
| inlinevirtual

Flag which indicates if the forensic log backend has at least one unusable connection.

Returns
  true if there is at least one unusable connection, false otherwise

Definition at line 366 of file legal_log_mgr.h.

## ◆ now()

struct timespec isc::dhcp::LegalLogMgr::now | ( |  | ) | const
| virtual

Returns the current system time.

This is exposed primarily to simplify testing.

Definition at line 227 of file legal_log_mgr.cc.

References LegalLogMgr(), and now().

Referenced by currentTimeInfo(), getNowString(), getType(), and now().

Here is the call graph for this function:

## ◆ open()

virtual void isc::dhcp::LegalLogMgr::open | ( |  | ) |
| pure virtual

Opens the store.

Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.

## ◆ parseConfig()

void isc::dhcp::LegalLogMgr::parseConfig | ( | const isc::data::ConstElementPtr & | parameters,
|  | isc::db::DatabaseConnection::ParameterMap & | map )
| static

Parse database specification.

Parse the configuration and check that the various keywords are consistent.

Note
  The supported parameters are:
  - common parameters:
    - type - one of: logfile (default), syslog, mysql, postgresql
    - request-parser-format
    - response-parser-format
    - timestamp-format
  - logfile parameters:
    - path
    - base-name
    - time-unit - one of: second, day, month, year
    - prerotate
    - postrotate
    - count
  - syslog parameters:
    - pattern
    - facility
  - database parameters:
    - name
    - host
    - password
    - port
    - user
    - trust-anchor
    - cert-file
    - key-file
    - ssl-mode (PostgreSQL only)
    - cipher-list (MySQL only)
    - reconnect-wait-time
    - max-reconnect-tries
    - on-fail
    - retry-on-startup
    - connect-timeout
    - read-timeout (MySQL only)
    - write-timeout (MySQL only)
    - tcp-user-timeout (PostgreSQL only)

Parameters

  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().

Here is the call graph for this function:

## ◆ parseDatabase()

void isc::dhcp::LegalLogMgr::parseDatabase | ( | const isc::data::ConstElementPtr & | parameters,
|  | isc::db::DatabaseConnection::ParameterMap & | map )
| static

Parse database specification.

Code adapted from isc::dhcp::DbAccessParser::parse

Parse the configuration and check that the various keywords are consistent.

Note
  The supported parameters are:
  - database parameters:
    - name
    - host
    - password
    - port
    - user
    - trust-anchor
    - cert-file
    - key-file
    - ssl-mode (PostgreSQL only)
    - cipher-list (MySQL only)
    - reconnect-wait-time
    - max-reconnect-tries
    - on-fail
    - retry-on-startup
    - connect-timeout
    - read-timeout (MySQL only)
    - write-timeout (MySQL only)
    - tcp-user-timeout (PostgreSQL only)

Parameters

  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().

Here is the call graph for this function:

## ◆ parseExtraParameters()

void isc::dhcp::LegalLogMgr::parseExtraParameters | ( | const isc::data::ConstElementPtr & | parameters,
|  | isc::db::DatabaseConnection::ParameterMap & | map )
| static

Parse extra parameters which are not related to backend connection.

Note
  The supported parameters are:
  - common parameters:
    - request-parser-format
    - response-parser-format
    - timestamp-format

Parameters

  | parameters | The library parameters.
  [out] | map | The parameter map.

Definition at line 204 of file legal_log_mgr.cc.

Referenced by parseConfig().

## ◆ parseFile()

void isc::dhcp::LegalLogMgr::parseFile | ( | const isc::data::ConstElementPtr & | parameters,
|  | isc::db::DatabaseConnection::ParameterMap & | map )
| static

Parse file specification.

Parse the configuration and check that the various keywords are consistent.

Note
  The supported parameters are:
  - logfile parameters:
    - path
    - base-name
    - time-unit - one of: second, day, month, year
    - prerotate
    - postrotate
    - count

Parameters

  | parameters | The library parameters.
  [out] | map | The parameter map.

Definition at line 157 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().

Here is the call graph for this function:

## ◆ parseSyslog()

void isc::dhcp::LegalLogMgr::parseSyslog | ( | const isc::data::ConstElementPtr & | parameters,
|  | isc::db::DatabaseConnection::ParameterMap & | map )
| static

Parse syslog specification.

Parse the configuration and check that the various keywords are consistent.

Note
  The supported parameters are:
  - syslog parameters:
    - pattern
    - facility

Parameters

  | parameters | The library parameters.
  [out] | map | The parameter map.

Definition at line 136 of file legal_log_mgr.cc.

References isc_throw.

Referenced by parseConfig().

## ◆ setParameters()

virtual void isc::dhcp::LegalLogMgr::setParameters | ( | isc::db::DatabaseConnection::ParameterMap | parameters | ) |
| inlinevirtual

Sets backend parameters.

Sets the backend parameters

Parameters

  parameters | Parameters of the backend.

Definition at line 357 of file legal_log_mgr.h.

## ◆ setRequestFormatExpression()

void isc::dhcp::LegalLogMgr::setRequestFormatExpression | ( | const std::string & | extended_format | ) |

Sets request extended format expression for custom logging.

Parameters

  extended_format | The request extended format expression.

Definition at line 341 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.

Here is the call graph for this function:

## ◆ setResponseFormatExpression()

void isc::dhcp::LegalLogMgr::setResponseFormatExpression | ( | const std::string & | extended_format | ) |

Sets response extended format expression for custom logging.

Parameters

  extended_format | The response extended format expression.

Definition at line 354 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.

Here is the call graph for this function:

## ◆ setTimestampFormat()

void isc::dhcp::LegalLogMgr::setTimestampFormat | ( | const std::string & | timestamp_format | ) |

Sets the timestamp format used for logging.

Parameters

  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 367 of file legal_log_mgr.cc.

## ◆ validatePath()

std::string isc::dhcp::LegalLogMgr::validatePath | ( | const std::string | logpath | ) |
| static

Validates a log path against the supported path for legal log files.

Parameters

  logpath | path to validate.

Returns
  validated path

Definition at line 396 of file legal_log_mgr.cc.

References getLogPath().

Referenced by parseFile().

Here is the call graph for this function:

## ◆ vectorDump()

string isc::dhcp::LegalLogMgr::vectorDump | ( | const std::vector< uint8_t > & | bytes | ) |
| static

Creates a string from a vector of printable bytes.

This assumes that str::isPrintable was called and returned true.

Parameters

  bytes | Vector of bytes to convert

Definition at line 333 of file legal_log_mgr.cc.

Referenced by genLease4Entry(), genLease6Entry(), and handleLease4Cmds().

## ◆ vectorHexDump()

string isc::dhcp::LegalLogMgr::vectorHexDump | ( | const std::vector< uint8_t > & | bytes,
|  | const std::string & | delimiter = ":" )
| static

Creates a string of hex digit pairs from a vector of bytes.

Parameters

  bytes | Vector of bytes to convert
  delimiter | String to use a delimiter, defaults to ":"

Returns
  std::string containing the hex output

Definition at line 317 of file legal_log_mgr.cc.

Referenced by genLease4Entry(), and genLease6Entry().

## ◆ writeln()

virtual void isc::dhcp::LegalLogMgr::writeln | ( | const std::string & | text,
|  | const std::string & | addr )
| pure virtual

Appends a string to the store with a timestamp and address.

Parameters

  text | String to append
  addr | Address or prefix

Exceptions

  LegalLogMgrError | if the write fails

Implemented in isc::legal_log::LegalSyslog, and isc::legal_log::RotatingFile.

The documentation for this class was generated from the following files:

- legal_log_mgr.h
- legal_log_mgr.cc