#this script is created for ---- get distinct ip address from all the logs , # and then get the location info from ip2location.com ,store them into the mongodb. from mongobase import Conn __author__ = 'fandongyun' from utils import IpLocation from utils import IpLocationFetch from mongobase.Settings import DBColNames from pymongo import mongo_client from requests import ConnectionError log_conn = Conn("NginxEventLog") log_db = log_conn.get_db() client = mongo_client.MongoClient(host="172.26.178.208") ip_db = client.__getattr__("IPLocationDB") ip_db_col_name = "IPLocationInfo" def find_ip_from_collection(collection_name): distinct_ip = log_db.__getattr__(collection_name).distinct("remote_addr") print len(distinct_ip) return distinct_ip def is_ip_resolved(ip): #TODO ip_count = ip_db.__getattr__(ip_db_col_name).find({"ip": ip}).count() if ip_count > 0:
def __init__(self): col_names = DBGlobalSettings.col_names db_name = DBGlobalSettings.db_name self.conn = Conn(db_name) self.db = self.conn.get_db()