Trying to log remote ip through plugin unsuccessfully


#1

Hi!

I have an elasticsearch cluster version 5.6.2.
I'm trying to log the remote ip that initiated the request.
For some reason when I try logging the ip I get null value.

Here is my plugin class:

public class RiemannLoggerPlugin extends Plugin implements ActionPlugin {

private static final String SETTING_DISABLE = "riemann.logger.disable";

private final Logger log = Loggers.getLogger(RiemannLoggerPlugin.class);
//private final boolean enabled;

public RiemannLoggerPlugin(Settings settings) {
    log.info("Starting Riemann Logger Plugin");
}

@Override
public List<RestHandler> getRestHandlers(Settings settings, RestController restController, ClusterSettings clusterSettings,
                                         IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
                                         IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
    ArrayList<RestHandler> restHandlers = new ArrayList<>(1);
    restHandlers.add(new RiemannLoggerRestHandler());
    return restHandlers;
}

public List<Setting<?>> getSettings() {
    List<Setting<?>> settings = new ArrayList<>();
    settings.add(Setting.simpleString(SETTING_DISABLE, Setting.Property.NodeScope));
    return settings;
}

@Override
public List<Class<? extends ActionFilter>> getActionFilters() {
    ArrayList<Class<? extends ActionFilter>> filters = new ArrayList<>();
    filters.add(RiemannLoggerActionFilter.class);
    return filters;
}
}

public class RiemannLoggerActionFilter extends ActionFilter.Simple {

private static final Logger log = LogManager.getLogger(RiemannLoggerActionFilter.class);

@Inject
public RiemannLoggerActionFilter(Settings settings) {
    super(settings);
}

@Override
public int order() {
    return Integer.MIN_VALUE;
}

@Override
protected boolean apply(String action, ActionRequest request, ActionListener<?> listener) {
    log.info("Woohoo! got a request from: " + request.remoteAddress());
    log.info("Action: " + action);
    log.info("Listener:" + listener.toString());
    return true;
}
}

Example log:
[2017-10-22T11:19:22,851][INFO ][c.f.e.r.RiemannLoggerActionFilter] Woohoo! got a request from: null
[2017-10-22T11:19:22,851][INFO ][c.f.e.r.RiemannLoggerActionFilter] Action: indices:data/read/mget
[2017-10-22T11:19:22,852][INFO ][c.f.e.r.RiemannLoggerActionFilter]
Listener:org.elasticsearch.action.support.TransportAction$1@1924d1bb

Thanks!


(system) #2

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.