pinpoint2.0.2 定制开发--增加钉钉群通知、@到具体个人,解决手机号码无法输入BUG、删除客户端需要认证、查看数据日期范围扩大等。

一、增加钉钉群报警,并@到个人、带报警模块URL

 

 

/*
 * Copyright 2018 NAVER Corp.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.navercorp.pinpoint.web.alarm;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.navercorp.pinpoint.web.alarm.checker.AlarmChecker;
import com.navercorp.pinpoint.web.alarm.vo.Rule;
import org.apache.hadoop.hbase.shaded.org.apache.http.HttpResponse;
import org.apache.hadoop.hbase.shaded.org.apache.http.HttpStatus;
import org.apache.hadoop.hbase.shaded.org.apache.http.client.HttpClient;
import org.apache.hadoop.hbase.shaded.org.apache.http.client.methods.HttpPost;
import org.apache.hadoop.hbase.shaded.org.apache.http.entity.StringEntity;
import org.apache.hadoop.hbase.shaded.org.apache.http.impl.client.DefaultHttpClient;
import org.apache.hadoop.hbase.shaded.org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepExecution;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author minwoo.jung
 */
public class EmptySmsSender implements SmsSender {

    private final Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void sendSms(AlarmChecker checker, int sequenceCount, StepExecution stepExecution) {

        Rule rule = checker.getRule();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式

        String content = String.format("[Pinpoint-APM告警]\n告警应用:%s\n告警规则:%s\n告警详情:%s\n告警触发次数:%d次\n告警时间:%s\n @%s\n链接:http://*******/main/%s@%s/5m",
                rule.getApplicationId(), rule.getCheckerName(),
                checker.getEmailMessage(), sequenceCount, df.format(new Date()), rule.getNotes(),rule.getApplicationId(),rule.getServiceType());

        this.dingTalk(content, rule.getNotes());
        logger.info("++++++++++++++++++++++++++send content:{}", content);
    }

    /**
     * 发送钉钉消息
     */
    public void dingTalk(String content, String phone) {

        try {
            String WEBHOOK_TOKEN = "https://oapi.dingtalk.com/robot/send?access_token=***********";

            HttpClient httpclient = new DefaultHttpClient();

            HttpPost httppost = new HttpPost(WEBHOOK_TOKEN);
            httppost.addHeader("Content-Type", "application/json; charset=utf-8");

            String textMsg = "{\n" +
                    "    \"msgtype\": \"text\", \n" +
                    "    \"text\": {\n" +
                    "        \"content\": \"" + content + "\"\n" +
                    "    }, \n" +
                    "    \"at\": {\n" +
                    "        \"atMobiles\": [\n" +
                    "            \"" + phone + "\" \n" +
                    "        ], \n" +
                    "        \"isAtAll\": false\n" +
                    "    }\n" +
                    "}";
            StringEntity se = new StringEntity(textMsg, "utf-8");
            httppost.setEntity(se);

            HttpResponse response = httpclient.execute(httppost);
            if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                String result = EntityUtils.toString(response.getEntity(), "utf-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
二、增加查看数据范围

 

 

 

 

tis(10),里边是需要的天数。

三、客户端管理

在pinpoint-web里的配置里密码配置为空

四、手机号码无法输入

 

 去除高亮的代码部分。

posted on 2020-05-21 14:47  net2817  阅读(454)  评论(1编辑  收藏  举报

导航