Kea 2.5.8
isc::db::AuditEntry Class Reference

Represents a single entry in the audit table. More...

#include <audit_entry.h>

Public Types

enum class  ModificationType : uint8_t { CREATE = 0 , UPDATE = 1 , DELETE = 2 }
 Types of the modifications. More...
 

Public Member Functions

 AuditEntry (const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const boost::posix_time::ptime &modification_time, const uint64_t revision_id, const std::string &log_message)
 Constructor using explicit modification time and id.
 
 AuditEntry (const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const uint64_t revision_id, const std::string &log_message)
 Constructor using default modification time.
 
std::string getLogMessage () const
 Returns log message.
 
boost::posix_time::ptime getModificationTime () const
 Returns modification time.
 
ModificationType getModificationType () const
 Returns modification type.
 
uint64_t getObjectId () const
 Returns object id.
 
std::string getObjectType () const
 Returns object type.
 
uint64_t getRevisionId () const
 Returns revision id.
 

Static Public Member Functions

static AuditEntryPtr create (const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const boost::posix_time::ptime &modification_time, const uint64_t revision_id, const std::string &log_message)
 Factory function creating an instance of AuditEntry.
 
static AuditEntryPtr create (const std::string &object_type, const uint64_t object_id, const ModificationType &modification_type, const uint64_t revision_id, const std::string &log_message)
 Factory function creating an instance of AuditEntry.
 

Detailed Description

Represents a single entry in the audit table.

The audit tables are used in the databases to track incremental changes, e.g. configuration changes applied via the configuration backend. The backend can query for the entries in the audit table to identify the SQL table in which the records were modified, the identifiers of the modified objects, type of the modifications, time of the modifications and optional log messages associated with the modifications.

The server should remember the most recent modification time out of all audit entries it has fetched. During the next attempt to fetch the most recent modifications in the database it will query for all entries with later modification time than stored. That way the server queries only for the audit entries it hasn't fetched yet. In the case two (or more) successive audit entries have the same modification time the strictly increasing modification id is used.

When the modification type of the entry is set to AuditEntry::ModificationType::DELETE, the corresponding configuration entry is already gone from the database. For example: when a subnet with ID of 123 is deleted from the dhcp4_subnet table, the audit entry similar to this will be stored in the audit table:

  • object_type: "dhcp4_subnet"
  • object_id: 123
  • modification_type: 3 (DELETE)
  • modification_time: "2019-01-15 15:45:23"
  • revision id: 234
  • log_message: "DHCPv4 subnet 123 deleted"

The subnet is instantly removed from the dhcp4_subnet table. When the server finds such entry in the audit table, it removes the subnet 123 from its (in-memory) configuration. There is no need make additional queries to fetch updated data from the dhcp4_subnet table, unless there are also audit entries indicating that some new subnets have been added or some subnets have been updated.

Definition at line 66 of file audit_entry.h.

Member Enumeration Documentation

◆ ModificationType

enum class isc::db::AuditEntry::ModificationType : uint8_t
strong

Types of the modifications.

The numbers representing those modification types correspond to the values representing them in the database.

Enumerator
CREATE 
UPDATE 
DELETE 

Definition at line 73 of file audit_entry.h.

Constructor & Destructor Documentation

◆ AuditEntry() [1/2]

isc::db::AuditEntry::AuditEntry ( const std::string &  object_type,
const uint64_t  object_id,
const ModificationType modification_type,
const boost::posix_time::ptime &  modification_time,
const uint64_t  revision_id,
const std::string &  log_message 
)

Constructor using explicit modification time and id.

Parameters
object_typename of the table where data was modified.
object_ididentifier of the modified record in this table.
modification_typetype of the modification, e.g. DELETE.
modification_timetime of modification for that record.
revision_ididentifier of the revision.
log_messageoptional log message associated with the modification.

Definition at line 16 of file audit_entry.cc.

◆ AuditEntry() [2/2]

isc::db::AuditEntry::AuditEntry ( const std::string &  object_type,
const uint64_t  object_id,
const ModificationType modification_type,
const uint64_t  revision_id,
const std::string &  log_message 
)

Constructor using default modification time.

Parameters
object_typename of the table where data was modified.
object_ididentifier of the modified record in this table.
modification_typetype of the modification, e.g. DELETE.
revision_ididentifier of the revision.
log_messageoptional log message associated with the modification.

Definition at line 32 of file audit_entry.cc.

Member Function Documentation

◆ create() [1/2]

AuditEntryPtr isc::db::AuditEntry::create ( const std::string &  object_type,
const uint64_t  object_id,
const ModificationType modification_type,
const boost::posix_time::ptime &  modification_time,
const uint64_t  revision_id,
const std::string &  log_message 
)
static

Factory function creating an instance of AuditEntry.

This function should be used to create an instance of the audit entry within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.

Parameters
object_typename of the table where data was modified.
object_ididentifier of the modified record in this table.
modification_typetype of the modification, e.g. DELETE.
modification_timetime of modification for that record.
revision_ididentifier of the revision.
log_messageoptional log message associated with the modification.
Returns
Pointer to the AuditEntry instance.

Definition at line 48 of file audit_entry.cc.

◆ create() [2/2]

AuditEntryPtr isc::db::AuditEntry::create ( const std::string &  object_type,
const uint64_t  object_id,
const ModificationType modification_type,
const uint64_t  revision_id,
const std::string &  log_message 
)
static

Factory function creating an instance of AuditEntry.

This function should be used to create an instance of the audit entry within a hooks library in cases when the library may be unloaded before the object is destroyed. This ensures that the ownership of the object by the Kea process is retained.

Parameters
object_typename of the table where data was modified.
object_ididentifier of the modified record in this table.
modification_typetype of the modification, e.g. DELETE.
revision_ididentifier of the revision.
log_messageoptional log message associated with the modification.
Returns
Pointer to the AuditEntry instance.

Definition at line 62 of file audit_entry.cc.

◆ getLogMessage()

std::string isc::db::AuditEntry::getLogMessage ( ) const
inline

Returns log message.

Returns
Optional log message corresponding to the changes.

Definition at line 194 of file audit_entry.h.

◆ getModificationTime()

boost::posix_time::ptime isc::db::AuditEntry::getModificationTime ( ) const
inline

Returns modification time.

Returns
Modification time of the corresponding record.

Definition at line 177 of file audit_entry.h.

◆ getModificationType()

ModificationType isc::db::AuditEntry::getModificationType ( ) const
inline

Returns modification type.

Returns
Type of the modification, e.g. DELETE.

Definition at line 170 of file audit_entry.h.

◆ getObjectId()

uint64_t isc::db::AuditEntry::getObjectId ( ) const
inline

Returns object id.

Returns
Identifier of the added, updated or deleted object.

Definition at line 163 of file audit_entry.h.

◆ getObjectType()

std::string isc::db::AuditEntry::getObjectType ( ) const
inline

Returns object type.

Returns
Name of the table in which the modification is present.

Definition at line 156 of file audit_entry.h.

◆ getRevisionId()

uint64_t isc::db::AuditEntry::getRevisionId ( ) const
inline

Returns revision id.

The revision id is used when two audit entries have the same modification time.

Returns
Identifier of the revision.

Definition at line 187 of file audit_entry.h.


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