inlet/geoip: add an option to make the database optional

This commit is contained in:
Vincent Bernat
2022-07-08 22:20:59 +02:00
parent ac0faebf58
commit 170f7b33c8
6 changed files with 11 additions and 6 deletions

View File

@@ -30,8 +30,9 @@ inlet:
kafka:
compression-codec: zstd
geoip:
# asn-database: /usr/share/GeoIP/GeoLite2-ASN.mmdb
# country-database: /usr/share/GeoIP/GeoLite2-Country.mmdb
optional: true
asn-database: /usr/share/GeoIP/GeoLite2-ASN.mmdb
country-database: /usr/share/GeoIP/GeoLite2-Country.mmdb
snmp:
workers: 10
flow:

View File

@@ -57,8 +57,6 @@ A few synthetic flows are generated in the background. Take a look at
the `docker-compose.yml` file if you want to setup the GeoIP database.
It requires two environment variables to fetch them from
[MaxMind](https://dev.maxmind.com/geoip/geolite2-free-geolocation-data).
The appropriate configuration also needs to be uncommented in
`akvorado.yaml`.
Be sure to flush the conntrack table after starting. See the
[troubleshooting section](05-troubleshooting.md#no-packets-received)

View File

@@ -203,6 +203,8 @@ is provided, the component is inactive. It accepts the following keys:
- `asn-database` tells the path to the ASN database
- `country-database` tells the path to the country database
- `optional` makes the presence of the databases optional on start
(when not present on start, the component is just disabled)
[MaxMind DB file format]: https://maxmind.github.io/MaxMind-DB/

View File

@@ -11,6 +11,8 @@ volumes:
services:
geoip:
# Put ACCOUNT_ID and LICENSE_KEY here, or provide them on the command-line
# (env GEOIPUPDATE_ACCOUNT_ID=... GEOIPUPDATE_LICENSE_KEY=... docker-compose ...)
image: maxmindinc/geoipupdate:v4
environment:
- GEOIPUPDATE_ACCOUNT_ID

View File

@@ -9,6 +9,8 @@ type Configuration struct {
ASNDatabase string
// CountryDatabase defines the path to the country database.
CountryDatabase string
// Optional tells if we need to error if not present on start.
Optional bool
}
// DefaultConfiguration represents the default configuration for the

View File

@@ -90,10 +90,10 @@ func (c *Component) openDatabase(which string, path string, container *atomic.Va
// Start starts the GeoIP component.
func (c *Component) Start() error {
if err := c.openDatabase("country", c.config.CountryDatabase, &c.db.country); err != nil {
if err := c.openDatabase("country", c.config.CountryDatabase, &c.db.country); err != nil && !c.config.Optional {
return err
}
if err := c.openDatabase("asn", c.config.ASNDatabase, &c.db.asn); err != nil {
if err := c.openDatabase("asn", c.config.ASNDatabase, &c.db.asn); err != nil && !c.config.Optional {
return err
}
if c.db.country.Load() == nil && c.db.asn.Load() == nil {