|
|
@@ -5,6 +5,7 @@
|
|
|
import time
|
|
|
import os
|
|
|
import sys
|
|
|
+import httpx
|
|
|
|
|
|
sys.path.append(os.path.join(os.path.abspath(__file__).split('auto')[0] + 'auto'))
|
|
|
|
|
|
@@ -61,6 +62,9 @@ class LogsHandle(object):
|
|
|
if text:
|
|
|
S = SendEmail(subject=subject, title=title, text=text)
|
|
|
S.send()
|
|
|
+
|
|
|
+ G = GotifyNotifier(title=title, message=text, token='A9KF--mx_12PjSu')
|
|
|
+ G.send_message()
|
|
|
else:
|
|
|
print("No error logs found for today.")
|
|
|
|
|
|
@@ -125,7 +129,41 @@ class SendEmail(object):
|
|
|
print("Error: 无法发送邮件", e)
|
|
|
|
|
|
|
|
|
+class GotifyNotifier:
|
|
|
+ def __init__(self, title, message, token='A8EVb0Cmxnb2vfk'):
|
|
|
+ self.gotify_url = 'https://gotify.erhe.top'
|
|
|
+ self.app_token = token
|
|
|
+ self.title = title
|
|
|
+ self.message = message
|
|
|
+
|
|
|
+ def send_message(self):
|
|
|
+ # 构建POST请求的headers
|
|
|
+ headers = {
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
+ }
|
|
|
+
|
|
|
+ # 构建POST请求的body
|
|
|
+ body = {
|
|
|
+ 'title': self.title,
|
|
|
+ 'message': self.message
|
|
|
+ }
|
|
|
+
|
|
|
+ # 发送POST请求
|
|
|
+ with httpx.Client() as client:
|
|
|
+ response = client.post(
|
|
|
+ url=f"{self.gotify_url}/message?token={self.app_token}",
|
|
|
+ headers=headers,
|
|
|
+ json=body
|
|
|
+ )
|
|
|
+
|
|
|
+ # 检查响应状态码
|
|
|
+ if response.status_code == 200:
|
|
|
+ print('Gotify Message sent successfully!')
|
|
|
+ else:
|
|
|
+ print('Failed to send message:', response.text)
|
|
|
+
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
|
- print("发送当天日志:start")
|
|
|
+ print("开始执行日志处理")
|
|
|
LogsHandle().logs_send()
|
|
|
- print("发送当天日志:done")
|
|
|
+ print("处理日志程序执行完毕")
|