INFO-短信告警示例

适用模块

报警组件 easyalert

具体说明

短信告警接入平台,需用户提供短信接收端口以及curl成功示例

使用示例

1、easyops找到easy_alert组件,在advanced配置组分别添加参数

template.channel.conf 类型string

template.plugin_ali_sms.conf 类型string

template.channel.conf配置如下

1 = {
  id = 2
  name = sms
  clz = "ali-sms"
  text = "短信"
  enable = true
  channelIdentification = 'sms'
  contentType = 'text'
}

template.plugin_ali_sms.conf 配置如下

name = "ali-sms"
post = true
url = "http://ip:port/xxxx"
//
setting = {
  wrap = "\n"
}
//
command = """
    content = org.apache.commons.lang3.StringEscapeUtils.escapeJson(content);
"""
header = {
}

param = {
}

body = {
  "telNumbers": "#{receiver}",  
  "taskName": "数据中台预警",
  "taskMsg": "#{content}"

}

2、easyops找到easy_alert组件,在advanced配置组分别添加参数

template.channel.conf 类型string

template.plugin_ali_sms.conf 类型string

补充参数信息后更新当前配置组-全部组件应用该版本,同步并重启

配置详情如下:

下图

INFO-短信告警示例 - 图1

INFO-短信告警示例 - 图2

如果客户侧短信接口有屏蔽规则,可以根据对应屏蔽规则修改脚本,以下大致举例了几种

name = "ali-sms"
post = true
url = "url"
//
setting = {
  wrap = "\n",
  emailSuffix = "@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}"
}
//
command = """
    function processContent(String text){
        if(text == null){
            return text;
        } else {

            // 去掉网址(http或https开头的URL)
            text = text.replaceAll("https?://[^\\s]*", "");

            // 去掉邮箱后缀
            text = text.replaceAll(emailSuffix, "");

            // 把-替换为空格
            text = org.apache.commons.lang3.StringUtils.replace(text, "-", " ");

            // 去掉可能会被识别成电话号码的数字串(7位及以上连续数字)
            text = text.replaceAll("\\b\\d{7,}\\b", "");

            // 去掉多余的空白字符
            text = text.replaceAll("\\s+", " ").trim();

            // 限制长度不超过300字符
            if(text.length() > 300){
                text = text.substring(0, 300);
            }
            return text;
        }
    }

    content = processContent(content);
    content = org.apache.commons.lang3.StringEscapeUtils.escapeJson(content);
"""
header = {

}

param = {
}

body = {

}

作者:林帅、潘晓宇