Reference¶
systemctl2mqtt package.
ServiceActiveType = Literal['active', 'inactive', 'failed']
module-attribute
¶
Systemctl service active status
ServiceEventStateType = Literal['on', 'off']
module-attribute
¶
Service event state
ServiceEventStatusType = Literal['running', 'exited', 'failed']
module-attribute
¶
Service event Systemctl status
ServiceLoadType = Literal['loaded', 'not-found', 'error']
module-attribute
¶
Systemctl service load status
Systemctl2MqttConfigException
¶
Bases: Systemctl2MqttException
Config exception occurred.
Systemctl2MqttConnectionException
¶
Bases: Systemctl2MqttException
Connection exception occurred.
Systemctl2MqttEventsException
¶
Bases: Systemctl2MqttException
Events processing exception occurred.
Systemctl2MqttStatsException
¶
Bases: Systemctl2MqttException
Stats processing exception occurred.
Systemctl2Mqtt
¶
systemctl2mqtt class.
Attributes:
Name | Type | Description |
---|---|---|
version |
str
|
The version of systemctl2mqtt |
cfg |
Systemctl2MqttConfig
|
The config for systemctl2mqtt |
b_stats |
bool
|
Activate the stats |
b_events |
bool
|
Activate the events |
systemctl_events |
Queue[dict[str, str]]
|
Queue with systemctl events |
systemctl_stats |
Queue[list[str]]
|
Queue with systemctl stats |
known_event_services |
dict[str, ServiceEvent]
|
The dict with the known service events |
known_stat_services |
dict[str, dict[int, ServiceStatsRef]]
|
The dict with the known service stats references |
last_stat_services |
dict[str, ServiceStats | dict[str, Any]]
|
The dict with the last service stats |
mqtt |
Client
|
The mqtt client |
systemctl_events_t |
Thread
|
The thread to collect events from systemctl |
systemctl_stats_t |
Thread
|
The thread to collect stats from systemctl |
systemctl_version |
str
|
The systemctl version |
discovery_binary_sensor_topic |
str
|
Topic template for a binary sensor |
discovery_sensor_topic |
str
|
Topic template for a nary sensor |
status_topic |
str
|
Topic template for a status value |
version_topic |
str
|
Topic template for a version value |
stats_topic |
str
|
Topic template for stats |
events_topic |
str
|
Topic template for an events |
do_not_exit |
bool
|
Prevent exit from within Systemctl2mqtt, when handled outside |
Initialize the Systemctl2mqtt.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cfg
|
Systemctl2MqttConfig
|
The configuration object for Systemctl2mqtt |
required |
do_not_exit
|
bool
|
Prevent exit from within Systemctl2mqtt, when handled outside |
False
|
Source code in systemctl2mqtt/systemctl2mqtt.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
__del__
¶
loop
¶
Start the loop.
Raises:
Type | Description |
---|---|
Systemctl2MqttEventsException
|
If anything goes wrong in the processing of the events |
Systemctl2MqttStatsException
|
If anything goes wrong in the processing of the stats |
Systemctl2MqttException
|
If anything goes wrong outside of the known exceptions |
Source code in systemctl2mqtt/systemctl2mqtt.py
loop_busy
¶
Start the loop (blocking).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raise_known_exceptions
|
bool
|
Should any known processing exception be raised or ignored |
False
|
Raises:
Type | Description |
---|---|
Systemctl2MqttEventsException
|
If anything goes wrong in the processing of the events |
Systemctl2MqttStatsException
|
If anything goes wrong in the processing of the stats |
Systemctl2MqttException
|
If anything goes wrong outside of the known exceptions |
Source code in systemctl2mqtt/systemctl2mqtt.py
PIDStats
¶
ServiceDeviceEntry
¶
ServiceEntry
¶
Bases: TypedDict
A Service entry object for discovery in home assistant.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the sensor to display in home assistant |
unique_id |
str
|
The unique id of the sensor in home assistant |
icon |
str | None
|
The icon of the sensor to display |
availability_topic |
str
|
The topic to check the availability of the sensor |
payload_available |
str
|
The payload of availability_topic of the sensor when available |
payload_unavailable |
The payload of availability_topic of the sensor when unavailable |
|
state_topic |
str
|
The topic containing all information for the state of the sensor |
value_template |
str
|
The jinja2 template to extract the state value from the state_topic for the sensor |
unit_of_measurement |
str | None
|
The unit of measurement of the sensor |
payload_on |
str | None
|
When a binary sensor: The value of extracted state of the sensor to be considered 'on' |
payload_off |
str | None
|
When a binary sensor: The value of extracted state of the sensor to be considered 'off' |
device |
ServiceDeviceEntry
|
The device the sensor is attributed to |
device_class |
str | None
|
The device class of the sensor |
state_topic |
str
|
The topic containing all information for the attributes of the sensor |
qos |
int
|
The QOS of the discovery message |
ServiceEvent
¶
Bases: TypedDict
A Service event object to send to an mqtt topic.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the Service |
description |
str
|
The description of the Service |
pid |
int
|
The pid of the Service |
cpids |
list[int]
|
The child pids of the Service |
status |
ServiceEventStatusType
|
The Systemctl status the Service is in |
state |
ServiceEventStateType
|
The state of the Service |
ServiceStats
¶
Bases: TypedDict
A Service stats object to send to an mqtt topic.
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the Service |
host |
str
|
The Systemctl host |
memory |
float
|
Used memory in MB |
cpu |
float
|
The cpu usage by the Service in cpu-% (ex.: a Systemctl with 4 cores has 400% cpu available) |
pid_stats |
dict[int, PIDStats]
|
The stats for all pids |
ServiceStatsRef
¶
Systemctl2MqttConfig
¶
Bases: TypedDict
A config object.
Attributes:
Name | Type | Description |
---|---|---|
log_level |
str
|
Log verbosity |
homeassistant_prefix |
str
|
MQTT discovery topic prefix |
systemctl2mqtt_hostname |
str
|
A descriptive name for the Systemctl being monitored |
mqtt_client_id |
str
|
Client Id for MQTT broker client |
mqtt_user |
str
|
Username for MQTT broker authentication |
mqtt_password |
str
|
Password for MQTT broker authentication |
mqtt_host |
str
|
Hostname or IP address of the MQTT broker |
mqtt_port |
int
|
Port or IP address of the MQTT broker |
mqtt_timeout |
int
|
Timeout for MQTT messages |
mqtt_topic_prefix |
str
|
MQTT topic prefix |
mqtt_qos |
int
|
QOS for standard MQTT messages |
destroyed_service_ttl |
int
|
How long, in seconds, before destroyed services are removed from Home Assistant. Services won't be removed if the service is restarted before the TTL expires. |
service_whitelist |
list[str]
|
Whitelist the services to monitor, if empty, everything is monitored. The entries are either match as literal strings or as regex. |
service_blacklist |
list[str]
|
Blacklist the services to monitor, takes priority over whitelist. The entries are either match as literal strings or as regex. |
enable_events |
bool
|
Flag to enable event monitoring |
enable_stats |
bool
|
Flag to enable stat monitoring |
stats_record_seconds |
int
|
Interval every how many seconds the stats are published via MQTT |
SystemctlService
¶
Bases: TypedDict
A systemctl service definition.
Attributes:
Name | Type | Description |
---|---|---|
unit |
str
|
The name of the service |
load |
ServiceLoadType
|
Is the service loaded |
active |
ServiceActiveType
|
High level status of the service |
sub |
ServiceEventStatusType
|
Detailed state of the service |
description |
str
|
Description of the service |
clean_for_discovery
¶
Cleanup a typed dict for home assistant discovery, which is quite picky and does not like empty of None values.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
val
|
ServiceEntry
|
The TypedDict to cleanup |
required |
Returns:
Type | Description |
---|---|
dict
|
The cleaned dict |