From 2ede95422bab0c4853b8db7cc15fe5c6e77aa75a Mon Sep 17 00:00:00 2001 From: Jon Siwek Date: Fri, 21 Sep 2018 13:25:50 -0500 Subject: [PATCH] Emit missing GeoIP database errors only once at startup Instead of one error per lookup. --- CHANGES | 4 ++++ VERSION | 2 +- src/bro.bif | 23 +++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index e167d1bb20..d3f2831c4e 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +2.6-beta2-8 | 2018-09-21 13:25:50 -0500 + + * Emit missing GeoIP database errors only once at startup (Jon Siwek, Corelight) + 2.6-beta2-7 | 2018-09-21 10:18:55 -0500 * Fix compile error in MMDB GeoIP code (Jon Siwek, Corelight) diff --git a/VERSION b/VERSION index b7a913bf71..bd5c1cc7e6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.6-beta2-7 +2.6-beta2-8 diff --git a/src/bro.bif b/src/bro.bif index 938a7b56ad..88aaa487d0 100644 --- a/src/bro.bif +++ b/src/bro.bif @@ -3695,6 +3695,8 @@ const char* MMDB::Filename() std::unique_ptr mmdb_loc; std::unique_ptr mmdb_asn; +static bool did_mmdb_loc_db_error = false; +static bool did_mmdb_asn_db_error = false; static bool mmdb_open(const char* filename, bool asn) { @@ -3719,6 +3721,11 @@ static bool mmdb_open(const char* filename, bool asn) catch ( const std::exception& e ) { + if ( asn ) + did_mmdb_asn_db_error = false; + else + did_mmdb_loc_db_error = false; + reporter->Info("Failed to open MaxMind DB: %s [%s]", filename, e.what()); return false; @@ -3742,6 +3749,7 @@ static void mmdb_check_loc() if ( mmdb_loc && mmdb_loc->StaleDB() ) { reporter->Info("Closing stale MaxMind DB [%s]", mmdb_loc->Filename()); + did_mmdb_loc_db_error = false; mmdb_loc.release(); } } @@ -3751,6 +3759,7 @@ static void mmdb_check_asn() if ( mmdb_asn && mmdb_asn->StaleDB() ) { reporter->Info("Closing stale MaxMind DB [%s]", mmdb_asn->Filename()); + did_mmdb_asn_db_error = false; mmdb_asn.release(); } } @@ -3943,7 +3952,12 @@ function lookup_location%(a: addr%) : geo_location { if ( ! mmdb_try_open_loc() ) { - builtin_error("Failed to open GeoIP location database"); + if ( ! did_mmdb_loc_db_error ) + { + did_mmdb_loc_db_error = true; + builtin_error("Failed to open GeoIP location database"); + } + return location; } } @@ -4021,7 +4035,12 @@ function lookup_asn%(a: addr%) : count { if ( ! mmdb_try_open_asn() ) { - builtin_error("No open GeoIP ASN database"); + if ( ! did_mmdb_asn_db_error ) + { + did_mmdb_asn_db_error = true; + builtin_error("Failed to open GeoIP ASN database"); + } + return new Val(0, TYPE_COUNT); } }