?????????Linux?????????С????
???????????? ???????[ 2014/7/18 14:26:40 ] ????????linux ??????
????4 LinuxSessionHandle
package com.sunfan.monitor.platform.linux;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import com.sunfan.monitor.platform.IMonitorable;
import com.trilead.ssh2.Connection;
import com.trilead.ssh2.Session;
import com.trilead.ssh2.StreamGobbler;
/**
*
* @author sunfan
*
*/
@Component
public class LinuxSessionHandle implements IMonitorable??Closeable{
Logger logger = LoggerFactory.getLogger(LinuxSessionHandle.class);
private Session session;
/**
* open session then execute commands on remote server and return the result of it
* @param command
* @return String
* @throws IOException
*/
public synchronized String executeCommand(Connection conn??String command) throws IOException {
String str="";
try {
session = conn.openSession();
session.execCommand(command);
str = this.read().toString();
} catch (Exception e) {
session.ping();
throw new IOException("session exception"??e);
}
finally{
close();
}
return str;
}
/**
* read the result of remote server execute commands
* @return
* @throws IOException
*/
private StringBuffer read() throws IOException{
InputStream stdout = new StreamGobbler(session.getStdout());
BufferedReader br = new BufferedReader(new InputStreamReader(stdout));
String tempString = null;
// readLine()??ε????????????
StringBuffer str = new StringBuffer();
while ((tempString = br.readLine()) != null) {
str.append(tempString+"
");
}
br.close();
return str;
}
/**
* close session
*/
@Override
public void close() throws IOException {
if (this.session != null) this.session.close();
}
}
5 EntityBaseUtil
package com.sunfan.monitor.entity.util;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author sunfan
*
*/
public class EntityBaseUtil {
/**change String result to List<String> result by split "
"
* remove the content above flag
* to transfer List<String> ---> list<String[]> by .split("\s{1??}")
* @param result
* @param flag
* @return
*/
public List<String[]> transferListofStringArray(String result??String flag){
List<String> resList = this.transferList(result);
List<String> contentList = this.removeResultHead(resList??flag);
return this.transferArrayOfList(contentList);
}
/**
* change String result to List<String> result by split "
"
* @param result
* @return List<String>
*/
public List<String> transferList(String result){
String[] strs = result.split("
");
List<String> list = new ArrayList<String>();
for(String s:strs){
list.add(s);
}
return list;
}
/**remove the content above flag
*
* @return List<String>
*/
public List<String> removeResultHead(List<String> resultList??String flag){
List<String> contentList = new ArrayList<String>();
contentList.addAll(resultList);
for(String res:resultList){
if(res.contains(flag)){
break;
}
contentList.remove(res);
}
return contentList;
}
/**to transfer List<String> ---> list<String[]> by .split("\s{1??}")
*
* @param contentList
* @return List<String[]>
*/
public List<String[]> transferArrayOfList(List<String> contentList){
List<String[]> contentLists =new ArrayList<>();
for(String content:contentList){
contentLists.add(content.split("\s{1??}"));
}
return contentLists;
}
/**get result of reference by title
*
* @param head data of reference title
* @param title reference title
* @param infos data of each reference
* @return String result of reference by title ??if title is not matched ??return " "
*/
public String resolveValueByTagName(List<String> head??String[] infos??String title){
if(head.indexOf(title)>0){
return infos[head.indexOf(title)];
}
return "";
}
}
|
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
Linux??????DDR????????????Linux?????????????????豸??????????linux???в???????????м??????????????????????????Linux????Linux??DNS????????????γ???????????Linux?????????????Linux????(???)????????Linux ????????????????????????????????Windows???У?Linux???????Linux????????????????Linux iommu??vfio???????Linux????ε???TCP???????Linux?????????????СLinux?·???????????Linux???Jexus?й?Asp.Net Core??ó???Linux?????????Щ??
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????