HTTP/HTTPS一次性检查(可配合crontab等工具当时检查)。对于HTTPS可设定是否检查证书有效性。

宋子桓🌈 84f8409683 更新请求和响应日志为仅调试模式输出 4 周之前
src 84f8409683 更新请求和响应日志为仅调试模式输出 4 周之前
.gitattributes cbc2c33cef 初次提交 2 月之前
.gitignore cbc2c33cef 初次提交 2 月之前
LICENSE cbc2c33cef 初次提交 2 月之前
NAME cbc2c33cef 初次提交 2 月之前
README.md cbc2c33cef 初次提交 2 月之前
REPORT cbc2c33cef 初次提交 2 月之前
VERSION cbc2c33cef 初次提交 2 月之前
go.mod cbc2c33cef 初次提交 2 月之前
go.sum cbc2c33cef 初次提交 2 月之前
resource.go cbc2c33cef 初次提交 2 月之前

README.md

Huan-WebWatcher

介绍

简单的 HTTP/HTTPS 监控系统,通过 Get 请求检查网站是否正常,并通过状态码判断状态。

如何配置

命令行参数

Usage of HSWv1.exe:
  --help
  --h
          Show usage of HSBv1.exe. If this option is set, the backend service
          will not run.

  --version
  --v
          Show version of HSBv1.exe. If this option is set, the backend service
          will not run.

  --license
  --l
          Show license of HSBv1.exe. If this option is set, the backend service
          will not run.

  --report
  --r
          Show how to report questions/errors of HSBv1.exe. If this option is
          set, the backend service will not run.

  --config string
  --c string
          The location of the running configuration file of the backend service.
          The option is a string, the default value is config.yaml in the
          running directory.

  --output-config string
          The location of the reverse output after the backend service running
          configuration file is parsed. The option is a string and the default
          is config.output.yaml in the running directory.

根据上面的描述,我们主要使用--config参数,该参数表示配置文件的位置。默认值是:config.yaml

--configconfig.yaml(默认值)时,--output-config则会默认设置为config.output.yaml,并将配置文件输出到此位置。 输出的配置文件是完整版,包含全部选项和默认选项的,同时过滤非法选项。

配置文件

配置文件是yaml文件,请看以下配置文件:

mode: debug  # 运行模式(Debug/Release/Test)
log-level: debug  # 日志记录登记
log-tag: enable  # 是否输出标签日志(Debug使用)
time-zone: Local  # 时区(UTC/Local/指定时区),若指定时区不存在,会退化到Local(本地电脑时区),若仍不存在则退化到UTC
name: 001  # 服务名称(会显示在消息推送中)

watcher:
  urls:
    - name: '百度' # URL的名字,当URL比较长的时候可以设定名字来缩短显示的URL,若不设置则默认 name 为 url的host
      url: https://www.baidu.com  # 网站的URL(必须是https协议)
      deadline: 150d  # 即将过期的标准,若证书在 deadline 时间内过期,则会发出警告。例如此处设置为150d则表示证书在150天内过期则会发出警报。
    - name: '百度' # URL的名字,当URL比较长的时候可以设定名字来缩短显示的URL,若不设置则默认 name 为 url的host
      url: https://song-zh.com  # 网站的URL(必须是https协议或http协议)
      skip-tls-verify: disable  # 是否跳过证书检查(默认不跳过)
      status:  # 表示网站正常的状态码(默认为2xx)
        - '2xx'  # 支持 1xx 2xx 3xx 4xx 5xx,例如 1xx 则表示状态码在 100-199 范围内,以此类推
        - 'xxx'  # 表示任何状态码均可,只要网站请求成功即视为正常
        - '200'  # 具体的状态码
api:
  webhook: # 企业微信机器人 Webhook,可为空,关闭企业微信推送

smtp:  # 发送邮件消息推送
  address: # smtp 服务器地址,可为空,为空表示关闭smtp
  user: # smtp 用户名(邮件),可为空,为空表示关闭smtp
  password: # smtp 用户密码
  recipient:
    - xxx@wxample.com  # 接收邮件通知的用户

构建与运行

构建

使用go build指令进行编译。

$ go build github.com/SongZihuan/web-watcher/src/cmd/webwatcher/hwwv1

生产环境下可以使用一些编译标志来压缩目标文件大小。

$ go build -trimpath -ldflags='-s -w' github.com/SongZihuan/web-watcher/src/cmd/webwatcher/hwwv1

运行

执行编译好的可执行文件即可。具体命令行参数可参见上文。

协议

本软件基于 MIT LICENSE 发布。 了解更多关于 MIT LICENSE , 请 点击此处