def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.
    config = Config(os.path.join("..", "..", "conf", "reporting.conf"))
    # Run migration only if mongo is enabled as reporting module.
    if config.mongodb.enabled:
        host = config.mongodb.get("host", "127.0.0.1")
        port = config.mongodb.get("port", 27017)
        print "Mongo reporting is enabled, strarting mongo data migration."

        # Connect.
        try:
            conn = Connection(host, port)
            db = conn.cuckoo
        except TypeError:
            print "Mongo connection port must be integer"
            sys.exit()
        except ConnectionFailure:
            print "Cannot connect to MongoDB"
            sys.exit()

        # Check for schema version and create it.
        if "cuckoo_schema" in db.collection_names():
            print "Mongo schema version not expected"
            sys.exit()
        else:
            db.cuckoo_schema.save({"version": mongo_revision})

    else:
        print "Mongo reporting module not enabled, skipping mongo migration."
def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.
    config = Config(os.path.join("..", "..", "conf", "reporting.conf"))
    # Run migration only if mongo is enabled as reporting module.
    if config.mongodb.enabled:
        host = config.mongodb.get("host", "127.0.0.1")
        port = config.mongodb.get("port", 27017)
        print "Mongo reporting is enabled, strarting mongo data migration."

        # Connect.
        try:
            conn = Connection(host, port)
            db = conn.cuckoo
        except TypeError:
            print "Mongo connection port must be integer"
            sys.exit()
        except ConnectionFailure:
            print "Cannot connect to MongoDB"
            sys.exit()

        # Check for schema version and create it.
        if "cuckoo_schema" in db.collection_names():
            print "Mongo schema version not expected"
            sys.exit()
        else:
            db.cuckoo_schema.save({"version": mongo_revision})

    else:
        print "Mongo reporting module not enabled, skipping mongo migration."
示例#3
0
def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.
    config = Config(cfg=os.path.join("..", "..", "conf", "reporting.conf"))
    # Run migration only if mongo is enabled as reporting module.
    if config.mongodb.enabled:
        host = config.mongodb.get("host", "127.0.0.1")
        port = config.mongodb.get("port", 27017)
        database = config.mongodb.get("db", "cuckoo")
        user = config.mongodb.get("user", None)
        password = config.mongodb.get("password", None)
        print "Mongo reporting is enabled, strarting mongo data migration."

        if not port.isnumber():
            print "Port must be an integer"
            sys.exit()

        # Support old Mongo.
        try:
            from pymongo.connection import Connection
            from pymongo.errors import ConnectionFailure

            conn = Connection(host, port)
            db = conn.cuckoo
            done = True
        except ImportError:
            print "Unable to import pymongo (install with `pip install pymongo`)"
            done = False
        except ConnectionFailure:
            print "Cannot connect to MongoDB"
            sys.exit()

        try:
            if not done:
                import pymongo

                try:
                    db = pymongo.MongoClient(host,
                                             port=port,
                                             username=user,
                                             password=password,
                                             authSource=database)[database]
                except pymongo.errors.ConnectionFailure:
                    print "Cannot connect to MongoDB"
                    sys.exit()
        except ImportError:
            print "Unable to import pymongo (install with `pip install pymongo`)"
            sys.exit()

        # Check for schema version and create it.
        if "cuckoo_schema" in db.collection_names():
            print "Mongo schema version not expected"
            sys.exit()
        else:
            db.cuckoo_schema.save({"version": mongo_revision})

    else:
        print "Mongo reporting module not enabled, skipping mongo migration."
示例#4
0
def mongo_upgrade():
    """Migrate mongodb schema and data."""
    # Read reporting.conf to fetch mongo configuration.
    config = Config(cfg=os.path.join("..", "..", "conf", "reporting.conf"))
    # Run migration only if mongo is enabled as reporting module.
    if config.mongodb.enabled:
        host = config.mongodb.get("host", "127.0.0.1")
        port = config.mongodb.get("port", 27017)
        database = config.mongodb.get("db", "cuckoo")
        print "Mongo reporting is enabled, strarting mongo data migration."

        if not port.isnumber():
            print "Port must be an integer"
            sys.exit()

        # Support old Mongo.
        try:
            from pymongo.connection import Connection
            from pymongo.errors import ConnectionFailure

            conn = Connection(host, port)
            db = conn.cuckoo
            done = True
        except ImportError:
            print "Unable to import pymongo (install with `pip install pymongo`)"
            done = False
        except ConnectionFailure:
            print "Cannot connect to MongoDB"
            sys.exit()

        try:
            if not done:
                import pymongo

                try:
                    db = pymongo.MongoClient(host, port)[database]
                except pymongo.errors.ConnectionFailure:
                    print "Cannot connect to MongoDB"
                    sys.exit()
        except ImportError:
            print "Unable to import pymongo (install with `pip install pymongo`)"
            sys.exit()

        # Check for schema version and create it.
        if "cuckoo_schema" in db.collection_names():
            print "Mongo schema version not expected"
            sys.exit()
        else:
            db.cuckoo_schema.save({"version": mongo_revision})

    else:
        print "Mongo reporting module not enabled, skipping mongo migration."