13.2.3. Audit log

13.2.3.1. Base class

class privacyidea.lib.auditmodules.base.Audit(config=None)[source]
add_to_log(param)[source]

Add to existing log entry :param param: :return:

audit_entry_to_dict(audit_entry)[source]

If the search_query returns an iterator with elements that are not a dictionary, the audit module needs to provide this function, to convert the audit entry to a dictionary.

csv_generator(param)[source]

A generator that can be used to stream the audit log

Parameters:param
Returns:
finalize_log()[source]

This method is called to finalize the audit_data. I.e. sign the data and write it to the database. It should hash the data and do a hash chain and sign the data

get_audit_id()[source]
get_count(search_dict, timedelta=None, success=None)[source]

Returns the number of found log entries. E.g. used for checking the timelimit.

Parameters:param – List of filter parameters
Returns:number of found entries
get_dataframe(start_time=datetime.datetime(2015, 11, 19, 22, 32, 5, 401440), end_time=datetime.datetime(2015, 11, 26, 22, 32, 5, 401480))[source]

The Audit module can handle its data the best. This function is used to return a pandas.dataframe with all audit data in the given time frame.

This dataframe then can be used for extracting statistics.

Parameters:
  • start_time (datetime) – The start time of the data
  • end_time (datetime) – The end time of the data
Returns:

Audit data

Return type:

dataframe

get_total(param, AND=True, display_error=True)[source]

This method returns the total number of audit entries in the audit store

initialize(*args, **kwds)[source]
initialize_log(param)[source]

This method initialized the log state. The fact, that the log state was initialized, also needs to be logged. Therefor the same params are passed as i the log method.

log(*args, **kwds)[source]

This method is used to log the data. During a request this method can be called several times to fill the internal audit_data dictionary.

log_token_num(count)[source]

Log the number of the tokens. Can be passed like log_token_num(get_tokens(count=True))

Parameters:count (int) – Number of tokens
Returns:
read_keys(*args, **kwds)[source]

Set the private and public key for the audit class. This is achieved by passing the entries.

#priv = config.get(“privacyideaAudit.key.private”) #pub = config.get(“privacyideaAudit.key.public”)

Parameters:
  • pub (string with filename) – Public key, used for verifying the signature
  • priv (string with filename) – Private key, used to sign the audit entry
Returns:

None

search(param, display_error=True, rp_dict=None)[source]

This function is used to search audit events.

param: Search parameters can be passed.

return: A pagination object

This function is deprecated.

search_query(search_dict, rp_dict)[source]

This function returns the audit log as an iterator on the result

set()[source]

This function could be used to set certain things like the signing key. But maybe it should only be read from privacyidea.ini?

13.2.3.2. SQL Audit module

class privacyidea.lib.auditmodules.sqlaudit.Audit(config=None)[source]

This is the SQLAudit module, which writes the audit entries to an SQL database table. It requires the configuration parameters. PI_AUDIT_SQL_URI

add_to_log(param)[source]

Add new text to an existing log entry :param param: :return:

clear()[source]

Deletes all entries in the database table. This is only used for test cases! :return:

csv_generator(param=None, user=None)[source]

Returns the audit log as csv file. :param config: The current flask app configuration :type config: dict :param param: The request parameters :type param: dict :param user: The user, who issued the request :return: None. It yields results as a generator

finalize_log()[source]

This method is used to log the data. It should hash the data and do a hash chain and sign the data

get_dataframe(start_time=datetime.datetime(2015, 11, 19, 22, 32, 5, 601456), end_time=datetime.datetime(2015, 11, 26, 22, 32, 5, 601488))[source]

The Audit module can handle its data the best. This function is used to return a pandas.dataframe with all audit data in the given time frame.

This dataframe then can be used for extracting statistics.

Parameters:
  • start_time (datetime) – The start time of the data
  • end_time (datetime) – The end time of the data
Returns:

Audit data

Return type:

dataframe

get_total(param, AND=True, display_error=True)[source]

This method returns the total number of audit entries in the audit store

log(param)[source]

Add new log details in param to the internal log data self.audit_data.

Parameters:param (dict) – Log data that is to be added
Returns:None
read_keys(pub, priv)[source]

Set the private and public key for the audit class. This is achieved by passing the entries.

#priv = config.get(“privacyideaAudit.key.private”) #pub = config.get(“privacyideaAudit.key.public”)

Parameters:
  • pub (string with filename) – Public key, used for verifying the signature
  • priv (string with filename) – Private key, used to sign the audit entry
Returns:

None

search(search_dict, page_size=15, page=1, sortorder='asc')[source]

This function returns the audit log as a Pagination object.

search_query(search_dict, page_size=15, page=1, sortorder='asc', sortname='number')[source]

This function returns the audit log as an iterator on the result