6 from systemd
import journal
8 urllib3
.disable_warnings()
9 http
= urllib3
.PoolManager()
11 webhook_url
= "<%= @slack_logger %>"
12 webhook_username
= "<%= @slack_logger_username %>"
13 webhook_icon
= "https://git.immae.eu/releases/logger.png"
15 def send_to_discord(message
):
16 def send_chunk(chunk
):
18 "avatar_url": webhook_icon
,
19 "username": webhook_username
,
20 "content": "```\n{}\n```".format(chunk
),
22 encoded
= json
.dumps(data
).encode('utf-8')
24 r
= http
.request("POST", webhook_url
,
25 headers
={'Content-Type': 'application/json'}
,
28 b
= json
.loads(r
.data
)
29 time
.sleep(b
["retry_after"] / 900)
30 r
= http
.request("POST", webhook_url
,
31 headers
={'Content-Type': 'application/json'}
,
36 for line
in message
.split("\n"):
37 if len(line
) + len(chunk
) > 2000 - 17:
45 j
.add_match(_SYSTEMD_UNIT
="cryptoportfolio-app.service")
50 lines
= [entry
["MESSAGE"] for entry
in list(j
)]
52 send_to_discord("\n".join(lines
))