客户端日志上传
This commit is contained in:
@@ -21,6 +21,11 @@
|
||||
<artifactId>fc-card</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jcraft</groupId>
|
||||
<artifactId>jsch</artifactId>
|
||||
<version>0.1.55</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -10,6 +10,8 @@ public class ClientConfig implements Serializable {
|
||||
String clientSN;
|
||||
String clientVid;
|
||||
|
||||
String clientPwd;
|
||||
|
||||
public String getServerIp() {
|
||||
return serverIp;
|
||||
}
|
||||
@@ -41,4 +43,12 @@ public class ClientConfig implements Serializable {
|
||||
public void setClientVid(String clientVid) {
|
||||
this.clientVid = clientVid;
|
||||
}
|
||||
|
||||
public String getClientPwd() {
|
||||
return clientPwd;
|
||||
}
|
||||
|
||||
public void setClientPwd(String clientPwd) {
|
||||
this.clientPwd = clientPwd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.sv.intergration;
|
||||
|
||||
import com.jcraft.jsch.*;
|
||||
import com.sv.netty.config.NettyConstant;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
public class LogService {
|
||||
|
||||
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
||||
|
||||
static Session session;
|
||||
|
||||
public void uploadLog(String password) throws JSchException, FileNotFoundException, SftpException {
|
||||
if (session == null){
|
||||
JSch jsch = new JSch();
|
||||
String serverIp = System.getProperty(NettyConstant.VENUE_SERVER_IP);
|
||||
session = jsch.getSession("root", serverIp, 22);
|
||||
session.setPassword(System.getProperty(NettyConstant.VENUE_CHECK_PWD));
|
||||
session.setConfig("StrictHostKeyChecking", "no");
|
||||
session.connect(3000);
|
||||
}
|
||||
ChannelSftp sftp = (ChannelSftp) session.openChannel("sftp");
|
||||
File file = new File("/home/venue/logs/common-default.log");
|
||||
if (file.exists()){
|
||||
sftp.put(new FileInputStream(file),"/home/uploadlog/" + System.getProperty(NettyConstant.VENUE_CLIENT_SN) + "-" + sdf.format(new Date()) + "-client.log");
|
||||
}
|
||||
if (sftp != null) {
|
||||
sftp.connect();
|
||||
sftp.disconnect();
|
||||
}
|
||||
if (session != null) {
|
||||
session.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,6 +31,7 @@ public class ClientService {
|
||||
System.setProperty(NettyConstant.VENUE_SERVER_PORT,decode.getServerPort());
|
||||
System.setProperty(NettyConstant.VENUE_CLIENT_SN,decode.getClientSN());
|
||||
System.setProperty(NettyConstant.VENUE_CLIENT_VID,decode.getClientVid());
|
||||
System.setProperty(NettyConstant.VENUE_CHECK_PWD,decode.getClientPwd());
|
||||
}
|
||||
bufferedReader.close();
|
||||
fileReader.close();
|
||||
|
||||
@@ -8,6 +8,7 @@ public interface NettyConstant {
|
||||
String VENUE_SERVER_PORT = "VENUE_SERVER_PORT";
|
||||
String VENUE_CLIENT_SN = "VENUE_CLIENT_SN";
|
||||
String VENUE_CLIENT_VID = "VENUE_CLIENT_VID";
|
||||
String VENUE_CHECK_PWD = "VENUE_CHECK_PWD";
|
||||
|
||||
/**
|
||||
* session中存储终端发送的额外参数
|
||||
|
||||
Reference in New Issue
Block a user