設定檔
最後更新
本頁說明
.webMonitor.json 的位置、產生時機與每個欄位的意義。位置與生命週期
go-web-monitor 不讀取環境變數,所有狀態與設定都存在當前工作目錄的
.webMonitor.json(專案 .gitignore 已排除此檔)。| 時機 | 行為 |
|---|---|
| 啟動時檔案不存在 | 建立空白清單,SMTP 預設 port: 587、enabled: false |
| 啟動時 | 讀取 list[].url 作為監控清單、config 作為 SMTP 設定;JSON 解析失敗則印出錯誤並結束 |
| 執行中 | 每輪檢查、add/del、smtp 指令後整份覆寫 |
在不同目錄啟動會使用不同的設定檔,各自獨立。
範例
- {
- "list": [
- {
- "url": "https://example.com",
- "code": 200,
- "duration": 62554917,
- "online": true,
- "last_check": "2025-01-15T23:12:29.200334+08:00",
- "expire": 87,
- "count": 0
- }
- ],
- "config": {
- "host": "smtp.gmail.com",
- "port": 587,
- "username": "your@email.com",
- "password": "your_app_password",
- "from": "your@email.com",
- "to": ["recipient@email.com"],
- "cc": "",
- "enabled": true
- }
- }
list[] 欄位(model.Website)
| 欄位 | 型別 | 說明 |
|---|---|---|
url | string | 正規化後的網址(未以 http 開頭者補 https://) |
code | int | 最近一次 HTTP 狀態碼;連線失敗為 0 |
duration | int | 回應耗時,單位奈秒(time.Duration) |
online | bool | 狀態碼介於 200–399 為 true |
last_check | string | 最近一次檢查時間(RFC 3339) |
expire | int | SSL 憑證剩餘天數;無法取得為 0 |
count | int | 連續離線次數,範圍 0–4 |
啟動時只使用
url,其餘欄位是上次執行的快照,第一輪檢查後即被覆蓋。config 欄位(model.Config)
| 欄位 | 型別 | 預設 | 說明 |
|---|---|---|---|
host | string | "" | SMTP 主機 |
port | int | 587 | 465 走隱式 TLS、587 走 STARTTLS |
username | string | "" | 與 password 皆非空才認證 |
password | string | "" | 以明文存放於檔案中 |
from | string | "" | 寄件者 |
to | []string | [] | 收件者清單 |
cc | string | "" | 副本地址;TUI 無對應指令,只能手動編輯 |
enabled | bool | false | 是否寄出告警與測試信 |
password 以明文寫入檔案,檔案權限為 0644;在多人共用的主機上請自行調整權限。手動編輯
程式執行中會整份覆寫設定檔,手動修改(例如
cc、批次匯入網址)請在程式結束後進行,下次啟動時生效。