Beispiel #1
0
def add_mouse(customer_names, mouse_name, address,
              username, uri, method):
    conn = db_connect()
    data = {
        RelayServers.RelayName: mouse_name,
        RelayServers.Customers: customer_names,
        RelayServers.Address: address,
    }
    try:
        (
            r
            .table(RelayServersCollection)
            .insert(data)
            .run(conn)
        )
        status = (
            MightyMouseResults(
                username, uri, method
            ).created(mouse_name, data)
        )

    except Exception as e:
        status = (
            MightyMouseResults(
                username, uri, method
            ).failed_to_create(mouse_name, e)
        )

        logger.exception(status)

    conn.close()

    return(status)
Beispiel #2
0
def update_mouse(exist, mouse_name, customer_names, address,
                 username, uri, method):
    conn = db_connect()
    if not address:
        address = exist[RelayServers.Address]

    data = {
        RelayServers.Customers: customer_names,
        RelayServers.Address: address,
    }
    try:
        a = (
            r
            .table(RelayServersCollection)
            .get(mouse_name)
            .update(data)
            .run(conn)
        )
        status = (
            MightyMouseResults(
                username, uri, method
            ).updated(mouse_name, data)
        )

    except Exception as e:
        status = (
            MightyMouseResults(
                username, uri, method
            ).failed_to_update(mouse_name, e)
        )
        logger.exception(status)

    conn.close()

    return(status)
Beispiel #3
0
def delete_mouse(mouse_name, username, uri, method):

    conn = db_connect()
    try:
        (
            r
            .table(RelayServersCollection)
            .get(mouse_name)
            .delete()
            .run(conn)
        )

        status = (
            MightyMouseResults(
                username, uri, method
            ).remove(mouse_name)
        )

    except Exception as e:
        status = (
            MightyMouseResults(
                username, uri, method
            ).failed_to_remove(mouse_name, e)
        )
        logger.exception(status)

    conn.close()

    return(status)
Beispiel #4
0
    def sync_supported_updates_to_all_agents(self, apps):
        try:
            conn = db_connect()
            deleted_count = 0
            (r.table(AppCollections.SupportedAppsPerAgent).delete().run(conn))
            conn.close()
            self.update_agents_with_supported(apps)

        except Exception as e:
            logger.exception(e)
Beispiel #5
0
    def sync_supported_updates_to_all_agents(self, apps):
        try:
            conn = db_connect()
            deleted_count = 0
            (r.table(AppCollections.SupportedAppsPerAgent).delete().run(conn))
            conn.close()
            self.update_agents_with_supported(apps)

        except Exception as e:
            logger.exception(e)
Beispiel #6
0
def update_supported_apps(json_data):

    try:
        rv_q = Queue("downloader", connection=RQ_PKG_POOL)
        conn = db_connect()

        inserted_count = 0
        all_customers = list(r.table(Collection.Customers).map(lambda x: x[CustomerKey.CustomerName]).run(conn))

        for i in range(len(json_data)):
            json_data[i][SupportedAppsKey.Customers] = all_customers
            json_data[i][SupportedAppsKey.ReleaseDate] = r.epoch_time(json_data[i][SupportedAppsKey.ReleaseDate])
            json_data[i][SupportedAppsKey.FilesDownloadStatus] = PackageCodes.FilePendingDownload
            json_data[i][SupportedAppsKey.Hidden] = "no"
            json_data[i][SupportedAppsKey.VulnerabilityId] = ""

            insert_app_data(json_data[i], DownloadCollections.LatestDownloadedSupported)
            file_data = json_data[i].get(SupportedAppsKey.FileData)
            add_file_data(json_data[i][SupportedAppsKey.AppId], file_data)
            data_to_update = {SupportedAppsKey.Customers: all_customers}
            exists = r.table(AppCollections.SupportedApps).get(json_data[i][SupportedAppsKey.AppId]).run(conn)

            if exists:
                updated = (
                    r.table(AppCollections.SupportedApps)
                    .get(json_data[i][SupportedAppsKey.AppId])
                    .update(data_to_update)
                    .run(conn)
                )

            else:
                updated = r.table(AppCollections.SupportedApps).insert(json_data[i]).run(conn)

            rv_q.enqueue_call(
                func=download_all_files_in_app,
                args=(
                    json_data[i][SupportedAppsKey.AppId],
                    json_data[i][SupportedAppsKey.OsCode],
                    None,
                    file_data,
                    0,
                    AppCollections.SupportedApps,
                ),
                timeout=86400,
            )

            inserted_count += updated["inserted"]

        conn.close()

        update_apps = IncomingSupportedApps()
        update_apps.sync_supported_updates_to_all_agents(json_data)

    except Exception as e:
        logger.exception(e)
Beispiel #7
0
def update_supported_apps(json_data):

    try:
        rv_q = Queue('downloader', connection=RQ_PKG_POOL)
        conn = db_connect()

        inserted_count = 0
        all_customers = list(
            r.table(Collection.Customers).map(
                lambda x: x[CustomerKey.CustomerName]).run(conn))

        for i in range(len(json_data)):
            json_data[i][SupportedAppsKey.Customers] = all_customers
            json_data[i][SupportedAppsKey.ReleaseDate] = \
                r.epoch_time(json_data[i][SupportedAppsKey.ReleaseDate])
            json_data[i][SupportedAppsKey.FilesDownloadStatus] = \
                PackageCodes.FilePendingDownload
            json_data[i][SupportedAppsKey.Hidden] = 'no'
            json_data[i][SupportedAppsKey.VulnerabilityId] = ''

            insert_app_data(json_data[i],
                            DownloadCollections.LatestDownloadedSupported)
            file_data = json_data[i].get(SupportedAppsKey.FileData)
            add_file_data(json_data[i][SupportedAppsKey.AppId], file_data)
            data_to_update = {SupportedAppsKey.Customers: all_customers}
            exists = (r.table(AppCollections.SupportedApps).get(
                json_data[i][SupportedAppsKey.AppId]).run(conn))

            if exists:
                updated = (r.table(AppCollections.SupportedApps).get(
                    json_data[i][SupportedAppsKey.AppId]).update(
                        data_to_update).run(conn))

            else:
                updated = (r.table(AppCollections.SupportedApps).insert(
                    json_data[i]).run(conn))

            rv_q.enqueue_call(func=download_all_files_in_app,
                              args=(json_data[i][SupportedAppsKey.AppId],
                                    json_data[i][SupportedAppsKey.OsCode],
                                    None, file_data, 0,
                                    AppCollections.SupportedApps),
                              timeout=86400)

            inserted_count += updated['inserted']

        conn.close()

        update_apps = IncomingSupportedApps()
        update_apps.sync_supported_updates_to_all_agents(json_data)

    except Exception as e:
        logger.exception(e)
Beispiel #8
0
def mouse_exists(mouse_name):

    conn = db_connect()
    try:
        exist = (r.table(RelayServersCollection).get(mouse_name).run(conn))

    except Exception as e:
        logger.exception(e)
        exist = False

    conn.close()

    return (exist)
Beispiel #9
0
def get_mouse_addresses(customer_name):

    conn = db_connect()
    try:
        exist = list(
            r.table(RelayServersCollection).pluck(
                RelayServers.Address).run(conn))

    except Exception as e:
        logger.exception(e)
        exist = False

    conn.close()

    return (exist)
Beispiel #10
0
def delete_mouse(mouse_name, username, uri, method):

    conn = db_connect()
    try:
        (r.table(RelayServersCollection).get(mouse_name).delete().run(conn))

        status = (MightyMouseResults(username, uri, method).remove(mouse_name))

    except Exception as e:
        status = (MightyMouseResults(username, uri,
                                     method).failed_to_remove(mouse_name, e))
        logger.exception(status)

    conn.close()

    return (status)
Beispiel #11
0
def get_mouse_addresses(customer_name):

    conn = db_connect()
    try:
        exist = list(
            r
            .table(RelayServersCollection)
            .pluck(RelayServers.Address)
            .run(conn)
        )

    except Exception as e:
        logger.exception(e)
        exist = False

    conn.close()

    return(exist)
Beispiel #12
0
def mouse_exists(mouse_name):

    conn = db_connect()
    try:
        exist = (
            r
            .table(RelayServersCollection)
            .get(mouse_name)
            .run(conn)
        )

    except Exception as e:
        logger.exception(e)
        exist = False

    conn.close()

    return(exist)
Beispiel #13
0
    def update_agents_with_supported(self, apps, agents=None):
        if agents is None:
            agents = []

        try:
            conn = db_connect()
            for agent in agents:
                self._delete_old_supported_apps_from_agent(
                    agent[SupportedAppsPerAgentKey.AgentId], conn)

            for app in apps:
                if not agents:
                    agents = self._get_list_of_agents_by_os_code(
                        app[AgentKey.OsCode])

                app_id = app.get(SupportedAppsKey.AppId)
                file_data = app.get(SupportedAppsKey.FileData)

                for agent in agents:
                    if agent[AgentKey.OsCode] == app[SupportedAppsKey.OsCode]:
                        agent_id = agent[SupportedAppsPerAgentKey.AgentId]

                        add_file_data(app_id, file_data, agent_id)

                        app_per_agent_props = \
                            self._set_app_per_agent_properties(agent, app_id)

                        agent_has_app = self.check_if_agent_has_app(
                            agent_id, app_id)

                        if not agent_has_app:
                            self.insert_app(app_per_agent_props)

                        elif agent_has_app:
                            app_per_agent_props[
                                SupportedAppsPerAgentKey.
                                Status] = CommonAppKeys.INSTALLED

                            self.insert_app(app_per_agent_props)

            conn.close()

        except Exception as e:
            logger.exception(e)
Beispiel #14
0
def all_agent_status():
    seconds = mktime(datetime.now().timetuple()) - 600
    try:
        conn = db_connect()
        (
            r
            .table(AgentsCollection)
            .filter(
                lambda x:
                x[AgentKey.LastAgentUpdate].to_epoch_time() < seconds
            )
            .update({AgentKey.AgentStatus: 'down'})
            .run(conn)
        )
        logger.info('agent uptime verifier completed')
        conn.close()

    except Exception as e:
        logger.exception(e)
Beispiel #15
0
def add_mouse(customer_names, mouse_name, address, username, uri, method):
    conn = db_connect()
    data = {
        RelayServers.RelayName: mouse_name,
        RelayServers.Customers: customer_names,
        RelayServers.Address: address,
    }
    try:
        (r.table(RelayServersCollection).insert(data).run(conn))
        status = (MightyMouseResults(username, uri,
                                     method).created(mouse_name, data))

    except Exception as e:
        status = (MightyMouseResults(username, uri,
                                     method).failed_to_create(mouse_name, e))

        logger.exception(status)

    conn.close()

    return (status)
Beispiel #16
0
def get_all_mouseys(username, uri, method, customer_name=None):

    conn = db_connect()
    try:
        if not customer_name:
            data = list(r.table(RelayServersCollection).run(conn))
        else:
            data = list(
                r.table(RelayServersCollection).filter(lambda x: x[
                    RelayServers.Customers].contains(customer_name)).run(conn))

        status = (GenericResults(username, uri, method).information_retrieved(
            data, len(data)))

    except Exception as e:
        status = (GenericResults(username, uri, method).something_broke(
            'retreiving Relay Servers', 'RelayServers', e))

    conn.close()

    return (status)
Beispiel #17
0
    def update_agents_with_supported(self, apps, agents=None):
        if agents is None:
            agents = []

        try:
            conn = db_connect()
            for agent in agents:
                self._delete_old_supported_apps_from_agent(agent[SupportedAppsPerAgentKey.AgentId], conn)

            for app in apps:
                if not agents:
                    agents = self._get_list_of_agents_by_os_code(app[AgentKey.OsCode])

                app_id = app.get(SupportedAppsKey.AppId)
                file_data = app.get(SupportedAppsKey.FileData)

                for agent in agents:
                    if agent[AgentKey.OsCode] == app[SupportedAppsKey.OsCode]:
                        agent_id = agent[SupportedAppsPerAgentKey.AgentId]

                        add_file_data(app_id, file_data, agent_id)

                        app_per_agent_props = self._set_app_per_agent_properties(agent, app_id)

                        agent_has_app = self.check_if_agent_has_app(agent_id, app_id)

                        if not agent_has_app:
                            self.insert_app(app_per_agent_props)

                        elif agent_has_app:
                            app_per_agent_props[SupportedAppsPerAgentKey.Status] = CommonAppKeys.INSTALLED

                            self.insert_app(app_per_agent_props)

            conn.close()

        except Exception as e:
            logger.exception(e)
Beispiel #18
0
def update_mouse(exist, mouse_name, customer_names, address, username, uri,
                 method):
    conn = db_connect()
    if not address:
        address = exist[RelayServers.Address]

    data = {
        RelayServers.Customers: customer_names,
        RelayServers.Address: address,
    }
    try:
        a = (r.table(RelayServersCollection).get(mouse_name).update(data).run(
            conn))
        status = (MightyMouseResults(username, uri,
                                     method).updated(mouse_name, data))

    except Exception as e:
        status = (MightyMouseResults(username, uri,
                                     method).failed_to_update(mouse_name, e))
        logger.exception(status)

    conn.close()

    return (status)
Beispiel #19
0
def get_all_mouseys(username, uri, method, customer_name=None):

    conn = db_connect()
    try:
        if not customer_name:
            data = list(
                r
                .table(RelayServersCollection)
                .run(conn)
            )
        else:
            data = list(
                r
                .table(RelayServersCollection)
                .filter(
                    lambda x: x[RelayServers.Customers].contains(customer_name)
                )
                .run(conn)
            )

        status = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, len(data))
        )

    except Exception as e:
        status = (
            GenericResults(
                username, uri, method
            ).something_broke('retreiving Relay Servers', 'RelayServers', e)
        )

    conn.close()

    return(status)
Beispiel #20
0
def initialize_indexes_and_create_tables():
    tables = [
        ('acls', Id),
        (AgentsCollection, AgentKey.AgentId),
        (AppCollections.UniqueApplications, AppsKey.AppId),
        (AppCollections.AppsPerAgent, Id),
        (AppCollections.CustomApps, CustomAppsKey.AppId),
        (AppCollections.CustomAppsPerAgent, Id),
        (AppCollections.SupportedApps, SupportedAppsKey.AppId),
        (AppCollections.SupportedAppsPerAgent, Id),
        (AppCollections.vFenseApps, vFenseAppsKey.AppId),
        (AppCollections.vFenseAppsPerAgent, Id),
        (FileCollections.Files, FilesKey.FileName),
        (FileCollections.FileServers, FileServerKeys.FileServerName),
        (CVECollections.CVE, CveKey.CveId),
        (WindowsSecurityCollection.Bulletin, WindowsSecurityBulletinKey.Id),
        (UbuntuSecurityCollection.Bulletin, UbuntuSecurityBulletinKey.Id),
        ('downloaded_status', Id),
        (HardwarePerAgentCollection, Id),
        (NotificationCollections.NotificationPlugins, Id),
        (NotificationCollections.Notifications, NotificationKeys.NotificationId),
        (NotificationCollections.NotificationsHistory, Id),
        ('notification_queue', Id),
        (OperationCollections.Agent, AgentOperationKey.OperationId),
        (OperationCollections.Admin, AgentOperationKey.OperationId),
        (OperationCollections.OperationPerAgent, Id),
        (OperationCollections.OperationPerApp, Id),
        ('plugin_configurations', 'name'),
        (DownloadCollections.LatestDownloadedSupported, SupportedAppsKey.AppId),
        (DownloadCollections.LatestDownloadedAgent, SupportedAppsKey.AppId),
        (TagsCollection, TagsKey.TagId),
        (TagsPerAgentCollection, Id),
        (QueueCollections.Agent, Id),
        (UserCollections.Users, UserKeys.UserName),
        (GroupCollections.Groups, GroupKeys.GroupId),
        (GroupCollections.GroupsPerUser, GroupsPerUserKeys.Id),
        (CustomerCollections.Customers, CustomerKeys.CustomerName),
        (CustomerCollections.CustomersPerUser, CustomerPerUserKeys.Id),
    ]
    conn = db_connect()
#################################### If Collections do not exist, create them #########################
    list_of_current_tables = r.table_list().run(conn)
    for table in tables:
        if table[0] not in list_of_current_tables:
            r.table_create(table[0], primary_key=table[1]).run(conn)

#################################### Get All Indexes ###################################################
    app_list = r.table(AppCollections.AppsPerAgent).index_list().run(conn)
    unique_app_list = r.table(AppCollections.UniqueApplications).index_list().run(conn)
    downloaded_list = r.table('downloaded_status').index_list().run(conn)
    custom_app_list = r.table(AppCollections.CustomApps).index_list().run(conn)
    custom_app_per_agent_list = r.table(AppCollections.CustomAppsPerAgent).index_list().run(conn)
    supported_app_list = r.table(AppCollections.SupportedApps).index_list().run(conn)
    supported_app_per_agent_list = r.table(AppCollections.SupportedAppsPerAgent).index_list().run(conn)
    vfense_app_list = r.table(AppCollections.vFenseApps).index_list().run(conn)
    vfense_app_per_agent_list = r.table(AppCollections.vFenseAppsPerAgent).index_list().run(conn)
    cve_list = r.table(CVECollections.CVE).index_list().run(conn)
    windows_bulletin_list = r.table(WindowsSecurityCollection.Bulletin).index_list().run(conn)
    ubuntu_bulletin_list = r.table(UbuntuSecurityCollection.Bulletin).index_list().run(conn)
    files_list = r.table(FileCollections.Files).index_list().run(conn)
    file_server_list = r.table(FileCollections.FileServers).index_list().run(conn)
    tags_list = r.table(TagsCollection).index_list().run(conn)
    agents_list = r.table(AgentsCollection).index_list().run(conn)
    agent_operations_list = r.table(OperationCollections.Agent).index_list().run(conn)
    admin_operations_list = r.table(OperationCollections.Admin).index_list().run(conn)
    operations_per_agent_list = r.table(OperationCollections.OperationPerAgent).index_list().run(conn)
    operations_per_app_list = r.table(OperationCollections.OperationPerApp).index_list().run(conn)
    notif_list = r.table(NotificationCollections.Notifications).index_list().run(conn)
    notif_history_list = r.table(NotificationCollections.NotificationsHistory).index_list().run(conn)
    hw_per_agent_list = r.table(HardwarePerAgentCollection).index_list().run(conn)
    tag_per_agent_list = r.table(TagsPerAgentCollection).index_list().run(conn)
    notif_plugin_list = r.table(NotificationCollections.NotificationPlugins,).index_list().run(conn)
    agent_queue_list = r.table(QueueCollections.Agent).index_list().run(conn)
    groups_list = r.table(GroupCollections.Groups).index_list().run(conn)
    groups_per_user_list = r.table(GroupCollections.GroupsPerUser).index_list().run(conn)
    customer_per_user_list = r.table(CustomerCollections.CustomersPerUser).index_list().run(conn)

#################################### AgentsColleciton Indexes ###################################################
    if not AgentIndexes.CustomerName in agents_list:
        r.table(AgentsCollection).index_create(AgentIndexes.CustomerName).run(conn)

    if not AgentIndexes.OsCode in agents_list:
        r.table(AgentsCollection).index_create(AgentIndexes.OsCode).run(conn)

#################################### AppsCollection Indexes ###################################################
    if not AppsIndexes.RvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(AppsIndexes.RvSeverity).run(conn)

    if not AppsIndexes.Name in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(AppsIndexes.Name).run(conn)

    if not AppsIndexes.NameAndVersion in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.NameAndVersion, lambda x: [
                x[AppsKey.Name], x[AppsKey.Version]]).run(conn)

    if not AppsIndexes.Customers in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(AppsIndexes.Customers, multi=True).run(conn)

    if not AppsIndexes.CustomerAndRvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.CustomerAndRvSeverity, lambda x: [
                x[AppsKey.Customers],
                x[AppsKey.RvSeverity]], multi=True).run(conn)

    if not AppsIndexes.AppIdAndRvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.AppIdAndRvSeverity, lambda x: [
                x[AppsKey.AppId],
                x[AppsKey.RvSeverity]]).run(conn)


#################################### FilesColleciton Indexes ###################################################
    if not FilesIndexes.FilesDownloadStatus in files_list:
        r.table(FileCollections.Files).index_create(FilesIndexes.FilesDownloadStatus).run(conn)

#################################### AppsPerAgentCollection Indexes ###################################################
    if not AppsPerAgentIndexes.Status in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(AppsPerAgentIndexes.Status).run(conn)

    if not AppsPerAgentIndexes.AgentId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(AppsPerAgentIndexes.AgentId).run(conn)

    if not AppsPerAgentIndexes.AppId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(AppsPerAgentIndexes.AppId).run(conn)

    if not AppsPerAgentIndexes.CustomerName in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(AppsPerAgentIndexes.CustomerName).run(conn)

    if not AppsPerAgentIndexes.AgentIdAndAppId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AgentIdAndAppId, lambda x: [
                x[AppsPerAgentKey.AgentId], x[AppsPerAgentKey.AppId]]).run(conn)

    if not AppsPerAgentIndexes.AppIdAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[AppsPerAgentKey.AppId], x[AppsPerAgentKey.CustomerName]]).run(conn)

    if not AppsPerAgentIndexes.AppIdAndStatus in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[AppsPerAgentKey.AppId], x[AppsPerAgentKey.Status]]).run(conn)

    if not AppsPerAgentIndexes.StatusAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[AppsPerAgentKey.Status], x[AppsPerAgentKey.CustomerName]]).run(conn)

    if not AppsPerAgentIndexes.AppIdAndStatusAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[AppsPerAgentKey.AppId],
                x[AppsPerAgentKey.Status],
                x[AppsPerAgentKey.CustomerName]]).run(conn)

    if not AppsPerAgentIndexes.StatusAndAgentId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[AppsPerAgentKey.Status], x[AppsPerAgentKey.AgentId]]).run(conn)


#################################### TagsCollection Indexes ###################################################
    if not TagsIndexes.CustomerName in tags_list:
        r.table(TagsCollection).index_create(TagsIndexes.CustomerName).run(conn)

    if not TagsIndexes.TagNameAndCustomer in tags_list:
        r.table(TagsCollection).index_create(
            TagsIndexes.TagNameAndCustomer, lambda x: [
                x[TagsKey.CustomerName], x[TagsKey.TagName]]).run(conn)

#################################### TagsPerAgentCollection Indexes ###################################################
    if not TagsPerAgentIndexes.TagId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(TagsPerAgentIndexes.TagId).run(conn)

    if not TagsPerAgentIndexes.AgentId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(TagsPerAgentIndexes.AgentId).run(conn)

    if not TagsPerAgentIndexes.AgentIdAndTagId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(
            TagsPerAgentIndexes.AgentIdAndTagId, lambda x: [
                x[TagsPerAgentKey.AgentId],
                x[TagsPerAgentKey.TagId]]).run(conn)


#################################### CustomAppsCollection Indexes ###################################################
    if not CustomAppsIndexes.RvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(CustomAppsIndexes.RvSeverity).run(conn)

    if not CustomAppsIndexes.Name in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(CustomAppsIndexes.Name).run(conn)

    if not CustomAppsIndexes.NameAndVersion in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.NameAndVersion, lambda x: [
                x[CustomAppsKey.Name], x[CustomAppsKey.Version]]).run(conn)

    if not CustomAppsIndexes.Customers in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(CustomAppsIndexes.Customers, multi=True).run(conn)

    if not CustomAppsIndexes.CustomerAndRvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.CustomerAndRvSeverity, lambda x: [
                x[CustomAppsKey.Customers], x[CustomAppsKey.RvSeverity]], multi=True).run(conn)

    if not CustomAppsIndexes.AppIdAndRvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.AppIdAndRvSeverity, lambda x: [
                x[CustomAppsKey.AppId],
                x[CustomAppsKey.RvSeverity]]).run(conn)

#################################### CustomAppsPerAgentCollection Indexes ###################################################
    if not CustomAppsPerAgentIndexes.Status in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(CustomAppsPerAgentIndexes.Status).run(conn)

    if not CustomAppsPerAgentIndexes.AgentId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(CustomAppsPerAgentIndexes.AgentId).run(conn)

    if not CustomAppsPerAgentIndexes.AppId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(CustomAppsPerAgentIndexes.AppId).run(conn)

    if not CustomAppsPerAgentIndexes.CustomerName in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(CustomAppsPerAgentIndexes.CustomerName).run(conn)

    if not CustomAppsPerAgentIndexes.AgentIdAndAppId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AgentIdAndAppId, lambda x: [
                x[CustomAppsPerAgentKey.AgentId], x[CustomAppsPerAgentKey.AppId]]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.AppId], x[CustomAppsPerAgentKey.CustomerName]]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndStatus in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[CustomAppsPerAgentKey.AppId], x[CustomAppsPerAgentKey.Status]]).run(conn)

    if not CustomAppsPerAgentIndexes.StatusAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.Status], x[CustomAppsPerAgentKey.CustomerName]]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndStatusAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.AppId],
                x[CustomAppsPerAgentKey.Status],
                x[CustomAppsPerAgentKey.CustomerName]]).run(conn)

    if not CustomAppsPerAgentIndexes.StatusAndAgentId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[CustomAppsPerAgentKey.Status], x[CustomAppsPerAgentKey.AgentId]]).run(conn)

#################################### SupportedAppsCollection Indexes ###################################################
    if not SupportedAppsIndexes.RvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(SupportedAppsIndexes.RvSeverity).run(conn)

    if not SupportedAppsIndexes.Name in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(SupportedAppsIndexes.Name).run(conn)

    if not SupportedAppsIndexes.NameAndVersion in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.NameAndVersion, lambda x: [
                x[SupportedAppsKey.Name], x[SupportedAppsKey.Version]]).run(conn)

    if not SupportedAppsIndexes.Customers in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(SupportedAppsIndexes.Customers, multi=True).run(conn)

    if not SupportedAppsIndexes.CustomerAndRvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.CustomerAndRvSeverity, lambda x: [
                x[SupportedAppsKey.Customers], x[SupportedAppsKey.RvSeverity]], multi=True).run(conn)

    if not SupportedAppsIndexes.AppIdAndRvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.AppIdAndRvSeverity, lambda x: [
                x[SupportedAppsKey.AppId],
                x[SupportedAppsKey.RvSeverity]]).run(conn)

#################################### SupportedAppsPerAgentCollection Indexes ###################################################
    if not SupportedAppsPerAgentIndexes.Status in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(SupportedAppsPerAgentIndexes.Status).run(conn)

    if not SupportedAppsPerAgentIndexes.AgentId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(SupportedAppsPerAgentIndexes.AgentId).run(conn)

    if not SupportedAppsPerAgentIndexes.AppId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(SupportedAppsPerAgentIndexes.AppId).run(conn)

    if not SupportedAppsPerAgentIndexes.CustomerName in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(SupportedAppsPerAgentIndexes.CustomerName).run(conn)

    if not SupportedAppsPerAgentIndexes.AgentIdAndAppId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AgentIdAndAppId, lambda x: [
                x[SupportedAppsPerAgentKey.AgentId], x[SupportedAppsPerAgentKey.AppId]]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.AppId], x[SupportedAppsPerAgentKey.CustomerName]]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndStatus in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[SupportedAppsPerAgentKey.AppId], x[SupportedAppsPerAgentKey.Status]]).run(conn)

    if not SupportedAppsPerAgentIndexes.StatusAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.Status], x[SupportedAppsPerAgentKey.CustomerName]]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndStatusAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.AppId],
                x[SupportedAppsPerAgentKey.Status],
                x[SupportedAppsPerAgentKey.CustomerName]]).run(conn)

    if not SupportedAppsPerAgentIndexes.StatusAndAgentId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[SupportedAppsPerAgentKey.Status], x[SupportedAppsPerAgentKey.AgentId]]).run(conn)

#################################### vFenseAppsCollection Indexes ###################################################
    if not vFenseAppsIndexes.RvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(AgentAppsIndexes.RvSeverity).run(conn)

    if not vFenseAppsIndexes.Name in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(AgentAppsIndexes.Name).run(conn)

    if not vFenseAppsIndexes.NameAndVersion in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.NameAndVersion, lambda x: [
                x[vFenseAppsKey.Name], x[vFenseAppsKey.Version]]).run(conn)

    if not vFenseAppsIndexes.Customers in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(AgentAppsIndexes.Customers, multi=True).run(conn)

    if not vFenseAppsIndexes.CustomerAndRvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.CustomerAndRvSeverity, lambda x: [
                x[vFenseAppsKey.Customers], x[vFenseAppsKey.RvSeverity]], multi=True).run(conn)

    if not vFenseAppsIndexes.AppIdAndRvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.AppIdAndRvSeverity, lambda x: [
                x[vFenseAppsKey.AppId],
                x[vFenseAppsKey.RvSeverity]]).run(conn)

#################################### vFenseAppsPerAgentCollection Indexes ###################################################
    if not vFenseAppsPerAgentIndexes.Status in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(AgentAppsPerAgentIndexes.Status).run(conn)

    if not vFenseAppsPerAgentIndexes.AgentId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(AgentAppsPerAgentIndexes.AgentId).run(conn)

    if not vFenseAppsPerAgentIndexes.AppId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(AgentAppsPerAgentIndexes.AppId).run(conn)

    if not vFenseAppsPerAgentIndexes.CustomerName in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(AgentAppsPerAgentIndexes.CustomerName).run(conn)

    if not vFenseAppsPerAgentIndexes.AgentIdAndAppId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AgentIdAndAppId, lambda x: [
                x[vFenseAppsPerAgentKey.AgentId], x[vFenseAppsPerAgentKey.AppId]]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.AppId], x[vFenseAppsPerAgentKey.CustomerName]]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndStatus in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[vFenseAppsPerAgentKey.AppId], x[vFenseAppsPerAgentKey.Status]]).run(conn)

    if not vFenseAppsPerAgentIndexes.StatusAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.Status], x[vFenseAppsPerAgentKey.CustomerName]]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndStatusAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.AppId],
                x[vFenseAppsPerAgentKey.Status],
                x[vFenseAppsPerAgentKey.CustomerName]]).run(conn)

    if not vFenseAppsPerAgentIndexes.StatusAndAgentId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[vFenseAppsPerAgentKey.Status], x[vFenseAppsPerAgentKey.AgentId]]).run(conn)


#################################### AgentOperationsCollection Indexes ###################################################
    if not AgentOperationIndexes.CustomerName in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(AgentOperationKey.CustomerName).run(conn)

    if not AgentOperationIndexes.TagId in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(AgentOperationKey.TagId).run(conn)

    if not AgentOperationIndexes.Operation in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(AgentOperationKey.Operation).run(conn)

    if not AgentOperationIndexes.AgentIds in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(AgentOperationIndexes.AgentIds, multi=True).run(conn)

    if not AgentOperationIndexes.OperationAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.OperationAndCustomer, lambda x: [
                x[AgentOperationKey.Operation],
                x[AgentOperationKey.CustomerName]]).run(conn)

    if not AgentOperationIndexes.PluginAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.PluginAndCustomer, lambda x: [
                x[AgentOperationKey.Plugin],
                x[AgentOperationKey.CustomerName]]).run(conn)

    if not AgentOperationIndexes.CreatedByAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.CreatedByAndCustomer, lambda x: [
                x[AgentOperationKey.CreatedBy],
                x[AgentOperationKey.CustomerName]]).run(conn)

#################################### OperationsPerAgentCollection Indexes ###################################################
    if not OperationPerAgentIndexes.OperationId in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(OperationPerAgentKey.OperationId).run(conn)

    if not OperationPerAgentIndexes.AgentIdAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.AgentIdAndCustomer, lambda x: [
                x[OperationPerAgentKey.AgentId],
                x[OperationPerAgentKey.CustomerName]]).run(conn)

    if not OperationPerAgentIndexes.TagIdAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.TagIdAndCustomer, lambda x: [
                x[OperationPerAgentKey.TagId],
                x[OperationPerAgentKey.CustomerName]]).run(conn)

    if not OperationPerAgentIndexes.StatusAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[OperationPerAgentKey.Status],
                x[OperationPerAgentKey.CustomerName]]).run(conn)

    if not OperationPerAgentIndexes.OperationIdAndAgentId in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.OperationIdAndAgentId, lambda x: [
                x[OperationPerAgentKey.OperationId],
                x[OperationPerAgentKey.AgentId]]).run(conn)

#################################### OperationsPerAppCollection Indexes ###################################################
    if not OperationPerAppIndexes.OperationId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(OperationPerAppKey.OperationId).run(conn)

    if not OperationPerAppIndexes.OperationIdAndAgentId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(
            OperationPerAppIndexes.OperationIdAndAgentId, lambda x: [
                x[OperationPerAppKey.OperationId],
                x[OperationPerAppKey.AgentId]]).run(conn)

    if not OperationPerAppIndexes.OperationIdAndAgentIdAndAppId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(
            OperationPerAppIndexes.OperationIdAndAgentIdAndAppId, lambda x: [
                x[OperationPerAppKey.OperationId],
                x[OperationPerAppKey.AgentId],
                x[OperationPerAppKey.AppId]]).run(conn)

#################################### HardwarePerAgentCollection Indexes ###################################################
    if not HardwarePerAgentIndexes.Type in hw_per_agent_list:
        r.table(HardwarePerAgentCollection).index_create(HardwarePerAgentIndexes.Type).run(conn)

    if not HardwarePerAgentIndexes.AgentId in hw_per_agent_list:
        r.table(HardwarePerAgentCollection).index_create(HardwarePerAgentIndexes.AgentId).run(conn)

#################################### DownloadStatusCollection Indexes ###################################################
    if not 'app_id' in downloaded_list:
        r.table('downloaded_status').index_create('app_id').run(conn)

    if not 'by_filename_and_rvid' in downloaded_list:
        r.table('downloaded_status').index_create(
            'by_filename_and_rvid', lambda x: [
                x['file_name'], x['app_id']]).run(conn)

#################################### NotificationsCollection Indexes ###################################################
    if not NotificationIndexes.CustomerName in notif_list:
        r.table(NotificationCollections.Notifications).index_create(NotificationKeys.CustomerName).run(conn)

    if not NotificationIndexes.RuleNameAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.RuleNameAndCustomer, lambda x: [
                x[NotificationKeys.RuleName],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.NotificationTypeAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.NotificationTypeAndCustomer, lambda x: [
                x[NotificationKeys.NotificationType],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.AppThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.AppThresholdAndCustomer, lambda x: [
                x[NotificationKeys.AppThreshold],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.RebootThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.RebootThresholdAndCustomer, lambda x: [
                x[NotificationKeys.RebootThreshold],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.ShutdownThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.ShutdownThresholdAndCustomer, lambda x: [
                x[NotificationKeys.ShutdownThreshold],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.CpuThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.CpuThresholdAndCustomer, lambda x: [
                x[NotificationKeys.CpuThreshold],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.MemThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.MemThresholdAndCustomer, lambda x: [
                x[NotificationKeys.MemThreshold],
                x[NotificationKeys.CustomerName]]).run(conn)

    if not NotificationIndexes.FileSystemThresholdAndFileSystemAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.FileSystemThresholdAndFileSystemAndCustomer, lambda x: [
                x[NotificationKeys.FileSystemThreshold],
                x[NotificationKeys.FileSystem],
                x[NotificationKeys.CustomerName]]).run(conn)

#################################### NotificationsHistory Indexes ###################################################
    if not NotificationHistoryIndexes.NotificationId in notif_history_list:
        r.table(NotificationCollections.NotificationsHistory).index_create(NotificationHistoryKeys.NotificationId).run(conn)

#################################### NotificationsPlugin Indexes ###################################################
    if not NotificationPluginIndexes.CustomerName in notif_plugin_list:
        r.table(NotificationCollections.NotificationPlugins).index_create(NotificationPluginKeys.CustomerName).run(conn)

#################################### Cve Indexes ###################################################
    if not CveIndexes.CveCategories in cve_list:
        r.table(CVECollections.CVE).index_create(CveIndexes.CveCategories, multi=True).run(conn)

#################################### Windows Bulletin Indexes ###################################################
    if not WindowsSecurityBulletinIndexes.BulletinId in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(WindowsSecurityBulletinIndexes.BulletinId).run(conn)

    if not WindowsSecurityBulletinIndexes.ComponentKb in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(WindowsSecurityBulletinIndexes.ComponentKb).run(conn)

    if not WindowsSecurityBulletinIndexes.CveIds in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(WindowsSecurityBulletinIndexes.CveIds, multi=True).run(conn)
#################################### Ubuntu Bulletin Indexes ###################################################
    if not UbuntuSecurityBulletinIndexes.BulletinId in ubuntu_bulletin_list:
        r.table(UbuntuSecurityCollection.Bulletin).index_create(UbuntuSecurityBulletinIndexes.BulletinId).run(conn)

    if not UbuntuSecurityBulletinIndexes.NameAndVersion in ubuntu_bulletin_list:
        r.table(UbuntuSecurityCollection.Bulletin).index_create(
            UbuntuSecurityBulletinIndexes.NameAndVersion, lambda x: 
                x[UbuntuSecurityBulletinKey.Apps].map(lambda y:
                    [y['name'], y['version']]), multi=True).run(conn)

#################################### Agent Queue Indexes ###################################################
    if not AgentQueueIndexes.AgentId in agent_queue_list:
        r.table(QueueCollections.Agent).index_create(AgentQueueIndexes.AgentId).run(conn)

#################################### Group Indexes ###################################################
    if not GroupIndexes.CustomerName in groups_list:
        r.table(GroupCollections.Groups).index_create(GroupIndexes.CustomerName).run(conn)

    if not GroupIndexes.GroupName in groups_list:
        r.table(GroupCollections.Groups).index_create(GroupIndexes.GroupName).run(conn)

#################################### Groups Per User Indexes ###################################################
    if not GroupsPerUserIndexes.UserName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(GroupsPerUserIndexes.UserName).run(conn)

    if not GroupsPerUserIndexes.CustomerName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(GroupsPerUserIndexes.CustomerName).run(conn)

    if not GroupsPerUserIndexes.GroupName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(GroupsPerUserIndexes.GroupName).run(conn)

    if not GroupsPerUserIndexes.GroupId in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(GroupsPerUserIndexes.GroupId).run(conn)

#################################### Customer Per User Indexes ###################################################
    if not CustomerPerUserIndexes.UserName in customer_per_user_list:
        r.table(CustomerCollections.CustomersPerUser).index_create(CustomerPerUserIndexes.UserName).run(conn)

    if not CustomerPerUserIndexes.CustomerName in customer_per_user_list:
        r.table(CustomerCollections.CustomersPerUser).index_create(CustomerPerUserIndexes.CustomerName).run(conn)

#################################### File Server Indexes ###################################################
    if not FileServerIndexes.CustomerName in file_server_list:
        r.table(FileCollections.FileServers).index_create(FileServerIndexes.CustomerName).run(conn)

#################################### Close Database Connection ###################################################
    conn.close()
Beispiel #21
0
def initialize_indexes_and_create_tables():
    tables = [
        ('acls', Id),
        (AgentsCollection, AgentKey.AgentId),
        (AppCollections.UniqueApplications, AppsKey.AppId),
        (AppCollections.AppsPerAgent, Id),
        (AppCollections.CustomApps, CustomAppsKey.AppId),
        (AppCollections.CustomAppsPerAgent, Id),
        (AppCollections.SupportedApps, SupportedAppsKey.AppId),
        (AppCollections.SupportedAppsPerAgent, Id),
        (AppCollections.vFenseApps, vFenseAppsKey.AppId),
        (AppCollections.vFenseAppsPerAgent, Id),
        (FileCollections.Files, FilesKey.FileName),
        (FileCollections.FileServers, FileServerKeys.FileServerName),
        (CVECollections.CVE, CveKey.CveId),
        (WindowsSecurityCollection.Bulletin, WindowsSecurityBulletinKey.Id),
        (UbuntuSecurityCollection.Bulletin, UbuntuSecurityBulletinKey.Id),
        ('downloaded_status', Id),
        (HardwarePerAgentCollection, Id),
        (NotificationCollections.NotificationPlugins, Id),
        (NotificationCollections.Notifications,
         NotificationKeys.NotificationId),
        (NotificationCollections.NotificationsHistory, Id),
        ('notification_queue', Id),
        (OperationCollections.Agent, AgentOperationKey.OperationId),
        (OperationCollections.Admin, AgentOperationKey.OperationId),
        (OperationCollections.OperationPerAgent, Id),
        (OperationCollections.OperationPerApp, Id),
        ('plugin_configurations', 'name'),
        (DownloadCollections.LatestDownloadedSupported,
         SupportedAppsKey.AppId),
        (DownloadCollections.LatestDownloadedAgent, SupportedAppsKey.AppId),
        (TagsCollection, TagsKey.TagId),
        (TagsPerAgentCollection, Id),
        (QueueCollections.Agent, Id),
        (UserCollections.Users, UserKeys.UserName),
        (GroupCollections.Groups, GroupKeys.GroupId),
        (GroupCollections.GroupsPerUser, GroupsPerUserKeys.Id),
        (CustomerCollections.Customers, CustomerKeys.CustomerName),
        (CustomerCollections.CustomersPerUser, CustomerPerUserKeys.Id),
    ]
    conn = db_connect()
    #################################### If Collections do not exist, create them #########################
    list_of_current_tables = r.table_list().run(conn)
    for table in tables:
        if table[0] not in list_of_current_tables:
            r.table_create(table[0], primary_key=table[1]).run(conn)

#################################### Get All Indexes ###################################################
    app_list = r.table(AppCollections.AppsPerAgent).index_list().run(conn)
    unique_app_list = r.table(
        AppCollections.UniqueApplications).index_list().run(conn)
    downloaded_list = r.table('downloaded_status').index_list().run(conn)
    custom_app_list = r.table(AppCollections.CustomApps).index_list().run(conn)
    custom_app_per_agent_list = r.table(
        AppCollections.CustomAppsPerAgent).index_list().run(conn)
    supported_app_list = r.table(
        AppCollections.SupportedApps).index_list().run(conn)
    supported_app_per_agent_list = r.table(
        AppCollections.SupportedAppsPerAgent).index_list().run(conn)
    vfense_app_list = r.table(AppCollections.vFenseApps).index_list().run(conn)
    vfense_app_per_agent_list = r.table(
        AppCollections.vFenseAppsPerAgent).index_list().run(conn)
    cve_list = r.table(CVECollections.CVE).index_list().run(conn)
    windows_bulletin_list = r.table(
        WindowsSecurityCollection.Bulletin).index_list().run(conn)
    ubuntu_bulletin_list = r.table(
        UbuntuSecurityCollection.Bulletin).index_list().run(conn)
    files_list = r.table(FileCollections.Files).index_list().run(conn)
    file_server_list = r.table(
        FileCollections.FileServers).index_list().run(conn)
    tags_list = r.table(TagsCollection).index_list().run(conn)
    agents_list = r.table(AgentsCollection).index_list().run(conn)
    agent_operations_list = r.table(
        OperationCollections.Agent).index_list().run(conn)
    admin_operations_list = r.table(
        OperationCollections.Admin).index_list().run(conn)
    operations_per_agent_list = r.table(
        OperationCollections.OperationPerAgent).index_list().run(conn)
    operations_per_app_list = r.table(
        OperationCollections.OperationPerApp).index_list().run(conn)
    notif_list = r.table(
        NotificationCollections.Notifications).index_list().run(conn)
    notif_history_list = r.table(
        NotificationCollections.NotificationsHistory).index_list().run(conn)
    hw_per_agent_list = r.table(HardwarePerAgentCollection).index_list().run(
        conn)
    tag_per_agent_list = r.table(TagsPerAgentCollection).index_list().run(conn)
    notif_plugin_list = r.table(
        NotificationCollections.NotificationPlugins, ).index_list().run(conn)
    agent_queue_list = r.table(QueueCollections.Agent).index_list().run(conn)
    groups_list = r.table(GroupCollections.Groups).index_list().run(conn)
    groups_per_user_list = r.table(
        GroupCollections.GroupsPerUser).index_list().run(conn)
    customer_per_user_list = r.table(
        CustomerCollections.CustomersPerUser).index_list().run(conn)

    #################################### AgentsColleciton Indexes ###################################################
    if not AgentIndexes.CustomerName in agents_list:
        r.table(AgentsCollection).index_create(
            AgentIndexes.CustomerName).run(conn)

    if not AgentIndexes.OsCode in agents_list:
        r.table(AgentsCollection).index_create(AgentIndexes.OsCode).run(conn)

#################################### AppsCollection Indexes ###################################################
    if not AppsIndexes.RvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.RvSeverity).run(conn)

    if not AppsIndexes.Name in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.Name).run(conn)

    if not AppsIndexes.NameAndVersion in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.NameAndVersion,
            lambda x: [x[AppsKey.Name], x[AppsKey.Version]]).run(conn)

    if not AppsIndexes.Customers in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.Customers, multi=True).run(conn)

    if not AppsIndexes.CustomerAndRvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.CustomerAndRvSeverity,
            lambda x: [x[AppsKey.Customers], x[AppsKey.RvSeverity]],
            multi=True).run(conn)

    if not AppsIndexes.AppIdAndRvSeverity in unique_app_list:
        r.table(AppCollections.UniqueApplications).index_create(
            AppsIndexes.AppIdAndRvSeverity,
            lambda x: [x[AppsKey.AppId], x[AppsKey.RvSeverity]]).run(conn)

#################################### FilesColleciton Indexes ###################################################
    if not FilesIndexes.FilesDownloadStatus in files_list:
        r.table(FileCollections.Files).index_create(
            FilesIndexes.FilesDownloadStatus).run(conn)

#################################### AppsPerAgentCollection Indexes ###################################################
    if not AppsPerAgentIndexes.Status in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.Status).run(conn)

    if not AppsPerAgentIndexes.AgentId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AgentId).run(conn)

    if not AppsPerAgentIndexes.AppId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppId).run(conn)

    if not AppsPerAgentIndexes.CustomerName in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.CustomerName).run(conn)

    if not AppsPerAgentIndexes.AgentIdAndAppId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AgentIdAndAppId, lambda x:
            [x[AppsPerAgentKey.AgentId], x[AppsPerAgentKey.AppId]]).run(conn)

    if not AppsPerAgentIndexes.AppIdAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndCustomer, lambda x:
            [x[AppsPerAgentKey.AppId], x[AppsPerAgentKey.CustomerName]]).run(
                conn)

    if not AppsPerAgentIndexes.AppIdAndStatus in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndStatus, lambda x:
            [x[AppsPerAgentKey.AppId], x[AppsPerAgentKey.Status]]).run(conn)

    if not AppsPerAgentIndexes.StatusAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.StatusAndCustomer, lambda x:
            [x[AppsPerAgentKey.Status], x[AppsPerAgentKey.CustomerName]]).run(
                conn)

    if not AppsPerAgentIndexes.AppIdAndStatusAndCustomer in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[AppsPerAgentKey.AppId], x[AppsPerAgentKey.Status], x[
                    AppsPerAgentKey.CustomerName]
            ]).run(conn)

    if not AppsPerAgentIndexes.StatusAndAgentId in app_list:
        r.table(AppCollections.AppsPerAgent).index_create(
            AppsPerAgentIndexes.StatusAndAgentId, lambda x:
            [x[AppsPerAgentKey.Status], x[AppsPerAgentKey.AgentId]]).run(conn)

#################################### TagsCollection Indexes ###################################################
    if not TagsIndexes.CustomerName in tags_list:
        r.table(TagsCollection).index_create(
            TagsIndexes.CustomerName).run(conn)

    if not TagsIndexes.TagNameAndCustomer in tags_list:
        r.table(TagsCollection).index_create(
            TagsIndexes.TagNameAndCustomer,
            lambda x: [x[TagsKey.CustomerName], x[TagsKey.TagName]]).run(conn)

#################################### TagsPerAgentCollection Indexes ###################################################
    if not TagsPerAgentIndexes.TagId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(
            TagsPerAgentIndexes.TagId).run(conn)

    if not TagsPerAgentIndexes.AgentId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(
            TagsPerAgentIndexes.AgentId).run(conn)

    if not TagsPerAgentIndexes.AgentIdAndTagId in tag_per_agent_list:
        r.table(TagsPerAgentCollection).index_create(
            TagsPerAgentIndexes.AgentIdAndTagId, lambda x:
            [x[TagsPerAgentKey.AgentId], x[TagsPerAgentKey.TagId]]).run(conn)

#################################### CustomAppsCollection Indexes ###################################################
    if not CustomAppsIndexes.RvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.RvSeverity).run(conn)

    if not CustomAppsIndexes.Name in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.Name).run(conn)

    if not CustomAppsIndexes.NameAndVersion in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.NameAndVersion,
            lambda x: [x[CustomAppsKey.Name], x[CustomAppsKey.Version]]).run(
                conn)

    if not CustomAppsIndexes.Customers in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.Customers, multi=True).run(conn)

    if not CustomAppsIndexes.CustomerAndRvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.CustomerAndRvSeverity,
            lambda x:
            [x[CustomAppsKey.Customers], x[CustomAppsKey.RvSeverity]],
            multi=True).run(conn)

    if not CustomAppsIndexes.AppIdAndRvSeverity in custom_app_list:
        r.table(AppCollections.CustomApps).index_create(
            CustomAppsIndexes.AppIdAndRvSeverity, lambda x:
            [x[CustomAppsKey.AppId], x[CustomAppsKey.RvSeverity]]).run(conn)

#################################### CustomAppsPerAgentCollection Indexes ###################################################
    if not CustomAppsPerAgentIndexes.Status in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.Status).run(conn)

    if not CustomAppsPerAgentIndexes.AgentId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AgentId).run(conn)

    if not CustomAppsPerAgentIndexes.AppId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppId).run(conn)

    if not CustomAppsPerAgentIndexes.CustomerName in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.CustomerName).run(conn)

    if not CustomAppsPerAgentIndexes.AgentIdAndAppId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AgentIdAndAppId, lambda x:
            [x[CustomAppsPerAgentKey.AgentId], x[CustomAppsPerAgentKey.AppId]
             ]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.AppId], x[CustomAppsPerAgentKey.
                                                  CustomerName]
            ]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndStatus in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[CustomAppsPerAgentKey.AppId], x[CustomAppsPerAgentKey.Status]
            ]).run(conn)

    if not CustomAppsPerAgentIndexes.StatusAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.Status], x[CustomAppsPerAgentKey.
                                                   CustomerName]
            ]).run(conn)

    if not CustomAppsPerAgentIndexes.AppIdAndStatusAndCustomer in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[CustomAppsPerAgentKey.AppId], x[CustomAppsPerAgentKey.Status
                                                  ], x[CustomAppsPerAgentKey.
                                                       CustomerName]
            ]).run(conn)

    if not CustomAppsPerAgentIndexes.StatusAndAgentId in custom_app_per_agent_list:
        r.table(AppCollections.CustomAppsPerAgent).index_create(
            CustomAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[CustomAppsPerAgentKey.Status], x[CustomAppsPerAgentKey.
                                                   AgentId]
            ]).run(conn)

#################################### SupportedAppsCollection Indexes ###################################################
    if not SupportedAppsIndexes.RvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.RvSeverity).run(conn)

    if not SupportedAppsIndexes.Name in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.Name).run(conn)

    if not SupportedAppsIndexes.NameAndVersion in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.NameAndVersion, lambda x:
            [x[SupportedAppsKey.Name], x[SupportedAppsKey.Version]]).run(conn)

    if not SupportedAppsIndexes.Customers in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.Customers, multi=True).run(conn)

    if not SupportedAppsIndexes.CustomerAndRvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.CustomerAndRvSeverity,
            lambda x:
            [x[SupportedAppsKey.Customers], x[SupportedAppsKey.RvSeverity]],
            multi=True).run(conn)

    if not SupportedAppsIndexes.AppIdAndRvSeverity in supported_app_list:
        r.table(AppCollections.SupportedApps).index_create(
            SupportedAppsIndexes.AppIdAndRvSeverity, lambda x:
            [x[SupportedAppsKey.AppId], x[SupportedAppsKey.RvSeverity]]).run(
                conn)

#################################### SupportedAppsPerAgentCollection Indexes ###################################################
    if not SupportedAppsPerAgentIndexes.Status in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.Status).run(conn)

    if not SupportedAppsPerAgentIndexes.AgentId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AgentId).run(conn)

    if not SupportedAppsPerAgentIndexes.AppId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppId).run(conn)

    if not SupportedAppsPerAgentIndexes.CustomerName in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.CustomerName).run(conn)

    if not SupportedAppsPerAgentIndexes.AgentIdAndAppId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AgentIdAndAppId, lambda x: [
                x[SupportedAppsPerAgentKey.AgentId], x[SupportedAppsPerAgentKey
                                                       .AppId]
            ]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.AppId], x[SupportedAppsPerAgentKey.
                                                     CustomerName]
            ]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndStatus in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[SupportedAppsPerAgentKey.AppId], x[SupportedAppsPerAgentKey.
                                                     Status]
            ]).run(conn)

    if not SupportedAppsPerAgentIndexes.StatusAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.Status], x[SupportedAppsPerAgentKey.
                                                      CustomerName]
            ]).run(conn)

    if not SupportedAppsPerAgentIndexes.AppIdAndStatusAndCustomer in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[SupportedAppsPerAgentKey.AppId],
                x[SupportedAppsPerAgentKey.Status], x[SupportedAppsPerAgentKey.
                                                      CustomerName]
            ]).run(conn)

    if not SupportedAppsPerAgentIndexes.StatusAndAgentId in supported_app_per_agent_list:
        r.table(AppCollections.SupportedAppsPerAgent).index_create(
            SupportedAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[SupportedAppsPerAgentKey.Status], x[SupportedAppsPerAgentKey.
                                                      AgentId]
            ]).run(conn)

#################################### vFenseAppsCollection Indexes ###################################################
    if not vFenseAppsIndexes.RvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            AgentAppsIndexes.RvSeverity).run(conn)

    if not vFenseAppsIndexes.Name in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            AgentAppsIndexes.Name).run(conn)

    if not vFenseAppsIndexes.NameAndVersion in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.NameAndVersion,
            lambda x: [x[vFenseAppsKey.Name], x[vFenseAppsKey.Version]]).run(
                conn)

    if not vFenseAppsIndexes.Customers in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            AgentAppsIndexes.Customers, multi=True).run(conn)

    if not vFenseAppsIndexes.CustomerAndRvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.CustomerAndRvSeverity,
            lambda x:
            [x[vFenseAppsKey.Customers], x[vFenseAppsKey.RvSeverity]],
            multi=True).run(conn)

    if not vFenseAppsIndexes.AppIdAndRvSeverity in vfense_app_list:
        r.table(AppCollections.vFenseApps).index_create(
            vFenseAppsIndexes.AppIdAndRvSeverity, lambda x:
            [x[vFenseAppsKey.AppId], x[vFenseAppsKey.RvSeverity]]).run(conn)

#################################### vFenseAppsPerAgentCollection Indexes ###################################################
    if not vFenseAppsPerAgentIndexes.Status in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            AgentAppsPerAgentIndexes.Status).run(conn)

    if not vFenseAppsPerAgentIndexes.AgentId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            AgentAppsPerAgentIndexes.AgentId).run(conn)

    if not vFenseAppsPerAgentIndexes.AppId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            AgentAppsPerAgentIndexes.AppId).run(conn)

    if not vFenseAppsPerAgentIndexes.CustomerName in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            AgentAppsPerAgentIndexes.CustomerName).run(conn)

    if not vFenseAppsPerAgentIndexes.AgentIdAndAppId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AgentIdAndAppId, lambda x:
            [x[vFenseAppsPerAgentKey.AgentId], x[vFenseAppsPerAgentKey.AppId]
             ]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.AppId], x[vFenseAppsPerAgentKey.
                                                  CustomerName]
            ]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndStatus in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndStatus, lambda x: [
                x[vFenseAppsPerAgentKey.AppId], x[vFenseAppsPerAgentKey.Status]
            ]).run(conn)

    if not vFenseAppsPerAgentIndexes.StatusAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.Status], x[vFenseAppsPerAgentKey.
                                                   CustomerName]
            ]).run(conn)

    if not vFenseAppsPerAgentIndexes.AppIdAndStatusAndCustomer in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.AppIdAndStatusAndCustomer, lambda x: [
                x[vFenseAppsPerAgentKey.AppId], x[vFenseAppsPerAgentKey.Status
                                                  ], x[vFenseAppsPerAgentKey.
                                                       CustomerName]
            ]).run(conn)

    if not vFenseAppsPerAgentIndexes.StatusAndAgentId in vfense_app_per_agent_list:
        r.table(AppCollections.vFenseAppsPerAgent).index_create(
            vFenseAppsPerAgentIndexes.StatusAndAgentId, lambda x: [
                x[vFenseAppsPerAgentKey.Status], x[vFenseAppsPerAgentKey.
                                                   AgentId]
            ]).run(conn)

#################################### AgentOperationsCollection Indexes ###################################################
    if not AgentOperationIndexes.CustomerName in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationKey.CustomerName).run(conn)

    if not AgentOperationIndexes.TagId in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationKey.TagId).run(conn)

    if not AgentOperationIndexes.Operation in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationKey.Operation).run(conn)

    if not AgentOperationIndexes.AgentIds in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.AgentIds, multi=True).run(conn)

    if not AgentOperationIndexes.OperationAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.OperationAndCustomer, lambda x: [
                x[AgentOperationKey.Operation], x[AgentOperationKey.
                                                  CustomerName]
            ]).run(conn)

    if not AgentOperationIndexes.PluginAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.PluginAndCustomer, lambda x: [
                x[AgentOperationKey.Plugin], x[AgentOperationKey.CustomerName]
            ]).run(conn)

    if not AgentOperationIndexes.CreatedByAndCustomer in agent_operations_list:
        r.table(OperationCollections.Agent).index_create(
            AgentOperationIndexes.CreatedByAndCustomer, lambda x: [
                x[AgentOperationKey.CreatedBy], x[AgentOperationKey.
                                                  CustomerName]
            ]).run(conn)

#################################### OperationsPerAgentCollection Indexes ###################################################
    if not OperationPerAgentIndexes.OperationId in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentKey.OperationId).run(conn)

    if not OperationPerAgentIndexes.AgentIdAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.AgentIdAndCustomer, lambda x: [
                x[OperationPerAgentKey.AgentId], x[OperationPerAgentKey.
                                                   CustomerName]
            ]).run(conn)

    if not OperationPerAgentIndexes.TagIdAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.TagIdAndCustomer, lambda x: [
                x[OperationPerAgentKey.TagId], x[OperationPerAgentKey.
                                                 CustomerName]
            ]).run(conn)

    if not OperationPerAgentIndexes.StatusAndCustomer in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.StatusAndCustomer, lambda x: [
                x[OperationPerAgentKey.Status], x[OperationPerAgentKey.
                                                  CustomerName]
            ]).run(conn)

    if not OperationPerAgentIndexes.OperationIdAndAgentId in operations_per_agent_list:
        r.table(OperationCollections.OperationPerAgent).index_create(
            OperationPerAgentIndexes.OperationIdAndAgentId, lambda x: [
                x[OperationPerAgentKey.OperationId], x[OperationPerAgentKey.
                                                       AgentId]
            ]).run(conn)

#################################### OperationsPerAppCollection Indexes ###################################################
    if not OperationPerAppIndexes.OperationId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(
            OperationPerAppKey.OperationId).run(conn)

    if not OperationPerAppIndexes.OperationIdAndAgentId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(
            OperationPerAppIndexes.OperationIdAndAgentId, lambda x:
            [x[OperationPerAppKey.OperationId], x[OperationPerAppKey.AgentId]
             ]).run(conn)

    if not OperationPerAppIndexes.OperationIdAndAgentIdAndAppId in operations_per_app_list:
        r.table(OperationCollections.OperationPerApp).index_create(
            OperationPerAppIndexes.OperationIdAndAgentIdAndAppId, lambda x: [
                x[OperationPerAppKey.OperationId], x[
                    OperationPerAppKey.AgentId], x[OperationPerAppKey.AppId]
            ]).run(conn)

#################################### HardwarePerAgentCollection Indexes ###################################################
    if not HardwarePerAgentIndexes.Type in hw_per_agent_list:
        r.table(HardwarePerAgentCollection).index_create(
            HardwarePerAgentIndexes.Type).run(conn)

    if not HardwarePerAgentIndexes.AgentId in hw_per_agent_list:
        r.table(HardwarePerAgentCollection).index_create(
            HardwarePerAgentIndexes.AgentId).run(conn)

#################################### DownloadStatusCollection Indexes ###################################################
    if not 'app_id' in downloaded_list:
        r.table('downloaded_status').index_create('app_id').run(conn)

    if not 'by_filename_and_rvid' in downloaded_list:
        r.table('downloaded_status').index_create(
            'by_filename_and_rvid',
            lambda x: [x['file_name'], x['app_id']]).run(conn)

#################################### NotificationsCollection Indexes ###################################################
    if not NotificationIndexes.CustomerName in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationKeys.CustomerName).run(conn)

    if not NotificationIndexes.RuleNameAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.RuleNameAndCustomer, lambda x: [
                x[NotificationKeys.RuleName], x[NotificationKeys.CustomerName]
            ]).run(conn)

    if not NotificationIndexes.NotificationTypeAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.NotificationTypeAndCustomer, lambda x: [
                x[NotificationKeys.NotificationType], x[NotificationKeys.
                                                        CustomerName]
            ]).run(conn)

    if not NotificationIndexes.AppThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.AppThresholdAndCustomer, lambda x: [
                x[NotificationKeys.AppThreshold], x[NotificationKeys.
                                                    CustomerName]
            ]).run(conn)

    if not NotificationIndexes.RebootThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.RebootThresholdAndCustomer, lambda x: [
                x[NotificationKeys.RebootThreshold], x[NotificationKeys.
                                                       CustomerName]
            ]).run(conn)

    if not NotificationIndexes.ShutdownThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.ShutdownThresholdAndCustomer, lambda x: [
                x[NotificationKeys.ShutdownThreshold], x[NotificationKeys.
                                                         CustomerName]
            ]).run(conn)

    if not NotificationIndexes.CpuThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.CpuThresholdAndCustomer, lambda x: [
                x[NotificationKeys.CpuThreshold], x[NotificationKeys.
                                                    CustomerName]
            ]).run(conn)

    if not NotificationIndexes.MemThresholdAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.MemThresholdAndCustomer, lambda x: [
                x[NotificationKeys.MemThreshold], x[NotificationKeys.
                                                    CustomerName]
            ]).run(conn)

    if not NotificationIndexes.FileSystemThresholdAndFileSystemAndCustomer in notif_list:
        r.table(NotificationCollections.Notifications).index_create(
            NotificationIndexes.FileSystemThresholdAndFileSystemAndCustomer,
            lambda x: [
                x[NotificationKeys.FileSystemThreshold],
                x[NotificationKeys.FileSystem], x[NotificationKeys.CustomerName
                                                  ]
            ]).run(conn)

#################################### NotificationsHistory Indexes ###################################################
    if not NotificationHistoryIndexes.NotificationId in notif_history_list:
        r.table(NotificationCollections.NotificationsHistory).index_create(
            NotificationHistoryKeys.NotificationId).run(conn)

#################################### NotificationsPlugin Indexes ###################################################
    if not NotificationPluginIndexes.CustomerName in notif_plugin_list:
        r.table(NotificationCollections.NotificationPlugins).index_create(
            NotificationPluginKeys.CustomerName).run(conn)

#################################### Cve Indexes ###################################################
    if not CveIndexes.CveCategories in cve_list:
        r.table(CVECollections.CVE).index_create(CveIndexes.CveCategories,
                                                 multi=True).run(conn)

#################################### Windows Bulletin Indexes ###################################################
    if not WindowsSecurityBulletinIndexes.BulletinId in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(
            WindowsSecurityBulletinIndexes.BulletinId).run(conn)

    if not WindowsSecurityBulletinIndexes.ComponentKb in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(
            WindowsSecurityBulletinIndexes.ComponentKb).run(conn)

    if not WindowsSecurityBulletinIndexes.CveIds in windows_bulletin_list:
        r.table(WindowsSecurityCollection.Bulletin).index_create(
            WindowsSecurityBulletinIndexes.CveIds, multi=True).run(conn)
#################################### Ubuntu Bulletin Indexes ###################################################
    if not UbuntuSecurityBulletinIndexes.BulletinId in ubuntu_bulletin_list:
        r.table(UbuntuSecurityCollection.Bulletin).index_create(
            UbuntuSecurityBulletinIndexes.BulletinId).run(conn)

    if not UbuntuSecurityBulletinIndexes.NameAndVersion in ubuntu_bulletin_list:
        r.table(UbuntuSecurityCollection.Bulletin).index_create(
            UbuntuSecurityBulletinIndexes.NameAndVersion,
            lambda x: x[UbuntuSecurityBulletinKey.Apps].map(
                lambda y: [y['name'], y['version']]),
            multi=True).run(conn)

#################################### Agent Queue Indexes ###################################################
    if not AgentQueueIndexes.AgentId in agent_queue_list:
        r.table(QueueCollections.Agent).index_create(
            AgentQueueIndexes.AgentId).run(conn)

#################################### Group Indexes ###################################################
    if not GroupIndexes.CustomerName in groups_list:
        r.table(GroupCollections.Groups).index_create(
            GroupIndexes.CustomerName).run(conn)

    if not GroupIndexes.GroupName in groups_list:
        r.table(GroupCollections.Groups).index_create(
            GroupIndexes.GroupName).run(conn)

#################################### Groups Per User Indexes ###################################################
    if not GroupsPerUserIndexes.UserName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(
            GroupsPerUserIndexes.UserName).run(conn)

    if not GroupsPerUserIndexes.CustomerName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(
            GroupsPerUserIndexes.CustomerName).run(conn)

    if not GroupsPerUserIndexes.GroupName in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(
            GroupsPerUserIndexes.GroupName).run(conn)

    if not GroupsPerUserIndexes.GroupId in groups_per_user_list:
        r.table(GroupCollections.GroupsPerUser).index_create(
            GroupsPerUserIndexes.GroupId).run(conn)

#################################### Customer Per User Indexes ###################################################
    if not CustomerPerUserIndexes.UserName in customer_per_user_list:
        r.table(CustomerCollections.CustomersPerUser).index_create(
            CustomerPerUserIndexes.UserName).run(conn)

    if not CustomerPerUserIndexes.CustomerName in customer_per_user_list:
        r.table(CustomerCollections.CustomersPerUser).index_create(
            CustomerPerUserIndexes.CustomerName).run(conn)

#################################### File Server Indexes ###################################################
    if not FileServerIndexes.CustomerName in file_server_list:
        r.table(FileCollections.FileServers).index_create(
            FileServerIndexes.CustomerName).run(conn)

#################################### Close Database Connection ###################################################
    conn.close()
Beispiel #22
0
    try:
        if os.path.exists(RETHINK_DATA_PATH):
            shutil.rmtree(RETHINK_DATA_PATH)
        msg = "Rethink instances.d directory removed and cleaned"
    except Exception as e:
        msg = "Rethink instances.d directory could not be removed"
        completed = False
    if rql_msg and msg:
        msg = rql_msg + msg
    elif rql_msg and not msg:
        msg = rql_msg
    return completed, msg


if __name__ == "__main__":
    conn = db_connect()
    if conn:
        connected = True
        rql_msg = "Rethink is Running"
    else:
        connected = False
        rql_msg = "Rethink is not Running"
    print rql_msg
    db_clean, db_msg = clean_database(connected)
    print db_msg
    db_initialized, msg = initialize_db()
    initialized = False
    if db_initialized:
        print "vFense environment has been succesfully initialized\n"
        subprocess.Popen(["chown", "-R", "vfense.vfense", VFENSE_BASE_PATH])
Beispiel #23
0
def initialize_db():
    os.umask(0)
    if not os.path.exists(VFENSE_TMP_PATH):
        os.mkdir(VFENSE_TMP_PATH, 0755)
    if not os.path.exists(RETHINK_CONF):
        subprocess.Popen(["ln", "-s", RETHINK_SOURCE_CONF, RETHINK_CONF])
    if not os.path.exists("/var/lib/rethinkdb/vFense"):
        os.makedirs("/var/lib/rethinkdb/vFense")
        subprocess.Popen(["chown", "-R", "rethinkdb.rethinkdb", "/var/lib/rethinkdb/vFense"])

    if not os.path.exists(VFENSE_LOG_PATH):
        os.mkdir(VFENSE_LOG_PATH, 0755)
    if not os.path.exists(VFENSE_SCHEDULER_PATH):
        os.mkdir(VFENSE_SCHEDULER_PATH, 0755)
    if not os.path.exists(VFENSE_APP_PATH):
        os.mkdir(VFENSE_APP_PATH, 0755)
    if not os.path.exists(VFENSE_APP_TMP_PATH):
        os.mkdir(VFENSE_APP_TMP_PATH, 0775)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "windows/data/xls")):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, "windows/data/xls"), 0755)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "cve/data/xml")):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, "cve/data/xml"), 0755)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, "ubuntu/data/html")):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, "ubuntu/data/html"), 0755)
    if get_distro() in DEBIAN_DISTROS:
        subprocess.Popen(["update-rc.d", "vFense", "defaults"])

        if not os.path.exists("/etc/init.d/vFense"):
            subprocess.Popen(["ln", "-s", os.path.join(VFENSE_BASE_SRC_PATH, "daemon/vFense"), VFENSE_INIT_D])

    if get_distro() in REDHAT_DISTROS:
        if os.path.exists("/usr/bin/rqworker"):
            subprocess.Popen(["ln", "-s", "/usr/bin/rqworker", "/usr/local/bin/rqworker"])

    if os.path.exists(get_sheduler_location()):
        subprocess.Popen(
            ["patch", "-N", get_sheduler_location(), os.path.join(VFENSE_CONF_PATH, "patches/scheduler.patch")]
        )
    try:
        tp_exists = pwd.getpwnam("vfense")

    except Exception as e:
        if get_distro() in DEBIAN_DISTROS:
            subprocess.Popen(["adduser", "--disabled-password", "--gecos", "", "vfense"])
        elif get_distro() in REDHAT_DISTROS:
            subprocess.Popen(["useradd", "vfense"])

    rethink_start = subprocess.Popen(["service", "rethinkdb", "start"])
    while not db_connect():
        print "Sleeping until rethink starts"
        sleep(2)
    completed = True
    if completed:
        conn = db_connect()
        r.db_create("vFense").run(conn)
        db = r.db("vFense")
        conn.close()
        ci.initialize_indexes_and_create_tables()
        conn = db_connect()

        default_customer = Customer(DefaultCustomers.DEFAULT, server_queue_ttl=args.queue_ttl, package_download_url=url)

        customers.create_customer(default_customer, init=True)

        group_data = group.create_group(DefaultGroups.ADMIN, DefaultCustomers.DEFAULT, [Permissions.ADMINISTRATOR])
        admin_group_id = group_data["generated_ids"]
        user.create_user(
            DefaultUsers.ADMIN,
            "vFense Admin Account",
            args.admin_password,
            admin_group_id,
            DefaultCustomers.DEFAULT,
            "",
        )
        print "Admin username = admin"
        print "Admin password = %s" % (args.admin_password)
        agent_pass = generate_pass()
        while not check_password(agent_pass)[0]:
            agent_pass = generate_pass()

        user.create_user(
            DefaultUsers.AGENT,
            "vFense Agent Communication Account",
            agent_pass,
            admin_group_id,
            DefaultCustomers.DEFAULT,
            "",
        )
        print "Agent api user = agent_api"
        print "Agent password = %s" % (agent_pass)

        monit.monit_initialization()

        if args.cve_data:
            print "Updating CVE's..."
            load_up_all_xml_into_db()
            print "Done Updating CVE's..."
            print "Updating Microsoft Security Bulletin Ids..."
            parse_bulletin_and_updatedb()
            print "Done Updating Microsoft Security Bulletin Ids..."
            print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )"
            begin_usn_home_page_processing(full_parse=True)
            print "Done Updating Ubuntu Security Bulletin Ids..."

        conn.close()
        completed = True

        msg = "Rethink Initialization and Table creation is now complete"
        # rethink_stop = subprocess.Popen(['service', 'rethinkdb','stop'])
        rql_msg = "Rethink stopped successfully\n"

        return completed, msg
    else:
        completed = False
        msg = "Failed during Rethink startup process"
        return completed, msg
Beispiel #24
0
    try:
        if os.path.exists(RETHINK_DATA_PATH):
            shutil.rmtree(RETHINK_DATA_PATH)
        msg = 'Rethink instances.d directory removed and cleaned'
    except Exception as e:
        msg = 'Rethink instances.d directory could not be removed'
        completed = False
    if rql_msg and msg:
        msg = rql_msg + msg
    elif rql_msg and not msg:
        msg = rql_msg
    return completed, msg


if __name__ == '__main__':
    conn = db_connect()
    if conn:
        connected = True
        rql_msg = 'Rethink is Running'
    else:
        connected = False
        rql_msg = 'Rethink is not Running'
    print rql_msg
    db_clean, db_msg = clean_database(connected)
    print db_msg
    db_initialized, msg = initialize_db()
    initialized = False
    if db_initialized:
        print 'vFense environment has been succesfully initialized\n'
        subprocess.Popen(['chown', '-R', 'vfense.vfense', VFENSE_BASE_PATH], )
Beispiel #25
0
def initialize_db():
    os.umask(0)
    if not os.path.exists(VFENSE_TMP_PATH):
        os.mkdir(VFENSE_TMP_PATH, 0755)
    if not os.path.exists(RETHINK_CONF):
        subprocess.Popen(['ln', '-s', RETHINK_SOURCE_CONF, RETHINK_CONF], )
    if not os.path.exists('/var/lib/rethinkdb/vFense'):
        os.makedirs('/var/lib/rethinkdb/vFense')
        subprocess.Popen([
            'chown', '-R', 'rethinkdb.rethinkdb', '/var/lib/rethinkdb/vFense'
        ], )

    if not os.path.exists(VFENSE_LOG_PATH):
        os.mkdir(VFENSE_LOG_PATH, 0755)
    if not os.path.exists(VFENSE_SCHEDULER_PATH):
        os.mkdir(VFENSE_SCHEDULER_PATH, 0755)
    if not os.path.exists(VFENSE_APP_PATH):
        os.mkdir(VFENSE_APP_PATH, 0755)
    if not os.path.exists(VFENSE_APP_TMP_PATH):
        os.mkdir(VFENSE_APP_TMP_PATH, 0775)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'windows/data/xls')):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, 'windows/data/xls'), 0755)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'cve/data/xml')):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, 'cve/data/xml'), 0755)
    if not os.path.exists(os.path.join(VFENSE_VULN_PATH, 'ubuntu/data/html')):
        os.makedirs(os.path.join(VFENSE_VULN_PATH, 'ubuntu/data/html'), 0755)
    if get_distro() in DEBIAN_DISTROS:
        subprocess.Popen(['update-rc.d', 'vFense', 'defaults'], )

        if not os.path.exists('/etc/init.d/vFense'):
            subprocess.Popen([
                'ln', '-s',
                os.path.join(VFENSE_BASE_SRC_PATH, 'daemon/vFense'),
                VFENSE_INIT_D
            ], )

    if get_distro() in REDHAT_DISTROS:
        if os.path.exists('/usr/bin/rqworker'):
            subprocess.Popen(
                ['ln', '-s', '/usr/bin/rqworker', '/usr/local/bin/rqworker'], )

    if os.path.exists(get_sheduler_location()):
        subprocess.Popen([
            'patch', '-N',
            get_sheduler_location(),
            os.path.join(VFENSE_CONF_PATH, 'patches/scheduler.patch')
        ], )
    try:
        tp_exists = pwd.getpwnam('vfense')

    except Exception as e:
        if get_distro() in DEBIAN_DISTROS:
            subprocess.Popen([
                'adduser',
                '--disabled-password',
                '--gecos',
                '',
                'vfense',
            ], )
        elif get_distro() in REDHAT_DISTROS:
            subprocess.Popen([
                'useradd',
                'vfense',
            ], )

    rethink_start = subprocess.Popen(['service', 'rethinkdb', 'start'])
    while not db_connect():
        print 'Sleeping until rethink starts'
        sleep(2)
    completed = True
    if completed:
        conn = db_connect()
        r.db_create('vFense').run(conn)
        db = r.db('vFense')
        conn.close()
        ci.initialize_indexes_and_create_tables()
        conn = db_connect()

        default_customer = Customer(DefaultCustomers.DEFAULT,
                                    server_queue_ttl=args.queue_ttl,
                                    package_download_url=url)

        customers.create_customer(default_customer, init=True)

        group_data = group.create_group(DefaultGroups.ADMIN,
                                        DefaultCustomers.DEFAULT,
                                        [Permissions.ADMINISTRATOR])
        admin_group_id = group_data['generated_ids']
        user.create_user(
            DefaultUsers.ADMIN,
            'vFense Admin Account',
            args.admin_password,
            admin_group_id,
            DefaultCustomers.DEFAULT,
            '',
        )
        print 'Admin username = admin'
        print 'Admin password = %s' % (args.admin_password)
        agent_pass = generate_pass()
        while not check_password(agent_pass)[0]:
            agent_pass = generate_pass()

        user.create_user(
            DefaultUsers.AGENT,
            'vFense Agent Communication Account',
            agent_pass,
            admin_group_id,
            DefaultCustomers.DEFAULT,
            '',
        )
        print 'Agent api user = agent_api'
        print 'Agent password = %s' % (agent_pass)

        monit.monit_initialization()

        if args.cve_data:
            print "Updating CVE's..."
            load_up_all_xml_into_db()
            print "Done Updating CVE's..."
            print "Updating Microsoft Security Bulletin Ids..."
            parse_bulletin_and_updatedb()
            print "Done Updating Microsoft Security Bulletin Ids..."
            print "Updating Ubuntu Security Bulletin Ids...( This can take a couple of minutes )"
            begin_usn_home_page_processing(full_parse=True)
            print "Done Updating Ubuntu Security Bulletin Ids..."

        conn.close()
        completed = True

        msg = 'Rethink Initialization and Table creation is now complete'
        #rethink_stop = subprocess.Popen(['service', 'rethinkdb','stop'])
        rql_msg = 'Rethink stopped successfully\n'

        return completed, msg
    else:
        completed = False
        msg = 'Failed during Rethink startup process'
        return completed, msg