Beispiel #1
0
    def __init__(self, username, uri, method, agent_id,
                 app_id, operation_id, reboot_required,
                 success, data, apps_to_delete,
                 apps_to_add, error=None):

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.reboot_required = reboot_required
        self.success = success
        self.data = data
        self.apps_to_delete = apps_to_delete
        self.apps_to_add = apps_to_add
        self.app_id = app_id
        self.oper_info=get_oper_info(operid=self.operation_id)
        self.operation = (
            Operation(
                self.username, self.customer_name,
                self.uri, self.method
            )
        )
Beispiel #2
0
def add_supported_app_to_agents(username, customer_name, uri, method, agent_id=None):

    if agent_id:
        agent_info = get_agent_info(agent_id)
        apps_info = (
            get_apps_data(
                customer_name,
                table=SupportedAppsCollection,
                os_code=agent_info[AgentKey.OsCode]
            )
        )
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(SupportedAppsKey.AppId)
                file_data = get_file_data(app_id)
                update_file_data(
                    app_id,
                    agent_id, file_data
                )
                agent_info_to_insert = (
                    {
                        SupportedAppsPerAgentKey.AgentId: agent_id,
                        SupportedAppsPerAgentKey.AppId: app_id,
                        SupportedAppsPerAgentKey.Status: AVAILABLE,
                        SupportedAppsPerAgentKey.CustomerName: customer_name,
                        SupportedAppsPerAgentKey.InstallDate: r.epoch_time(0.0)
                    }
                )
                apps_to_insert_per_agent(
                    username, uri, method, agent_info_to_insert,
                    table=SupportedAppsPerAgentCollection
                )
Beispiel #3
0
    def __init__(self, username, customer_name, uri, method,
                 agentid, rv_plugin, agent_data=None,
                 oper_type='newagent', delete_afterwards=True):

        self.delete_afterwards = delete_afterwards
        self.customer_name = customer_name
        if not agent_data:
            agent_data = get_agent_info(
                agentid=agentid
            )

        self.add_packages_from_agent(
            username, agentid,
            agent_data, rv_plugin
        )
        
        if oper_type == 'newagent':
            self.add_custom_apps(
                username, customer_name,
                uri, method, agentid
            )
            self.add_supported_apps(agentid)
            self.add_agent_apps(agentid)

        elif oper_type == 'updatesapplications':
            self.add_supported_apps(agentid)
            self.add_agent_apps(agentid)
Beispiel #4
0
    def __init__(self,
                 username,
                 customer_name,
                 uri,
                 method,
                 agentid,
                 rv_plugin,
                 agent_data=None,
                 oper_type='newagent',
                 delete_afterwards=True):

        self.delete_afterwards = delete_afterwards
        self.customer_name = customer_name
        if not agent_data:
            agent_data = get_agent_info(agentid=agentid)

        self.add_packages_from_agent(username, agentid, agent_data, rv_plugin)

        if oper_type == 'newagent':
            self.add_custom_apps(username, customer_name, uri, method, agentid)
            self.add_supported_apps(agentid)
            self.add_agent_apps(agentid)

        elif oper_type == 'updatesapplications':
            self.add_supported_apps(agentid)
            self.add_agent_apps(agentid)
Beispiel #5
0
def add_supported_app_to_agents(username,
                                customer_name,
                                uri,
                                method,
                                agent_id=None):

    if agent_id:
        agent_info = get_agent_info(agent_id)
        apps_info = (get_apps_data(customer_name,
                                   table=SupportedAppsCollection,
                                   os_code=agent_info[AgentKey.OsCode]))
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(SupportedAppsKey.AppId)
                file_data = get_file_data(app_id)
                update_file_data(app_id, agent_id, file_data)
                agent_info_to_insert = ({
                    SupportedAppsPerAgentKey.AgentId:
                    agent_id,
                    SupportedAppsPerAgentKey.AppId:
                    app_id,
                    SupportedAppsPerAgentKey.Status:
                    AVAILABLE,
                    SupportedAppsPerAgentKey.CustomerName:
                    customer_name,
                    SupportedAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                apps_to_insert_per_agent(username,
                                         uri,
                                         method,
                                         agent_info_to_insert,
                                         table=SupportedAppsPerAgentCollection)
Beispiel #6
0
    def __init__(self,
                 username,
                 uri,
                 method,
                 agent_id,
                 app_id,
                 operation_id,
                 reboot_required,
                 success,
                 data,
                 apps_to_delete,
                 apps_to_add,
                 error=None):

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.reboot_required = reboot_required
        self.success = success
        self.data = data
        self.apps_to_delete = apps_to_delete
        self.apps_to_add = apps_to_add
        self.app_id = app_id
        self.oper_info = get_oper_info(operid=self.operation_id)
        self.operation = (Operation(self.username, self.customer_name,
                                    self.uri, self.method))
Beispiel #7
0
def get_all_agent_apps_for_agent(agent_id):
    agent = get_agent_info(agent_id)
    apps = (get_apps_data(table=LatestDownloadedAgentCollection,
                          os_code=agent[AgentKey.OsCode]))

    if apps:
        update_apps = (IncomingSupportedOrAgentApps(table=AgentAppsCollection))
        update_apps.update_agents_with_supported(apps, [agent])
    def filter_by_status_and_sev(self, pkg_status, sev, conn=None):

        try:
            agent = get_agent_info(self.agent_id)
            if agent:
                if pkg_status in ValidPackageStatuses:
                    if sev in ValidRvSeverities:
                        base = (r.table(
                            self.CurrentAppsPerAgentCollection).get_all(
                                [pkg_status, self.agent_id],
                                index=self.CurrentAppsPerAgentIndexes.
                                StatusAndAgentId).eq_join(
                                    self.CurrentAppsPerAgentKey.AppId,
                                    r.table(self.CurrentAppsCollection)).zip())
                        if self.show_hidden == NO:
                            base = base.filter(
                                {self.CurrentAppsKey.Hidden: NO})

                        packages = list(
                            base.filter(r.row[self.CurrentAppsKey.RvSeverity]
                                        == sev).map(self.map_hash).order_by(
                                            self.sort(self.sort_key)).skip(
                                                self.offset).limit(
                                                    self.count).run(conn))

                        pkg_count = (base.filter(
                            r.row[self.CurrentAppsKey.RvSeverity] ==
                            sev).count().run(conn))

                        return_status = (GenericResults(
                            self.username, self.uri,
                            self.method).information_retrieved(
                                packages, pkg_count))

                    else:
                        return_status = (PackageResults(
                            self.username, self.uri,
                            self.method).invalid_severity(sev))

                else:
                    return_status = (PackageResults(
                        self.username, self.uri,
                        self.method).invalid_status(self.agent_id, pkg_status))

            else:
                return_status = (GenericResults(self.username, self.uri,
                                                self.method).invalid_id(
                                                    self.agent_id, 'agents'))

        except Exception as e:
            return_status = (GenericResults(
                self.username, self.uri,
                self.method).something_broke("Package Searching went haywire",
                                             'os_updates', e))
            logger.exception(e)

        return (return_status)
Beispiel #9
0
    def delete_agent(self, uri, method, conn=None):
        try:
            agent_info = get_agent_info(self.agent_id)
            if agent_info:
                (
                    r
                    .table(AgentsCollection)
                    .get(self.agent_id)
                    .delete()
                    .run(conn)
                )

                (
                    r
                    .table(HardwarePerAgentCollection)
                    .get_all(self.agent_id, index=HardwarePerAgentIndexes.AgentId)
                    .delete()
                    .run(conn)
                )
                (
                    r
                    .table(TagsPerAgentCollection)
                    .get_all(self.agent_id, index=TagsPerAgentIndexes.AgentId)
                    .delete()
                    .run(conn)
                )

                rv_q = Queue('delete_agent', connection=rq_pool)
                rv_q.enqueue_call(
                    func=delete_all_app_data_for_agent,
                    args=(self.agent_id,),
                    timeout=3600,
                )
                status = (
                    GenericResults(
                        self.username, uri, method
                    ).object_deleted(self.agent_id, 'agents')
                )
                logger.info(status['message'])

            else:
                status = (
                    GenericResults(
                        self.username, uri, method
                    ).invalid_id(self.agent_id, 'agents')
                )
                logger.info(status['message'])

        except Exception as e:
            status = (
                GenericResults(
                    self.username, uri, method
                ).something_broke(self.agent_id, 'agents', e)
            )
            logger.exception(status['message'])

        return(status)
Beispiel #10
0
    def query_by_name(self, name, conn=None):
        try:
            agent = get_agent_info(self.agent_id)
            if agent:
                base = (
                    r
                    .table(self.CurrentAppsPerAgentCollection)
                    .get_all(self.agent_id, index=self.CurrentAppsPerAgentIndexes.AgentId)
                    .eq_join(self.CurrentAppsPerAgentKey.AppId, r.table(self.CurrentAppsCollection))
                    .zip()
                )
                if self.show_hidden == NO:
                    base = base.filter({self.CurrentAppsKey.Hidden: NO})

                packages = list(
                    base
                    .filter(lambda x: x[self.CurrentAppsKey.Name].match("(?i)"+name))
                    .map(self.map_hash)
                    .order_by(self.sort(self.sort_key))
                    .skip(self.offset)
                    .limit(self.count)
                    .run(conn)
                )

                pkg_count = (
                    base
                    .filter(lambda x: x[self.CurrentAppsKey.Name].match("(?i)"+name))
                    .count()
                    .run(conn)
                )

                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).information_retrieved(packages, pkg_count)
                )

            else:
                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).invalid_id(self.agent_id, 'agents')
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)
Beispiel #11
0
def add_custom_app_to_agents(username,
                             customer_name,
                             uri,
                             method,
                             file_data,
                             agent_id=None,
                             app_id=None):

    if app_id and not agent_id:
        app_info = (get_app_data(app_id, table=CustomAppsCollection))

        agent_ids = get_all_agent_ids(customer_name,
                                      agent_os=app_info[AgentKey.OsCode])
        if len(agent_ids) > 0:
            for agentid in agent_ids:
                update_file_data(app_id, agentid, file_data)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agentid,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                apps_to_insert_per_agent(username, uri, method,
                                         agent_info_to_insert)

    if agent_id and not app_id:
        agent_info = get_agent_info(agent_id)
        apps_info = get_apps_data(customer_name,
                                  os_code=agent_info[AgentKey.OsCode])
        if len(apps_info) > 0:
            for app_info in apps_info:
                app_id = app_info.get(CustomAppsKey.AppId)
                file_data = get_file_data(app_id)
                update_file_data(app_id, agent_id, file_data)
                agent_info_to_insert = ({
                    CustomAppsPerAgentKey.AgentId:
                    agent_id,
                    CustomAppsPerAgentKey.AppId:
                    app_id,
                    CustomAppsPerAgentKey.Status:
                    AVAILABLE,
                    CustomAppsPerAgentKey.CustomerName:
                    customer_name,
                    CustomAppsPerAgentKey.InstallDate:
                    r.epoch_time(0.0)
                })
                apps_to_insert_per_agent(username, uri, method,
                                         agent_info_to_insert)
Beispiel #12
0
def get_all_supported_apps_for_agent(agent_id):
    agent = get_agent_info(agent_id)
    apps = (
        get_apps_data(
            table=LatestDownloadedSupportedCollection,
            os_code=agent[AgentKey.OsCode]
        )
    )
    if apps:
        update_apps = (
            IncomingSupportedOrAgentApps(
                table=SupportedAppsCollection
            )
        )
        update_apps.update_agents_with_supported(apps, [agent])
Beispiel #13
0
    def __init__(self, username, uri, method, agent_id,
                 operation_id, success, error=None):

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.success = success
        self.operation = (
            Operation(
                self.username, self.customer_name,
                self.uri, self.method
            )
        )
Beispiel #14
0
    def __init__(self,
                 username,
                 uri,
                 method,
                 agent_id,
                 operation_id,
                 success,
                 error=None):

        self.agent_id = agent_id
        self.operation_id = operation_id
        self.username = username
        self.uri = uri
        self.method = method
        self.agent_data = get_agent_info(agentid=self.agent_id)
        self.customer_name = self.agent_data['customer_name']
        self.date_now = mktime(datetime.now().timetuple())
        self.error = error
        self.success = success
        self.operation = (Operation(self.username, self.customer_name,
                                    self.uri, self.method))
    def query_by_name(self, name, conn=None):
        try:
            agent = get_agent_info(self.agent_id)
            if agent:
                base = (r.table(self.CurrentAppsPerAgentCollection).get_all(
                    self.agent_id,
                    index=self.CurrentAppsPerAgentIndexes.AgentId).eq_join(
                        self.CurrentAppsPerAgentKey.AppId,
                        r.table(self.CurrentAppsCollection)).zip())
                if self.show_hidden == NO:
                    base = base.filter({self.CurrentAppsKey.Hidden: NO})

                packages = list(
                    base.filter(lambda x: x[self.CurrentAppsKey.Name].match(
                        "(?i)" + name)).map(self.map_hash).order_by(
                            self.sort(self.sort_key)).skip(self.offset).limit(
                                self.count).run(conn))

                pkg_count = (
                    base.filter(lambda x: x[self.CurrentAppsKey.Name].match(
                        "(?i)" + name)).count().run(conn))

                return_status = (GenericResults(
                    self.username, self.uri,
                    self.method).information_retrieved(packages, pkg_count))

            else:
                return_status = (GenericResults(self.username, self.uri,
                                                self.method).invalid_id(
                                                    self.agent_id, 'agents'))

        except Exception as e:
            return_status = (GenericResults(
                self.username, self.uri,
                self.method).something_broke("Package Searching went haywire",
                                             'os_updates', e))
            logger.exception(e)

        return (return_status)
Beispiel #16
0
    def delete_agent(self, uri, method, conn=None):
        try:
            agent_info = get_agent_info(self.agent_id)
            if agent_info:
                (r.table(AgentsCollection).get(
                    self.agent_id).delete().run(conn))

                (r.table(HardwarePerAgentCollection).get_all(
                    self.agent_id,
                    index=HardwarePerAgentIndexes.AgentId).delete().run(conn))
                (r.table(TagsPerAgentCollection).get_all(
                    self.agent_id,
                    index=TagsPerAgentIndexes.AgentId).delete().run(conn))

                rv_q = Queue('delete_agent', connection=rq_pool)
                rv_q.enqueue_call(
                    func=delete_all_app_data_for_agent,
                    args=(self.agent_id, ),
                    timeout=3600,
                )
                status = (GenericResults(self.username, uri,
                                         method).object_deleted(
                                             self.agent_id, 'agents'))
                logger.info(status['message'])

            else:
                status = (GenericResults(self.username, uri,
                                         method).invalid_id(
                                             self.agent_id, 'agents'))
                logger.info(status['message'])

        except Exception as e:
            status = (GenericResults(self.username, uri,
                                     method).something_broke(
                                         self.agent_id, 'agents', e))
            logger.exception(status['message'])

        return (status)
Beispiel #17
0
    def filter_by_status(self, pkg_status, conn=None):
        try:
            agent = get_agent_info(self.agent_id)
            if agent:
                if pkg_status in ValidPackageStatuses:
                    base = (
                        r
                        .table(self.CurrentAppsPerAgentCollection, use_outdated=True)
                        .get_all(
                            [pkg_status, self.agent_id],
                            index=self.CurrentAppsPerAgentIndexes.StatusAndAgentId)
                        .eq_join(self.CurrentAppsPerAgentKey.AppId, r.table(self.CurrentAppsCollection))
                        .zip()
                    )
                    if self.show_hidden == NO:
                        base = base.filter({self.CurrentAppsKey.Hidden: NO})

                    packages = list(
                        base
                        .map(self.map_hash)
                        .order_by(self.sort(self.sort_key))
                        .skip(self.offset)
                        .limit(self.count)
                        .run(conn)
                    )

                    pkg_count = (
                        base
                        .count()
                        .run(conn)
                    )

                    return_status = (
                        GenericResults(
                            self.username, self.uri, self.method
                        ).information_retrieved(packages, pkg_count)
                    )

                else:
                    return_status = (
                        PackageResults(
                            self.username, self.uri, self.method
                        ).invalid_status(self.agent_id, pkg_status)
                    )

            else:
                return_status = (
                    GenericResults(
                        self.username, self.uri, self.method
                    ).invalid_id(self.agent_id, 'agents')
                )

        except Exception as e:
            return_status = (
                GenericResults(
                    self.username, self.uri, self.method
                ).something_broke(
                    "Package Searching went haywire",
                    'os_updates', e
                    )
            )
            logger.exception(e)

        return(return_status)