From 3a838b8b56ab66713ed15e792c40ac3696c963e6 Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sun, 26 Jun 2016 15:01:00 -0400 Subject: [PATCH] Add MaxMind debug info --- src/main/java/net/frozenorb/apiv3/APIv3.java | 2 +- src/main/java/net/frozenorb/apiv3/model/IpIntel.java | 11 +++++++++++ .../java/net/frozenorb/apiv3/util/MaxMindUtils.java | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/frozenorb/apiv3/APIv3.java b/src/main/java/net/frozenorb/apiv3/APIv3.java index 97c2155..6dee85e 100644 --- a/src/main/java/net/frozenorb/apiv3/APIv3.java +++ b/src/main/java/net/frozenorb/apiv3/APIv3.java @@ -331,7 +331,7 @@ public final class APIv3 extends AbstractVerticle { ctx.response().setStatusCode(code); if (!ctx.request().path().contains("dumps")) { - log.info(gson.toJson(response)); + //log.info(gson.toJson(response)); } ctx.response().end(gson.toJson(response)); diff --git a/src/main/java/net/frozenorb/apiv3/model/IpIntel.java b/src/main/java/net/frozenorb/apiv3/model/IpIntel.java index 4e8c943..cf20c51 100644 --- a/src/main/java/net/frozenorb/apiv3/model/IpIntel.java +++ b/src/main/java/net/frozenorb/apiv3/model/IpIntel.java @@ -6,6 +6,7 @@ import fr.javatic.mongo.jacksonCodec.Entity; import fr.javatic.mongo.jacksonCodec.objectId.Id; import lombok.AllArgsConstructor; import lombok.Getter; +import lombok.extern.slf4j.Slf4j; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.maxmind.MaxMindResult; import net.frozenorb.apiv3.util.MaxMindUtils; @@ -15,6 +16,7 @@ import java.time.Instant; import java.util.LinkedList; import java.util.List; +@Slf4j @Entity @AllArgsConstructor public final class IpIntel { @@ -34,22 +36,31 @@ public final class IpIntel { } public static void findOrCreateById(String id, SingleResultCallback callback) { + log.info("ip intel for " + id + " queried..."); + findById(id, (existingIpIntel, error) -> { if (error != null) { + log.info("ip intel for " + id + " db check failed"); callback.onResult(null, error); } else if (existingIpIntel != null) { + log.info("ip intel for " + id + " found in db, returning that"); callback.onResult(existingIpIntel, null); } else { + log.info("ip intel for " + id + " not found, calling maxmind"); MaxMindUtils.getInsights(id, (maxMindResult, error2) -> { if (error2 != null) { + log.info("ip intel for " + id + " maxmind query failed"); callback.onResult(null, error2); } else { + log.info("ip intel for " + id + " returned from maxmind, inserting"); IpIntel newIpIntel = new IpIntel(id, maxMindResult); ipIntelCollection.insertOne(newIpIntel, (ignored, error3) -> { if (error3 != null) { + log.info("ip intel for " + id + " insertion failed"); callback.onResult(null, error3); } else { + log.info("ip intel for " + id + " insertion succeeded"); callback.onResult(newIpIntel, null); } }); diff --git a/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java b/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java index 6e17137..0d3e5d3 100644 --- a/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java +++ b/src/main/java/net/frozenorb/apiv3/util/MaxMindUtils.java @@ -6,11 +6,13 @@ import io.vertx.core.http.HttpClient; import io.vertx.core.http.HttpClientOptions; import io.vertx.core.json.JsonObject; import lombok.experimental.UtilityClass; +import lombok.extern.slf4j.Slf4j; import net.frozenorb.apiv3.APIv3; import net.frozenorb.apiv3.maxmind.MaxMindResult; import java.util.Base64; +@Slf4j @UtilityClass public class MaxMindUtils { @@ -21,6 +23,8 @@ public class MaxMindUtils { public static void getInsights(String ip, SingleResultCallback callback) { String authHeader = "Basic " + Base64.getEncoder().encodeToString((maxMindUserId + ":" + maxMindLicenseKey).getBytes(Charsets.UTF_8)); + log.warn("Requesting ip info for " + ip + " from MaxMind."); + httpsClient.get(443, "geoip.maxmind.com", "/geoip/v2.1/insights/" + ip, (response) -> { response.bodyHandler((body) -> { JsonObject bodyJson = new JsonObject(body.toString());