Emit missing GeoIP database errors only once at startup

Instead of one error per lookup.
This commit is contained in:
Jon Siwek 2018-09-21 13:25:50 -05:00
parent d7097635f4
commit 2ede95422b
3 changed files with 26 additions and 3 deletions

View file

@ -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)

View file

@ -1 +1 @@
2.6-beta2-7
2.6-beta2-8

View file

@ -3695,6 +3695,8 @@ const char* MMDB::Filename()
std::unique_ptr<MMDB> mmdb_loc;
std::unique_ptr<MMDB> 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() )
{
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);
}
}