Merge pull request #108 from MISP/fixGeoReader

Fix geo reader
pull/111/head
Sami Mokaddem 2019-06-27 11:07:59 +02:00 committed by GitHub
commit ab886714d5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 3 deletions

View File

@ -120,7 +120,9 @@ class Geo_helper:
if not self.coordinate_list_valid(coord_list): if not self.coordinate_list_valid(coord_list):
raise InvalidCoordinate("Coordinate do not match EPSG:900913 / EPSG:3785 / OSGEO:41001") raise InvalidCoordinate("Coordinate do not match EPSG:900913 / EPSG:3785 / OSGEO:41001")
self.push_to_redis_zset(self.keyCategCoord, json.dumps(ordDic)) self.push_to_redis_zset(self.keyCategCoord, json.dumps(ordDic))
self.push_to_redis_zset(self.keyCategCountry, rep['full_rep'].country.iso_code) iso_code = rep['full_rep'].country.iso_code if rep['full_rep'].country.iso_code is not None else rep['full_rep'].registered_country.iso_code
country_name = rep['full_rep'].country.name if rep['full_rep'].country.name is not None else rep['full_rep'].registered_country.name
self.push_to_redis_zset(self.keyCategCountry, iso_code)
ordDic = OrderedDict() #keep fields with the same layout in redis ordDic = OrderedDict() #keep fields with the same layout in redis
ordDic['categ'] = categ ordDic['categ'] = categ
ordDic['value'] = supposed_ip ordDic['value'] = supposed_ip
@ -129,10 +131,10 @@ class Geo_helper:
"coord": coord, "coord": coord,
"categ": categ, "categ": categ,
"value": supposed_ip, "value": supposed_ip,
"country": rep['full_rep'].country.name, "country": country_name,
"specifName": rep['full_rep'].subdivisions.most_specific.name, "specifName": rep['full_rep'].subdivisions.most_specific.name,
"cityName": rep['full_rep'].city.name, "cityName": rep['full_rep'].city.name,
"regionCode": rep['full_rep'].country.iso_code, "regionCode": iso_code,
} }
j_to_send = json.dumps(to_send) j_to_send = json.dumps(to_send)
self.serv_coord.publish(self.CHANNELDISP, j_to_send) self.serv_coord.publish(self.CHANNELDISP, j_to_send)
@ -203,6 +205,9 @@ class Geo_helper:
print("To test for support: echo \"help GEOADD\"| redis-cli") print("To test for support: echo \"help GEOADD\"| redis-cli")
self.logger.debug('Added to redis: keyname={}, lon={}, lat={}, content={}'.format(keyname, lon, lat, content)) self.logger.debug('Added to redis: keyname={}, lon={}, lat={}, content={}'.format(keyname, lon, lat, content))
def push_to_redis_zset(self, keyCateg, toAdd, endSubkey="", count=1): def push_to_redis_zset(self, keyCateg, toAdd, endSubkey="", count=1):
if not isinstance(toAdd, str):
self.logger.warning(f'Can\'t add to redis, element is not of type String. {type(toAdd)}')
return
now = datetime.datetime.now() now = datetime.datetime.now()
today_str = util.getDateStrFormat(now) today_str = util.getDateStrFormat(now)
keyname = "{}:{}{}".format(keyCateg, today_str, endSubkey) keyname = "{}:{}{}".format(keyCateg, today_str, endSubkey)