Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void processLogs(List<String> logs) {
- try {
- Connection conn = DMConnector.getDMConnection();
- PreparedStatement statement = conn.prepareStatement("INSERT INTO Logs (to_address, status, smtp_transac, log_timestamp) VALUES (?,?,?,?)");
- System.out.println(logs.size());
- String to_address;
- String status;
- String smtp_transac;
- String timestamp;
- for (String log : logs) {
- to_address = log.split(" <")[1].split("> ")[0];
- status = log.split(" ")[2];
- smtp_transac = log.split(">:")[1];
- timestamp = log.split(" ")[0] + log.split(" ")[1];
- statement.setString(1, to_address);
- statement.setString(2, status);
- statement.setString(3, smtp_transac);
- statement.setString(4, timestamp);
- statement.executeUpdate();
- System.out.println("toAdd = " + to_address + " status= " + status + " smtp_transac = " + smtp_transac + "n");
- }
- statement.close();
- conn.close();
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- }
- public List<String> getLogs() {
- String remoteHostUserName = "";
- String remoteHostPassword = "";
- String hostIP = "";
- List<String> results = new ArrayList<String>();
- JSch jsch = new JSch();
- try {
- Session session = jsch.getSession(remoteHostUserName, hostIP, 22);
- Properties config = new Properties();
- config.put("StrictHostKeyChecking", "no");
- session.setConfig(config);
- // Skip prompting for the password info and go direct...
- session.setPassword(remoteHostPassword);
- session.connect();
- String command = "hvmail_report -q all --last '1 min' -a --show-address --show-mtaid --show-time | sort";
- Channel channel = session.openChannel("exec");
- ((ChannelExec) channel).setCommand(command);
- ((ChannelExec) channel).setErrStream(System.err);
- InputStream in = channel.getInputStream();
- System.out.println("Connect to session...");
- channel.connect();
- byte[] tmp = new byte[1024];
- while (true) {
- while (in.available() > 0) {
- int i = in.read(tmp, 0, 1024);
- if (i < 0) {
- break;
- }
- //System.out.println(new String(tmp, 0, i));
- Collections.addAll(results, new String(tmp, 0, i).split("rn|r|n"));
- }
- if (channel.isClosed()) {
- System.out.println("exit-status: " + channel.getExitStatus());
- break;
- }
- try {
- Thread.sleep(1000);
- } catch (Exception ee) {
- ee.printStackTrace();
- }
- }
- channel.disconnect();
- session.disconnect();
- if (in.markSupported()){
- in.reset();
- }
- } catch (Exception e) {
- System.out.println(e);
- }
- return results;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement