logstash配置
    mkdir -p /data/logalert/data
    mkdir -p /data/logalert/scripts
    yum install -y python3
    pip3 install requests

    1. //[root@keep-nxl7x scripts]# cat /etc/logstash/conf.d/logstash.conf
    2. input {
    3. file {
    4. path => "/data-gpu/podlog/20220412/batch/*.log"
    5. max_open_files => 20000
    6. }
    7. file {
    8. path => "/data-cpu/podlog/20220412/batch/*.log"
    9. max_open_files => 20000
    10. }
    11. file {
    12. path => "/data/podlog/20220412/batch/*.log"
    13. max_open_files => 20000
    14. }
    15. }
    16. output {
    17. if 'cudaGetDeviceCount' in [message] or 'UserCenterError' in [message] {
    18. file {
    19. path => "/data/logalert/data/%{+yyyyMMddHHmmss}.log"
    20. codec => line { format => "%{message}"}
    21. }
    22. }
    23. }
    1. #!/usr/bin/python3
    2. # -*- coding: utf-8 -*-
    3. import requests, json, sys
    4. def msg(text,cluster):
    5. json_text={
    6. "msg_type":"text",
    7. "content":{
    8. "msg":"任务日志关键字告警",
    9. "text":cluster+"\n"+text
    10. }
    11. }
    12. print(requests.post(api_url,json.dumps(json_text),headers=headers).content)
    13. if __name__=='__main__':
    14. api_url = 'https://open.feishu.cn/open-apis/bot/v2/hook/e9a0edf5-46f2-44c4-8b67-b2d12a8579e2'
    15. headers = {'Content-Type': 'application/json;charset=utf-8'}
    16. if sys.argv[1]:
    17. text = sys.argv[1]
    18. if sys.argv[2]:
    19. cluster = sys.argv[2]
    20. title = "任务日志关键字告警"
    21. cluster = cluster+title
    22. msg(text,cluster)