use of com.sohu.cache.ssh.SSHTemplate.Result in project new-cloud by xie-summer.
the class ServerStatusCollector method collectServerStatus.
/**
* 收集系统状况
* @param ip
* @param session
*/
private void collectServerStatus(String ip, SSHSession session) {
final Server server = new Server();
server.setIp(ip);
Result result = session.executeCommand(COLLECT_SERVER_STATUS, new DefaultLineProcessor() {
@Override
public void process(String line, int lineNum) throws Exception {
server.parse(line, null);
}
});
if (!result.isSuccess()) {
logger.error("collect " + ip + " err:" + result.getResult(), result.getExcetion());
}
// 保存服务器静态信息
serverDataService.saveAndUpdateServerInfo(server);
// 保存服务器状况信息
serverDataService.saveServerStat(server);
}
use of com.sohu.cache.ssh.SSHTemplate.Result in project cachecloud by sohutv.
the class ServerStatusCollector method collectServerStatus.
/**
* 收集系统状况
* @param ip
* @param session
*/
private void collectServerStatus(String ip, SSHSession session) {
final Server server = new Server();
server.setIp(ip);
Result result = session.executeCommand(COLLECT_SERVER_STATUS, new DefaultLineProcessor() {
public void process(String line, int lineNum) throws Exception {
server.parse(line, null);
}
});
if (!result.isSuccess()) {
logger.error("collect " + ip + " err:" + result.getResult(), result.getExcetion());
}
// 保存服务器静态信息
serverDataService.saveAndUpdateServerInfo(server);
// 保存服务器状况信息
serverDataService.saveServerStat(server);
}
use of com.sohu.cache.ssh.SSHTemplate.Result in project cachecloud by sohutv.
the class SSHUtil method execute.
/**
* SSH 方式登录远程主机,执行命令,方法内部会关闭所有资源,调用方无须关心。
*
* @param ip 主机ip
* @param username 用户名
* @param password 密码
* @param command 要执行的命令
*/
public static String execute(String ip, int port, String username, String password, final String command) throws SSHException {
if (StringUtil.isBlank(command)) {
return EMPTY_STRING;
}
port = IntegerUtil.defaultIfSmallerThan0(port, ConstUtils.SSH_PORT_DEFAULT);
Result rst = sshTemplate.execute(ip, port, username, password, new SSHCallback() {
public Result call(SSHSession session) {
return session.executeCommand(command);
}
});
if (rst.isSuccess()) {
return rst.getResult();
}
return "";
}
Aggregations