ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Static Protected Attributes | List of all members
adctk.syslog_publisher.SyslogPublisher Class Reference

Publish to syslog. More...

Inheritance diagram for adctk.syslog_publisher.SyslogPublisher:
Inheritance graph
[legend]
Collaboration diagram for adctk.syslog_publisher.SyslogPublisher:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self)
 
int config (self, **kwargs)
 
int initialize (self)
 Set up any resources needed for reuse in publish().
 
int publish (self, builder.Builder b)
 Publish json extracted from builder.
 
None finalize (self)
 Clean up any resources set up in initialize (files, pipes, etc).
 
- Public Member Functions inherited from adctk.publisher.Publisher
str name (self)
 Get the name which a factory or error message should use.
 
str version (self)
 
dict[str, str] get_option_defaults (self)
 
None pause (self)
 Cause publish calls to be ignored until resume is called.
 
None resume (self)
 Cancel an prior calls to pause.
 
int publish_str (self, str json_string)
 
int publish_obj (self, obj)
 

Public Attributes

 defaults
 
 paused
 
 plugin_prefix
 
 mode
 
- Public Attributes inherited from adctk.publisher.Publisher
 defaults
 
 plugin_prefix
 
 paused
 
 state
 
 mode
 

Protected Member Functions

int _config (self, str priority)
 
- Protected Member Functions inherited from adctk.publisher.Publisher
str _get (self, dict[str, str] opts, str field)
 
bool _get_bool (self, dict[str, str] opts, str field)
 

Static Protected Attributes

str _name = "syslog"
 
str _version = "1.0.0"
 
 _priority = None
 
- Static Protected Attributes inherited from adctk.publisher.Publisher
str _name = "unknown"
 
str _version = "0.0.0"
 

Additional Inherited Members

- Static Public Member Functions inherited from adctk.publisher.Publisher
tuple[float] get_timeout_defaults ()
 Get the adc server connect and response timeouts defined in the environment ADC_SERVER_CONNECT_TIMEOUT and ADC_SERVER_POST_TIMEOUT as a tuple or default values if not defined.
 
str get_url_default ()
 Get the alleged adc server url base from environment ADC_SERVER_URL or the default if it is not present.
 
str get_port_default ()
 Get the adc server port number to use if it is properly defined in the environment ADC_SERVER_PORT or the default if it is not.
 
- Static Public Attributes inherited from adctk.publisher.Publisher
 API_VERSION = adc_version.AdcVersion()._dict()
 

Detailed Description

Publish to syslog.

Syslog priority is a global in C, so _priority is the last value we set it to using openlog across all instances of this publisher.

Environment variables:

Constructor & Destructor Documentation

◆ __init__()

adctk.syslog_publisher.SyslogPublisher.__init__ (   self)

Reimplemented from adctk.publisher.Publisher.

61 def __init__(self):
62 super().__init__()
63 self.defaults = _defaults
64 self.paused = False
65 self.plugin_prefix = "ADC_SYSLOG_PLUGIN_"
66

Member Function Documentation

◆ _config()

int adctk.syslog_publisher.SyslogPublisher._config (   self,
str  priority 
)
protected
67 def _config(self, priority: str) -> int:
68 SyslogPublisher._priority = _get_priority_from_string(priority)
69 return 0
70

◆ config()

int adctk.syslog_publisher.SyslogPublisher.config (   self,
**  kwargs 
)
the only option for the syslog plugin is "PRIORITY=<syslog_level>

Reimplemented from adctk.publisher.Publisher.

71 def config(self, **kwargs) -> int:
72 """the only option for the syslog plugin is "PRIORITY=<syslog_level>"""
73 priority = self._get(kwargs, "PRIORITY")
74 self.mode = publisher.Publisher.Mode.INIT
75 return self._config(priority.lower())
76

◆ finalize()

None adctk.syslog_publisher.SyslogPublisher.finalize (   self)

Clean up any resources set up in initialize (files, pipes, etc).

Reimplemented from adctk.publisher.Publisher.

94 def finalize(self) -> None:
95 return None

◆ initialize()

int adctk.syslog_publisher.SyslogPublisher.initialize (   self)

Set up any resources needed for reuse in publish().

Reimplemented from adctk.publisher.Publisher.

77 def initialize(self) -> int:
78 syslog.openlog("ADC", logoption=(syslog.LOG_CONS | syslog.LOG_PID),
79 facility=syslog.LOG_USER)
80 self.mode = publisher.Publisher.Mode.PUB_OR_FINAL
81 return 0
82

◆ publish()

int adctk.syslog_publisher.SyslogPublisher.publish (   self,
builder.Builder  b 
)

Publish json extracted from builder.

Reimplemented from adctk.publisher.Publisher.

83 def publish(self, b: builder.Builder) -> int:
84 if self.paused:
85 return 0
86 if SyslogPublisher._priority is None:
87 self._config("info")
88 if self.mode != publisher.Publisher.Mode.PUB_OR_FINAL:
89 self.initialize()
90 message = b.serialize()
91 syslog.syslog(SyslogPublisher._priority, message)
92 return 0
93

Member Data Documentation

◆ _name

str adctk.syslog_publisher.SyslogPublisher._name = "syslog"
staticprotected

◆ _priority

adctk.syslog_publisher.SyslogPublisher._priority = None
staticprotected

◆ _version

str adctk.syslog_publisher.SyslogPublisher._version = "1.0.0"
staticprotected

◆ defaults

adctk.syslog_publisher.SyslogPublisher.defaults

◆ mode

adctk.syslog_publisher.SyslogPublisher.mode

◆ paused

adctk.syslog_publisher.SyslogPublisher.paused

◆ plugin_prefix

adctk.syslog_publisher.SyslogPublisher.plugin_prefix

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