通知配置

备注:如果点击测试 无法接收到消息,可尝试给剩余天数 设置一个比较大的值大

1、邮件

第一步:需要在 系统管理/系统设置/邮箱设置 中设置好系统发件邮件

如果需要对域名进行到期监控和邮件提醒,必须设置发件邮件

第二步:填写收件人列表

需要填写json格式的数据,例如:

[
  "tom@qq.com",
  "jack@qq.com"
]

2、WebHook

2.1、webhook发送微信消息

可以使用的微信推送平台有很多,可以参考

微信推送消息通知接口汇总

2.2、webhook发送钉钉消息

获取请求地址

https://oapi.dingtalk.com/robot/send?access_token=<access_token>

设置请求头

{
    "Content-Type": "application/json"
}

设置请求体

{
  "msgtype": "text",
  "text": {
    "content":"监控报警: 我就是我, 是不一样的烟火"
  }
}

使用模板的请求体示例

{
  "msgtype": "text",
  "text": {
      "content": "{% for row in list %}{{row.domain}} {{row.start_date or '-' }} - {{row.expire_date or '-' }} ({{row.expire_days}}){% endfor %}"
  }
}

可以参考 @PanZongQing 分享的钉钉webhook配置:

对接钉钉群内自定义webhook机器人发送告警注意事项

2.3、webhook发送Resend邮件

Resend 是一个为开发者提供的email 接口

工作原理:通过api接口使用HTTP协议发送邮件到Resend服务器,再通过Resend服务器使用SMTP协议发送邮件到目标邮箱

步骤:

1、注册账号:https://resend.com/

2、获取API Key

3、配置webhook

  • 请求方法: POST

  • 请求地址: https://api.resend.com/emails

  • 请求头

    {
      "Authorization": "Bearer <API Key>",
      "Content-Type": "application/json"
    }
    
  • 请求体

 {
    "from": "onboarding@resend.dev",
    "to": "123456@qq.com",
    "subject": "Hello World",
    "html": "<p><strong>证书到期提醒</strong></p>"
}

2.4、webhook配置showdoc

showdoc是一个从服务器推送消息到手机的工具,可以通过api接口推送到微信服务号消息

注册地址:https://push.showdoc.com.cn/

  • 请求方法: POST

  • 请求地址:

https://push.showdoc.com.cn/server/api/push/<API Key>
  • 请求头

{
    "Content-Type": "application/json"
}
  • 请求体

{
  "title": "域名到期提醒",
  "content": "{% for row in list %}{{row.domain}} {{row.start_date or '-' }} - {{row.expire_date or '-' }} ({{row.expire_days}}){% endfor %}"
}

2.5、webhook发送飞书消息

模板示例由微信群友@kaka 提供

{
    "msg_type": "interactive",
    "card": {
        "config": {
                "wide_screen_mode": true,
                "enable_forward": true
        },
        "elements": [{
                "tag": "div",
                "text": {
                        "tag": "plain_text",
                        "content": "",
                        "lines": 1
                        }
                        ,
                "fields": [

                        {

                        "text": {
                            "tag": "lark_md",
                            "content": "**域名证书 **:  <ul> {%- for row in list %} {%- if row.expire_days > 0 %} <li> {{row.domain}} {{"当前域名或证书  申请时间: "}} {{row.start_date or '-' }} - {{"到期时间: "}} {{row.expire_date or '-' }} {{"剩余: "}}( {% if row.expire_days > 0 %} {{row.expire_days}} {% endif %}  ) {{"天; "}} {% endif %} {% endfor %} </li> </ul> "
                        }
                    }

                ]

                },


         {
                "actions": [{
                        "tag": "button",

                        "text": {
                                "content": "域名或证书过期提醒 :玫瑰:",
                                "tag": "lark_md"
                        },
                        "url": "https://dc.console.aliyun.com/",
                        "type": "primary",
                        "value": {
                                         "chosen": "approve"
                        }
                }],
                "tag": "action"
        }],
        "header": {
                "title": {
                        "content": "域名或证书过期  告警",
                        "tag": "plain_text"
                },
                "template": "red"
        }
    }
}

3、企业微信

{
    "touser": "UserName",
    "msgtype": "text",
    "agentid": 1000001,
    "text": {
        "content": "你的域名证书即将到期\n点击查看<a href=\"http://www.demo.com/\">Domain Admin</a>"
    }
}

自定义通知模板示例

{
    "touser": "UserName",
    "msgtype": "text",
    "agentid": 1000001,
    "text": {
        "content": "SSL证书到期提醒:\n{% for row in list %}{{row.domain}} {{row.group_name or '-'}} ({{row.expire_days}}){% endfor %}"
    }
}

参考:https://developer.work.weixin.qq.com/document/path/90236

4、钉钉

{
    "agent_id": "<agent_id>",
    "userid_list": "<userid_list>",
    "msg": {
        "msgtype": "text",
        "text": {
            "content": "域名或证书过期提醒"
        }
    }
}

参考文档:https://open.dingtalk.com/document/orgapp/asynchronous-sending-of-enterprise-session-messages

5、飞书

{
    "receive_id": "<receive_id>",
    "msg_type": "text",
    "content": "{\"text\":\"域名或证书过期提醒\"}"
}

参考文档:https://open.feishu.cn/document/server-docs/im-v1/message/create

6、模板和参数

采用jinja2 模板引擎

WebHook、企业微信、飞书、钉钉均支持自定义通知模板

6.1、通用示例

传入模板的参数示例:

{
    "list":[
        {
            "domain": "www.demo.com",
            "start_date": "2023-06-01",
            "expire_date": "2023-06-21",
            "expire_days": 20
        }
    ]
}

参数说明

参数 类型 说明
domain string 域名/证书域名
start_date string 生效时间
expire_date string 过期时间
expire_days int 剩余天数

备注:list仅包含满足通知条件的数据

示例

{
  "title": "域名到期提醒",
  "content": "{% for row in list %}{{row.domain}} {{row.start_date or '-' }} - {{row.expire_date or '-' }} ({{row.expire_days}}){% endfor %}"
}

渲染结果

{
  "title": "域名到期提醒",
  "content": "www.demo.com 2023-06-01 - 2023-06-21 (20)"
}

不同的事件参数稍有不同,会有其独特的参数

6.2、域名到期

{
    "list": [
      {
        "id": 9,
        "user_id": 1,

        "domain": "www.baidu.com",

        "group_id": 9,
        "group_name": "百度系",

        "comment": "备注",

        "start_time": "2010-08-28 04:11:35",
        "expire_time": "2023-08-28 04:11:35",
        "start_date": "2010-08-28",
        "expire_date": "2023-08-28",
        "expire_days": 5,

        "domain_registrar": "厦门易名科技股份有限公司",
        "domain_registrar_url": "https://www.ename.net/",
        "icp_company": "北京百度网讯科技有限公司",
        "icp_licence": "京ICP证030173号-1",

        "tags": [
          "企业服务",
          "汽车服务"
        ],
        "tags_str": "企业服务、汽车服务",

        "is_auto_update": true,
        "is_expire_monitor": true,

        "create_time": "2023-07-20 22:59:20",
        "update_time": "2023-08-22 16:01:13",
        "update_time_label": "13分钟前"
      }
    ]
}

6.3、SSL证书到期

{
    "list": [
      {
        "id": 3,
        "user_id": 1,

        "domain": "www.baidu.com",
        "root_domain": "baidu.com",
        "port": 443,

        "group_id": 4,
        "group_name": "百度系",

        "comment": "备注字段",

        "start_time": "2023-07-06 09:51:06",
        "expire_time": "2024-08-06 09:51:05",
        "start_date": "2023-07-06",
        "expire_date": "2024-08-06",
        "expire_days": 349,

        "is_auto_update": true,
        "is_expire_monitor": true,
        "is_dynamic_host": false,

        "create_time": "2023-08-22 16:28:19",
        "update_time": "2023-08-22 16:28:19",
        "update_time_label": "刚刚"
        }
    ]
}

6.4、监控异常

异常通知和异常恢复通知的字段一致

{
    "monitor_row": {
        "title": "名称",
        "http_url": "请求URL",
        "allow_error_count": 3,
        "status": 2
    },
    "error": "报错信息"
}

参数说明

参数 类型 说明
error string 报错信息
monitor_row.title string 名称
monitor_row.http_url string 请求URL
monitor_row.allow_error_count int 重试次数
monitor_row.status int 状态:0未知,1成功,2失败