|
|
package com.monitor.javaserver.bigdata;
|
|
|
|
|
|
import com.monitor.common.config.SnsMobileConfig;
|
|
|
import com.monitor.common.service.AlarmMsgService;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.web.client.RestClientException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
/**
|
|
|
* Created by jack on 2017/3/23.
|
|
|
*/
|
|
|
@Component
|
|
|
public class BigdataAlarm {
|
|
|
|
|
|
public static final String WATCH_URL = "http://h5.data.yoho.cn/rs/api/getRtChannelDataByPlatform.do?&platform=3";
|
|
|
|
|
|
public static final Integer LIMIT = 2;
|
|
|
|
|
|
@Autowired
|
|
|
public AlarmMsgService alarmMsgService;
|
|
|
|
|
|
@Autowired
|
|
|
private SnsMobileConfig snsMobileConfig;
|
|
|
|
|
|
@Resource(name = "javaapiRestTemplate")
|
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
private Integer count = 0;
|
|
|
|
|
|
private AlarmData lastAlarmData = null;
|
|
|
|
|
|
@Scheduled(cron = "${cron_bigdata_alarm}")
|
|
|
public void run() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (!checkResp()) {
|
|
|
|
|
|
alarm("warn:Data is not update.");
|
|
|
}
|
|
|
|
|
|
count = 0;
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
count++;
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
if (LIMIT <= count) {
|
|
|
|
|
|
alarm("warn:Api response is not 200, continue " + count + " times.");
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
public void alarm(String content) {
|
|
|
|
|
|
alarmMsgService.sendSms("Bigdata", content, snsMobileConfig.getBigdataMobile());
|
|
|
}
|
|
|
|
|
|
public boolean checkResp() throws RestClientException {
|
|
|
AlarmData alarmData = restTemplate.getForObject(WATCH_URL, AlarmData.class);
|
|
|
|
|
|
if (null == lastAlarmData) {
|
|
|
|
|
|
lastAlarmData = alarmData;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return vsAlarmData(alarmData);
|
|
|
}
|
|
|
|
|
|
public boolean vsAlarmData(AlarmData alarmData) {
|
|
|
|
|
|
if (null == alarmData || null == lastAlarmData) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (null == alarmData.getToday() || null == lastAlarmData.getToday()) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
if (alarmData.getToday().equals(lastAlarmData.getToday())) {
|
|
|
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
this.lastAlarmData = alarmData;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|