|
|
|
|
@ -22,6 +22,7 @@ import org.json.simple.parser.JSONParser;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
@ -113,4 +114,150 @@ public class TestController {
|
|
|
|
|
result.put("res", "OK");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/rest/test/noting.do", method=RequestMethod.POST)
|
|
|
|
|
public @ResponseBody Map<String, Object> noting(@RequestBody Map<String,Object> reqMap) throws Exception {
|
|
|
|
|
Map result = new HashMap();
|
|
|
|
|
|
|
|
|
|
String commandSeq = trsmrcvDao.getCommandSeq("");
|
|
|
|
|
Map<String, String> commandInMap = new HashMap<String,String>();
|
|
|
|
|
commandInMap.put("commandSeq", commandSeq);
|
|
|
|
|
commandInMap.put("sysName", "monitoring");
|
|
|
|
|
commandInMap.put("command", "nothing");
|
|
|
|
|
trsmrcvDao.insertCommand(commandInMap);
|
|
|
|
|
|
|
|
|
|
this.touchAndWait("monitoring", commandSeq);
|
|
|
|
|
|
|
|
|
|
result.put("res", "OK");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value="/rest/test/sendMail.do", method=RequestMethod.POST)
|
|
|
|
|
public @ResponseBody Map<String, Object> sendMail(@RequestBody Map<String,Object> reqMap) throws Exception {
|
|
|
|
|
Map result = new HashMap();
|
|
|
|
|
|
|
|
|
|
String SEND_MAIL_MANAGER = "monitoring";
|
|
|
|
|
|
|
|
|
|
String commandSeq = trsmrcvDao.getCommandSeq("");
|
|
|
|
|
Map<String, String> commandInMap = new HashMap<String,String>();
|
|
|
|
|
commandInMap.put("commandSeq", commandSeq);
|
|
|
|
|
commandInMap.put("sysName", SEND_MAIL_MANAGER);
|
|
|
|
|
commandInMap.put("command", "sendMail");
|
|
|
|
|
trsmrcvDao.insertCommand(commandInMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<String> hpup = (List<String>) reqMap.get("hpup");
|
|
|
|
|
List<String> mailProps = (List<String>) reqMap.get("mailProps");
|
|
|
|
|
String from = reqMap.get("from").toString();
|
|
|
|
|
List<String> to = (List<String>) reqMap.get("to");
|
|
|
|
|
String subject = reqMap.get("subject").toString();
|
|
|
|
|
String text = reqMap.get("text").toString();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Map<String,String> mailInMap = new HashMap<String,String>();
|
|
|
|
|
mailInMap.put("commandSeq", commandSeq);
|
|
|
|
|
mailInMap.put("hpup", String.join(",", hpup));
|
|
|
|
|
mailInMap.put("mailProps", String.join(",", mailProps));
|
|
|
|
|
mailInMap.put("from", from);
|
|
|
|
|
mailInMap.put("to", String.join(",", to));
|
|
|
|
|
mailInMap.put("subject", subject);
|
|
|
|
|
mailInMap.put("text", text);
|
|
|
|
|
|
|
|
|
|
trsmrcvDao.insertSendMail(mailInMap);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.touchAndWait(SEND_MAIL_MANAGER, commandSeq);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result.put("res", "OK");
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Map<String,Object> touchAndWait(String touchSys, String commandSeq) throws Exception {
|
|
|
|
|
Map<String,Object> commandResult = new HashMap<String,Object>();
|
|
|
|
|
|
|
|
|
|
this.shellCmd("/gpta/source-app/cfs/relay/ssh_ssh_touch.sh " + touchSys);
|
|
|
|
|
|
|
|
|
|
int FIRST_SLEEP = 2000;
|
|
|
|
|
Thread.sleep(FIRST_SLEEP);
|
|
|
|
|
|
|
|
|
|
int WAITING_CNT = 20;
|
|
|
|
|
int WAITING_SLEEP = 1000;
|
|
|
|
|
|
|
|
|
|
boolean commandComplate = false;
|
|
|
|
|
for(int i=0; i < WAITING_CNT; i++){
|
|
|
|
|
Map<String, String> commandOutMap = trsmrcvDao.selectCommandById(commandSeq);
|
|
|
|
|
if(commandOutMap.get("STAT_CD").equals("2")){
|
|
|
|
|
commandComplate = true;
|
|
|
|
|
//TODO if need result
|
|
|
|
|
//commandResult.put
|
|
|
|
|
}
|
|
|
|
|
if(commandComplate){
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
Thread.sleep(WAITING_SLEEP);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return commandResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean shellCmd(String cmd) {
|
|
|
|
|
Process process = null;
|
|
|
|
|
Runtime runtime = Runtime.getRuntime();
|
|
|
|
|
StringBuffer successOutput = new StringBuffer();
|
|
|
|
|
StringBuffer errorOutput = new StringBuffer();
|
|
|
|
|
BufferedReader successBufferReader = null;
|
|
|
|
|
BufferedReader errorBufferReader = null;
|
|
|
|
|
String msg = null;
|
|
|
|
|
boolean result = false;
|
|
|
|
|
|
|
|
|
|
logger.info("shellCmd - 1");
|
|
|
|
|
List<String> cmdList = new ArrayList<String>();
|
|
|
|
|
|
|
|
|
|
cmdList.add("/bin/sh");
|
|
|
|
|
cmdList.add("-c");
|
|
|
|
|
|
|
|
|
|
cmdList.add(cmd);
|
|
|
|
|
String[] array = cmdList.toArray(new String[cmdList.size()]);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
process = runtime.exec(array);
|
|
|
|
|
successBufferReader = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
|
|
|
|
|
|
|
|
|
|
while ((msg = successBufferReader.readLine()) != null) {
|
|
|
|
|
successOutput.append(msg + System.getProperty("line.separator"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
errorBufferReader = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
|
|
|
|
|
while ((msg = errorBufferReader.readLine()) != null) {
|
|
|
|
|
errorOutput.append(msg + System.getProperty("line.separator"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process.waitFor();
|
|
|
|
|
if (process.exitValue() == 0) {
|
|
|
|
|
result = true;
|
|
|
|
|
} else {
|
|
|
|
|
logger.info("abnormal finish error : " + successOutput.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (errorOutput.toString().length() > 0) {
|
|
|
|
|
logger.info("error : " + errorOutput.toString());
|
|
|
|
|
}
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
logger.info(e.getMessage());
|
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
|
logger.info(e.getMessage());
|
|
|
|
|
} finally {
|
|
|
|
|
try {
|
|
|
|
|
process.destroy();
|
|
|
|
|
if (successBufferReader != null) successBufferReader.close();
|
|
|
|
|
if (errorBufferReader != null) errorBufferReader.close();
|
|
|
|
|
|
|
|
|
|
} catch (IOException e1) {
|
|
|
|
|
logger.info(e1.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|