pyloggr.cache

This module defines the Cache class and the cache singleton. They are used to store and retrieve data from Redis. For example, the syslog server process uses Cache to stores information about currently connected syslog clients, so that the web frontend is able to display that information.

Clients should typically use the cache singleton, instead of the Cache class.

Cache initialization is done by initialize class method. The initialize method should be called by launchers, at startup time.

Note

In a development environment, if Redis has not been started by the OS, Redis can be started directly by pyloggr using configuration item REDIS['try_spawn_redis'] = True

cache

Cache singleton

class Cache[source]

Bases: object

Cache class abstracts storage and retrieval from Redis

Variables:redis_conn (StrictRedis) – underlying StrictRedis connection object (class variable)
classmethod initialize()[source]

Cache initialization.

initialize tries to connect to redis and sets redis_conn class variable. If connection fails and REDIS['try_spawn_redis'] is set, it also tries to spawn the Redis process.

Raises CacheError:
 when redis initialization fails
class SyslogCache(server_id)[source]

Bases: object

Stores information about the running pyloggr’s syslog processes in a Redis cache

Parameters:
  • redis_conn (StrictRedis) – the Redis connection
  • server_id (int) – The syslog process server_id
clients

Return the list of clients for this syslog process

Returns:list of clients or None (Redis not available)
ports

Return the list of ports that the syslog process listens on

Returns:list of ports (numeric and socket name)
Return type:list
status

Returns syslog process status

Returns:Boolean or None (if Redis not available)
class SyslogServerList[source]

Bases: object

Encapsulates the list of syslog processes

__delitem__(server_id)[source]

Deletes a SyslogCache object (used when the syslog server shuts down)

Parameters:server_id – process id
__getitem__(server_id)[source]

Return a SyslogCache object based on process id

Parameters:server_id – process id
Return type:SyslogCache
__len__()[source]

Returns the number of syslog processes

Returns:how many syslog processes, or None (Redis not available)
Return type:int