Authored by qinchao

定时监控url的可访问行:wap首页

@@ -108,6 +108,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar @@ -108,6 +108,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
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 type != 'watchuri.resources.simple.pice' "+
  111 + " and type != 'watchuri.watchuri.wap.index' "+
111 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " + 112 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
112 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' "; 113 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
113 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m"; 114 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
@@ -124,6 +125,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar @@ -124,6 +125,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
124 " and type != 'graphic_validateexceed_forbid' " + 125 " and type != 'graphic_validateexceed_forbid' " +
125 " and type != 'graphic_validate_failexceed_forbid' " + 126 " and type != 'graphic_validate_failexceed_forbid' " +
126 " and type != 'watchuri.resources.simple.pice' "+ 127 " and type != 'watchuri.resources.simple.pice' "+
  128 + " and type != 'watchuri.watchuri.wap.index' "+
127 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " + 129 " and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
128 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' "; 130 " and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
129 // String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m"; 131 // 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.monitor.common.service.AlarmMsgService;
  6 +import com.util.GetUsersInfoUtil;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.http.*;
  11 +import org.springframework.scheduling.annotation.Scheduled;
  12 +import org.springframework.stereotype.Component;
  13 +import org.springframework.web.client.RestTemplate;
  14 +import org.springframework.web.util.UriComponentsBuilder;
  15 +
  16 +import javax.annotation.Resource;
  17 +import java.net.URI;
  18 +
  19 +/**
  20 + * Created by craig.qin on 2017/10/16.
  21 + * 监控一个url:联盟跳转,wap首页
  22 + */
  23 +@Component
  24 +public class WapUrlAlarm
  25 +{
  26 + public static final Logger logger = LoggerFactory.getLogger(ResourcesSimplePiceAlarm.class);
  27 +
  28 + public static final String WATCH_URL = "https://webunion.yohobuy.com/union/go?union_type=4&union_data=D00kvbdf4jrh3m59jj6B&go_url=https%3A%2F%2Fm.yohobuy.com&tracking_id=7869446178";
  29 +
  30 + /**
  31 + * 根据报警组名称取成员的手机号码
  32 + */
  33 + @Autowired
  34 + private GetUsersInfoUtil getUsersInfoUtil;
  35 +
  36 + @Autowired
  37 + public AlarmMsgService alarmMsgService;
  38 +
  39 + @Resource(name = "javaapiRestTemplate")
  40 + private RestTemplate restTemplate;
  41 +
  42 + /**
  43 + * 十分钟监控一次
  44 + */
  45 + @Scheduled(cron = "0 * * * * ?")
  46 + public void alarm() {
  47 + //发送拦截短信
  48 + String mobile_user = "15051889346";//葛正文的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
  49 + try {
  50 + UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
  51 + //WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
  52 + URI uri = builder.build(true).encode().toUri();
  53 + // String alarmData = restTemplate.getForObject(uri, String.class);
  54 +
  55 + HttpHeaders headers = new HttpHeaders();
  56 + headers.add("Content-Type", "text/html");
  57 + headers.add("Cache-Control", "max-age=0");
  58 + HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
  59 + ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, String.class);
  60 + HttpStatus status = responseEntity.getStatusCode();
  61 + if (200!=status.value()){
  62 + alarm("联盟跳转页面访问异常,code="+status.value(),mobile_user);
  63 + }
  64 +
  65 + } catch (Exception e) {
  66 + logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
  67 + alarm("联盟跳转页面访问异常,探测异常",mobile_user);
  68 + }
  69 +
  70 + }
  71 +
  72 + private void alarm(String content,String mobile) {
  73 + alarmMsgService.sendSms("watchuri.wap.index", content, mobile);
  74 + }
  75 +}
@@ -23,4 +23,9 @@ public class AlarmGroupContants { @@ -23,4 +23,9 @@ public class AlarmGroupContants {
23 * 运维-双中心切换: 23 * 运维-双中心切换:
24 */ 24 */
25 public final static String GROUP_NAME_YUNWEI_SWITCH_CENTER = "切换组"; 25 public final static String GROUP_NAME_YUNWEI_SWITCH_CENTER = "切换组";
  26 +
  27 + /**
  28 + * 用户组
  29 + */
  30 + public final static String GROUP_NAME_USER_LOGIN = "用户组-用户登录";
26 } 31 }