MangoCool

利用github的Actions功能,实现检测网站是否在线,如果不在线,发送邮件提醒

2020-03-10 17:56:31   作者:MangoCool   来源:MangoCool

自己的博客,也不是每天都会看,最近因为博客经常挂掉,百度收录减少了,导致之前每天几百ip(别笑,重在参与和学习!),现在只有几十了。

所以想找个能实时监测网站在线的办法,于是想起了之前阮老师分享的一篇文章,就是利用github的Actions来,以下是我实践的内容:

github的Actions功能虽然免费,但是还是须要绑定你的银行卡什么的,不然用不了

1、启用Actions

2、接着创建一个workflows

3、在.github/workflows/创建一个yml文件,名字随便取,我取名action.yml

name: "check my website is working"

on: 
  push:
  schedule:
    - cron: '10 * * * *'


jobs:
  my-job:
    name: my job
    runs-on: ubuntu-latest
    steps:
      - name: 'Checkout codes'
        uses: actions/checkout@v1
      - name: 'Check Website'
        run: echo "WEBSITE_WORKING=$(bash ./check_website.sh)" >> $GITHUB_ENV
      - name: 'Get Date'
        run: echo "REPORT_DATE=$(TZ=':Asia/Shanghai' date '+%Y-%m-%d %T')" >> $GITHUB_ENV
      - name: 'Send Mail'
        if: env.WEBSITE_WORKING != 200
        uses: dawidd6/action-send-mail@master
        with:
          server_address: smtp.163.com
          server_port: 465
          username: ${{secrets.MAIL_USERNAME}}
          password: ${{secrets.MAIL_PASSWORD}}
          subject: MangoCool Website is Not Working (${{env.WEBSITE_WORKING}}) (${{env.REPORT_DATE}})
          body: my mangocool website is not working.
          to: 58742094@qq.com
          from: GitHub Actions
          content_type: text/html

4、check_website.sh

#!/bin/sh

set -eux

curl -I -m 5 -s -w "%{http_code}\n" -o /dev/null  https://www.mangocool.com

5、配置MAIL_USERNAME和MAIL_PASSWORD

 

编辑完成并提交,github会自动运行Actions下的.yml的文件,包括运行状态,如果有错也会提示。

完整代码在https://github.com/wz2326/check_website

关于Actions的详细描述,可以看https://help.github.com/en/actions/building-actions/about-actions

或者看阮老师http://www.ruanyifeng.com/blog/2019/12/github_actions.html

标签: github Actions check 检测 网站 邮件提醒

分享:

上一篇激活office2016 亲测可用

下一篇HttpsURLConnection GET 请求 部分乱码问题

关于我

崇尚极简,热爱技术,喜欢唱歌,热衷旅行,爱好电子产品的一介码农。

座右铭

当你的才华还撑不起你的野心的时候,你就应该静下心来学习,永不止步!

人生之旅历途甚长,所争决不在一年半月,万不可因此着急失望,招精神之萎葸。

Copyright 2015- 芒果酷(mangocool.com) All rights reserved. 湘ICP备14019394号

免责声明:本网站部分文章转载其他媒体,意在为公众提供免费服务。如有信息侵犯了您的权益,可与本网站联系,本网站将尽快予以撤除。