Authored by qinchao

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

... ... @@ -108,6 +108,7 @@ public class MonitorAlarmMapperImpl extends InfluxDBQuery implements MonitorAlar
" and type != 'graphic_validateexceed_forbid' " +
" and type != 'graphic_validate_failexceed_forbid' " +
" and type != 'watchuri.resources.simple.pice' "+
" and type != 'watchuri.watchuri.wap.index' "+
" and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
" and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
// 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
" and type != 'graphic_validateexceed_forbid' " +
" and type != 'graphic_validate_failexceed_forbid' " +
" and type != 'watchuri.resources.simple.pice' "+
" and type != 'watchuri.watchuri.wap.index' "+
" and sms_content != 'YOHOBUY实时店铺监控系统:spark数据没写入' " +
" and sms_content != 'MonitAlarmInfo(host=10.67.1.139, service=SparkJobRunner, info=spark任务异常)' ";
// String command = "SELECT count(sms_content) FROM monitor_alarm where time > now() - "+ min+"m";
... ...
package com.monitor.javaserver.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.monitor.common.service.AlarmMsgService;
import com.util.GetUsersInfoUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import javax.annotation.Resource;
import java.net.URI;
/**
* Created by craig.qin on 2017/10/16.
* 监控一个url:联盟跳转,wap首页
*/
@Component
public class WapUrlAlarm
{
public static final Logger logger = LoggerFactory.getLogger(ResourcesSimplePiceAlarm.class);
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";
/**
* 根据报警组名称取成员的手机号码
*/
@Autowired
private GetUsersInfoUtil getUsersInfoUtil;
@Autowired
public AlarmMsgService alarmMsgService;
@Resource(name = "javaapiRestTemplate")
private RestTemplate restTemplate;
/**
* 十分钟监控一次
*/
@Scheduled(cron = "0 * * * * ?")
public void alarm() {
//发送拦截短信
String mobile_user = "15051889346";//葛正文的电话//getUsersInfoUtil.getMobileByAlarmGroup(AlarmGroupContants.GROUP_NAME_USER_LOGIN);
try {
UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(WATCH_URL);
//WATCH_URL 包含了特殊字符,但不需要编码转义:build(true)
URI uri = builder.build(true).encode().toUri();
// String alarmData = restTemplate.getForObject(uri, String.class);
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "text/html");
headers.add("Cache-Control", "max-age=0");
HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> responseEntity = restTemplate.exchange(uri, HttpMethod.GET, requestEntity, String.class);
HttpStatus status = responseEntity.getStatusCode();
if (200!=status.value()){
alarm("联盟跳转页面访问异常,code="+status.value(),mobile_user);
}
} catch (Exception e) {
logger.error("ResourcesSimplePiceAlarm watchurl RESOURCES.SIMPLE.PICE error",e);
alarm("联盟跳转页面访问异常,探测异常",mobile_user);
}
}
private void alarm(String content,String mobile) {
alarmMsgService.sendSms("watchuri.wap.index", content, mobile);
}
}
... ...
... ... @@ -23,4 +23,9 @@ public class AlarmGroupContants {
* 运维-双中心切换:
*/
public final static String GROUP_NAME_YUNWEI_SWITCH_CENTER = "切换组";
/**
* 用户组
*/
public final static String GROUP_NAME_USER_LOGIN = "用户组-用户登录";
}
\ No newline at end of file
... ...