-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
37 lines (25 loc) · 890 Bytes
/
main.py
File metadata and controls
37 lines (25 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
from config import ConfigLoader
from slack import post_to_slack
from snmp import TonerStatus, check_toner_status
def configure():
logging.basicConfig(level=logging.WARNING)
try:
config_loader = ConfigLoader()
config = config_loader.get_config()
logging.info(f"Using config {config}")
return config
except ValueError as e:
logging.error(f"Configuration error: {e}")
raise
def levels_to_message(levels: list[TonerStatus]):
message = "The follow toner levels are low:"
for level in levels:
message += f"\n{level.consumable}: {level.level}%"
return message
config = configure()
statuses = check_toner_status(config)
low_statuses = [s for s in statuses if s.level <= config.low_level]
if any(low_statuses):
message = levels_to_message(low_statuses)
post_to_slack(message, config)