Skip to content

Commit

Permalink
Add logs to CPVM connection process (#8924)
Browse files Browse the repository at this point in the history
* increment cpvm connection logs

* remove sourceIp variable

* increment cpvm connection logs

* extract duplicate error messages to variables

* change logs level from trace to debug in authenticateToVNCServer

* add logs in trace level inside of connection loop

* remove redundant trace log

* add logs to ConsoleProxyNoVNCHandler class

* retrieve client source IP

* add periods to log messages

* change log levels from warn to error inside of catch blocks

* add client IP to successful authentication log

* replace concatenation with String.format()

* remove String.format() and use log4j2 new features instead

* remove String.format() and use log4j2 new features instead

* apply Daan's suggestion

Co-authored-by: dahn <daan.hoogland@gmail.com>

* resolve conflicts

* fix logs with three parameters

* get correct client IP

* use log4j dependencies directly

* apply winterhazel's suggestion

Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>

* remove log proxy

* address winterhazel's suggestions on ConsoleProxyNoVncClient class

* address winterhazel's suggestions on ConsoleProxyNoVNCHandler class

* address winterhazel's suggestions on ConsoleProxyNoVNCHandler class

Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>

---------

Co-authored-by: dahn <daan.hoogland@gmail.com>
Co-authored-by: Fabricio Duarte <fabricio.duarte.jr@gmail.com>
  • Loading branch information
3 people authored Sep 9, 2024
1 parent b068c68 commit 501d8c1
Show file tree
Hide file tree
Showing 30 changed files with 172 additions and 437 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ public class ConsoleProxyClientParam {
private String username;
private String password;

/**
* IP that has generated the console endpoint
*/
private String sourceIP;

/**
* IP of the client that has connected to the console
*/
private String clientIp;

private String websocketUrl;

private String sessionUuid;
Expand Down Expand Up @@ -201,4 +210,12 @@ public void setClientProvidedExtraSecurityToken(String clientProvidedExtraSecuri
public void setSessionUuid(String sessionUuid) {
this.sessionUuid = sessionUuid;
}

public String getClientIp() {
return clientIp;
}

public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
import java.util.List;
import java.util.Map;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class AjaxFIFOImageCache {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

private List<Integer> fifoQueue;
private Map<Integer, byte[]> cache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,19 @@
import org.apache.logging.log4j.core.config.Configurator;
import org.eclipse.jetty.websocket.api.Session;

import com.cloud.consoleproxy.util.Logger;
import com.cloud.utils.PropertiesUtil;
import com.google.gson.Gson;
import com.sun.net.httpserver.HttpServer;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
*
* ConsoleProxy, singleton class that manages overall activities in console proxy process. To make legacy code work, we still
*/
public class ConsoleProxy {
protected static Logger LOGGER = Logger.getLogger(ConsoleProxy.class);
protected static Logger LOGGER = LogManager.getLogger(ConsoleProxy.class);

public static final int KEYBOARD_RAW = 0;
public static final int KEYBOARD_COOKED = 1;
Expand Down Expand Up @@ -280,7 +282,6 @@ public static void ensureRoute(String address) {
public static void startWithContext(Properties conf, Object context, byte[] ksBits, String ksPassword, String password, Boolean isSourceIpCheckEnabled) {
setEncryptorPassword(password);
configLog4j();
Logger.setFactory(new ConsoleProxyLoggerFactory());
LOGGER.info("Start console proxy with context");

if (conf != null) {
Expand Down Expand Up @@ -427,7 +428,6 @@ private static void startupHttpCmdPort() {
public static void main(String[] argv) {
standaloneStart = true;
configLog4j();
Logger.setFactory(new ConsoleProxyLoggerFactory());

InputStream confs = ConsoleProxy.class.getResourceAsStream("/conf/consoleproxy.properties");
Properties conf = new Properties();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConsoleProxyAjaxHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

public ConsoleProxyAjaxHandler() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConsoleProxyAjaxImageHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

@Override
public void handle(HttpExchange t) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@

import com.sun.net.httpserver.HttpServer;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConsoleProxyBaseServerFactoryImpl implements ConsoleProxyServerFactory {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

@Override
public void init(byte[] ksBits, String ksPassword) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,16 @@ public class ConsoleProxyClientParam {
private String password;
private String websocketUrl;

/**
* IP that has generated the console endpoint
*/
private String sourceIP;

/**
* IP of the client that has connected to the console
*/
private String clientIp;

private String sessionUuid;

/**
Expand Down Expand Up @@ -204,4 +212,12 @@ public String getClientProvidedExtraSecurityToken() {
public void setClientProvidedExtraSecurityToken(String clientProvidedExtraSecurityToken) {
this.clientProvidedExtraSecurityToken = clientProvidedExtraSecurityToken;
}

public String getClientIp() {
return clientIp;
}

public void setClientIp(String clientIp) {
this.clientIp = clientIp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConsoleProxyCmdHandler implements HttpHandler {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

@Override
public void handle(HttpExchange t) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import java.util.HashMap;
import java.util.Map;

import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

public class ConsoleProxyHttpHandlerHelper {
protected static Logger LOGGER = Logger.getLogger(ConsoleProxyHttpHandlerHelper.class);
protected static Logger LOGGER = LogManager.getLogger(ConsoleProxyHttpHandlerHelper.class);

public static Map<String, String> getQueryMap(String query) {
String[] params = query.split("&");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
import java.util.Map;


import com.cloud.consoleproxy.util.Logger;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.core.config.Configurator;

//
Expand All @@ -33,7 +34,7 @@
// itself and the shell script will re-launch console proxy
//
public class ConsoleProxyMonitor {
protected Logger logger = Logger.getLogger(getClass());
protected Logger logger = LogManager.getLogger(getClass());

private String[] _argv;
private Map<String, String> _argMap = new HashMap<String, String>();
Expand Down
Loading

0 comments on commit 501d8c1

Please sign in to comment.