飞书日志监控

Nginx 的log日志文件下载查看配置

  server {
     listen 80;
     auth_basic "Nginx";  
     auth_basic_user_file /usr/local/nginx/conf/passwd1;
     autoindex on;
     server_name log.hanye;
     charset utf-8;
     
     location / {
          root  /data/sh/log;
          autoindex_exact_size off; # 关闭计算文件确切大小(单位bytes),只显示大概大小(单位kb、mb、gb)
          autoindex_localtime on; 
          autoindex on;
      }
  }
 #!/bin/bash
 #crontab: * * * * * monitor_failed_log_monitor.sh
 TIME=`date +%Y-%m-%d-%H:%M:%S`
 IP='192.168.31.12'
 FUNC_feishu() {
    Webhook=https://open.feishu.cn/open-apis/bot/v2/hook/$token
    curl -d  '{"msg_type":"text","content":{"text":" 所属集群: '$message' \n 服务地址: '$IP' \n 报错时间: '$TIME' \n 服务类型: '$message1' \n 日志地址: '$message2/$message3' \n 登录账号: \n 登录密码:  "}}' \
   -H 'Content-Type: application/json' \
   -X POST $Webhook
 }
 
 FUNC_msg() {
      Time=`date  +%Y-%m-%d`
      message=华北集群
      message1=php-fpm日志报错
      message2=http://192.168.31.12
      message3=php-fpm-$Time.log
      md5file="/data/sh/log/fpm.txt"
      logfile="/data/sh/log/php-fpm-$Time.log"
      fpmfile="/home/laravel/storage/logs/laravel.log"
      if [ ! -f $fpmfile ]; then
              echo "" > $fpmfile
              chmod -R 777 $fpmfile
              echo "1" > /data/sh/log/line
      fi
      file_new_stat="`stat ${fpmfile}|grep Size|awk -F":" '{print $2}'|awk '{print $1}'`"
      #获取MD5
      SCAN_CMD=`which  md5sum`
      #获取文件最新行
      count=`cat -n $fpmfile |awk '{print $1}' |tail -n1`
      #获取文件上一次的行
      count2=`cat /data/sh/log/line`
      b=`cat $md5file`
      a=`${SCAN_CMD} ${fpmfile}|awk '{print $1}'`
      #if [ $a != $b ]; then
           if [ $count -gt $count2 ]; then
           tail -n +$count2  $fpmfile|grep  -Ei  "ErrorException|QueryException|FatalThrowableError|prod.ERROR" > /dev/null
           if [ $? -eq 0 ]; then
             tail  -n +$count2 $fpmfile|grep -v "INFO" > $logfile
             FUNC_feish
             /usr/bin/scp $logfile root@192.168.31.12:/data/sh/log/ > /dev/null
           fi
           echo "$a" > $md5file
           cat -n $fpmfile |awk '{print $1}' |tail -n1 > /data/sh/log/line
        fi
 }
 FUNC_msg

Last updated