Authored by qinchao

定时监控url的可访问行:

@@ -107,6 +107,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar @@ -107,6 +107,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
107 " and type != 'graphic_accessexceed_forbid' " + 107 " and type != 'graphic_accessexceed_forbid' " +
108 " and type != 'graphic_validateexceed_forbid' " + 108 " and type != 'graphic_validateexceed_forbid' " +
109 " and type != 'graphic_validate_failexceed_forbid' " + 109 " and type != 'graphic_validate_failexceed_forbid' " +
  110 + " and type != 'watchuri.resources.simple.pice' "+
110 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " + 111 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
111 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' "; 112 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
112 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m"; 113 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
@@ -122,6 +123,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar @@ -122,6 +123,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
122 " and type != 'graphic_accessexceed_forbid' " + 123 " and type != 'graphic_accessexceed_forbid' " +
123 " and type != 'graphic_validateexceed_forbid' " + 124 " and type != 'graphic_validateexceed_forbid' " +
124 " and type != 'graphic_validate_failexceed_forbid' " + 125 " and type != 'graphic_validate_failexceed_forbid' " +
  126 + " and type != 'watchuri.resources.simple.pice' "+
125 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " + 127 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
126 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' "; 128 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
127 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m"; 129 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
  1 +package com.monitor.javaserver.schedule;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.contants.AlarmGroupContants;
  6 +import com.monitor.common.config.SnsMobileConfig;
  7 +import com.monitor.common.service.AlarmMsgService;
  8 +import com.monitor.common.util.HttpRestClient;
  9 +import com.monitor.javaserver.bigdata.Vdata;
  10 +import com.monitor.javaserver.bigdata.ctrl.MonitAlarmCtrl;
  11 +import com.util.GetUsersInfoUtil;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.scheduling.annotation.Scheduled;
  16 +import org.springframework.stereotype.Component;
  17 +import org.springframework.web.client.RestTemplate;
  18 +import org.springframework.web.util.UriComponentsBuilder;
  19 +
  20 +import javax.annotation.Resource;
  21 +import java.net.URI;
  22 +import java.util.HashMap;
  23 +import java.util.Map;
  24 +
  25 +/**
  26 + * Created by craig.qin on 2017/10/16.
  27 + * 监控一个url
  28 + *
  29 + */
  30 +@Component
  31 +public class ResourcesSimplePiceAlarm {
  32 + public static final Logger logger = LoggerFactory.getLogger(ResourcesSimplePiceAlarm.class);
  33 +
  34 + public static final String WATCH_URL = "http://api.yoho.cn/?app_version=6.1.0&client_secret=502635028941287371c61be7e11ef2e5&client_type=android&gender=&method=resources.simple.pice&physical_channel=1&screen_size=1080x1776&session_key=9ed0b5a9eb5d1275ab7b9bd9be8f4fb0&udid=865586024514640f121382564bbe647&uid=500027824&v=7&yh_channel=1&os_version=android4.4.2%3APE-TL20";
  35 +
  36 + /**
  37 + * 根据报警组名称取成员的手机号码
  38 + */
  39 + @Autowired
  40 + private GetUsersInfoUtil getUsersInfoUtil;
  41 +
  42 + @Autowired
  43 + public AlarmMsgService alarmMsgService;
  44 +
  45 + @Resource(name = "javaapiRestTemplate")
  46 + private RestTemplate restTemplate;
  47 +
  48 + /**
  49 + * 十分钟监控一次
  50 + */
  51 + @Scheduled(cron = "0 2/10 * * * ?")
  52 + public void alarm() {
  53 + //发送拦截短信
  54 + String mobile_user = "13770338135";//耿超的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
  55 + try {
  56 + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
  57 + //WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
  58 + URI uri = builder.build(true).encode().toUri();
  59 + String alarmData = restTemplate.getForObject(uri, String.class);
  60 +
  61 + if(alarmData==null||alarmData.length()==0){
  62 + alarm("RESOURCES.SIMPLE.PICE接口访问异常:接口返回值为null异常",mobile_user);
  63 + return;
  64 + }
  65 +
  66 + JSONObject jsonObject=JSON.parseObject(alarmData);
  67 + if(jsonObject.get("code")==null||200!=(Integer)jsonObject.get("code")){
  68 + alarm("RESOURCES.SIMPLE.PICE接口访问异常:code="+(String) jsonObject.get("code"),mobile_user);
  69 + return;
  70 + }
  71 + boolean correctData=false;
  72 + JSONObject dataJO=(JSONObject)jsonObject.get("data");
  73 + if(dataJO!=null){
  74 + if(dataJO.get("sk")!=null){
  75 + String sk=(String)dataJO.get("sk");
  76 + if(sk!=null&&sk.length()>0){
  77 + correctData=true;
  78 + }
  79 + }
  80 + }
  81 + if(!correctData){
  82 + alarm("RESOURCES.SIMPLE.PICE接口访问异常:data="+dataJO,mobile_user);
  83 + return;
  84 + }
  85 +
  86 + } catch (Exception e) {
  87 + logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
  88 + alarm("RESOURCES.SIMPLE.PICE接口访问异常,探测异常",mobile_user);
  89 + }
  90 +
  91 + }
  92 +
  93 + private void alarm(String content,String mobile) {
  94 + alarmMsgService.sendSms("watchuri.resources.simple.pice", content, mobile);
  95 + }
  96 +}