Exemple #1
0
def top_packages_needed(username, customer_name,
                        uri, method, count=5, conn=None):
    
    apps_needed=[]
    
    try:
        data = (
            r
            .table(AppCollections.AppsPerAgent)
            .get_all(
                [CommonAppKeys.AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer
            )
            .eq_join(AppsKey.AppId, r.table(AppCollections.UniqueApplications))
            .filter(
                lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO
            )
            .map(
                lambda x:
                {
                    AppsKey.Name: x['right'][AppsKey.Name],
                    AppsKey.AppId: x['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: x['right'][AppsKey.RvSeverity],
                    AppsKey.ReleaseDate: x['right'][AppsKey.ReleaseDate].to_epoch_time(),
                }
            )
            .group(AppsKey.Name, AppsKey.AppId, AppsKey.RvSeverity, AppsKey.ReleaseDate)
            .count()
            .ungroup()
            .map(
                lambda x:
                {
                    AppsKey.Name: x['group'][0],
                    AppsKey.AppId: x['group'][1],
                    AppsKey.RvSeverity: x['group'][2],
                    AppsKey.ReleaseDate: x['group'][3],
                    'count': x['reduction'],
                }
            )
            .order_by(r.desc('count'), r.desc(AppsKey.ReleaseDate))
            .limit(count)
            .run(conn)
        )

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, count)
        )

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('top os apps needed', 'widget', e)
        )
        logger.exception(results)

    return(results)
Exemple #2
0
def get_severity_bar_chart_stats_for_tag(username,
                                         customer_name,
                                         uri,
                                         method,
                                         tag_id,
                                         conn=None):
    try:
        sevs = (r.table(TagsPerAgentCollection, use_outdated=True).get_all(
            tag_id, index=TagsPerAgentIndexes.TagId
        ).pluck(TagsPerAgentKey.AgentId).eq_join(
            lambda x: [CommonAppKeys.AVAILABLE, x[AppsPerAgentKey.AgentId]],
            r.table(AppCollections.AppsPerAgent),
            index=AppsPerAgentIndexes.StatusAndAgentId).map({
                AppsKey.AppId:
                r.row['right'][AppsKey.AppId],
            }).eq_join(AppsKey.AppId, r.table(
                AppCollections.UniqueApplications)).filter(lambda x: x[
                    'right'][AppsKey.Hidden] == CommonKeys.NO).map({
                        AppsKey.AppId:
                        r.row['right'][AppsKey.AppId],
                        AppsKey.RvSeverity:
                        r.row['right'][AppsKey.RvSeverity]
                    }).group(AppsKey.RvSeverity).count().ungroup().order_by(
                        r.desc('reduction')).run(conn))
        data = app_stats_by_severity(sevs)

        results = (GenericResults(username, uri, method).information_retrieved(
            data, len(CommonSeverityKeys.ValidRvSeverities)))

    except Exception as e:
        results = (GenericResults(username, uri, method).something_broke(
            'widget severity stats', 'widget', e))
        logger.exception(results)

    return (results)
Exemple #3
0
def top_packages_needed(username,
                        customer_name,
                        uri,
                        method,
                        count=5,
                        conn=None):

    apps_needed = []

    try:
        data = (
            r.table(AppCollections.AppsPerAgent).get_all(
                [CommonAppKeys.AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer).eq_join(
                    AppsKey.AppId, r.table(AppCollections.UniqueApplications)).
            filter(lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO).map(
                lambda x: {
                    AppsKey.Name:
                    x['right'][AppsKey.Name],
                    AppsKey.AppId:
                    x['right'][AppsKey.AppId],
                    AppsKey.RvSeverity:
                    x['right'][AppsKey.RvSeverity],
                    AppsKey.ReleaseDate:
                    x['right'][AppsKey.ReleaseDate].to_epoch_time(),
                }).group(
                    AppsKey.Name, AppsKey.AppId, AppsKey.RvSeverity,
                    AppsKey.ReleaseDate).count().ungroup().map(
                        lambda x: {
                            AppsKey.Name: x['group'][0],
                            AppsKey.AppId: x['group'][1],
                            AppsKey.RvSeverity: x['group'][2],
                            AppsKey.ReleaseDate: x['group'][3],
                            'count': x['reduction'],
                        }).order_by(r.desc('count'), r.desc(
                            AppsKey.ReleaseDate)).limit(count).run(conn))

        results = (GenericResults(username, uri,
                                  method).information_retrieved(data, count))

    except Exception as e:
        results = (GenericResults(username, uri, method).something_broke(
            'top os apps needed', 'widget', e))
        logger.exception(results)

    return (results)
Exemple #4
0
def get_severity_bar_chart_stats_for_tag(username, customer_name,
                                         uri, method, tag_id, conn=None):
    try:
        sevs = (
            r
            .table(TagsPerAgentCollection, use_outdated=True)
            .get_all(tag_id, index=TagsPerAgentIndexes.TagId)
            .pluck(TagsPerAgentKey.AgentId)
            .eq_join(
                lambda x: [
                    CommonAppKeys.AVAILABLE,
                    x[AppsPerAgentKey.AgentId]
                ],
                r.table(AppCollections.AppsPerAgent),
                index=AppsPerAgentIndexes.StatusAndAgentId
            )
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                }
            )
            .eq_join(AppsKey.AppId, r.table(AppCollections.UniqueApplications))
            .filter(
                lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO
            )
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: r.row['right'][AppsKey.RvSeverity]
                }
            )
            .group(AppsKey.RvSeverity)
            .count()
            .ungroup()
            .order_by(r.desc('reduction'))
            .run(conn)
        )
        data = app_stats_by_severity(sevs)

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, len(CommonSeverityKeys.ValidRvSeverities))
        )

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('widget severity stats', 'widget', e)
        )
        logger.exception(results)

    return(results)
Exemple #5
0
def recently_released_packages(username,
                               customer_name,
                               uri,
                               method,
                               count=5,
                               conn=None):

    data = []

    try:
        data = list(
            r.table(AppCollections.AppsPerAgent, use_outdated=True).get_all(
                [CommonAppKeys.AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer).eq_join(
                    AppsKey.AppId, r.table(AppCollections.UniqueApplications)).
            map(
                lambda x: {
                    AppsKey.Name:
                    x['right'][AppsKey.Name],
                    AppsKey.AppId:
                    x['right'][AppsKey.AppId],
                    AppsKey.RvSeverity:
                    x['right'][AppsKey.RvSeverity],
                    AppsKey.Hidden:
                    x['right'][AppsKey.Hidden],
                    AppsKey.ReleaseDate:
                    x['right'][AppsKey.ReleaseDate].to_epoch_time(),
                    'count': (r.table(AppCollections.AppsPerAgent).get_all(
                        [x['right'][AppsKey.AppId], CommonAppKeys.AVAILABLE],
                        index=AppsPerAgentIndexes.AppIdAndStatus).eq_join(
                            AppsKey.AppId,
                            r.table(AppCollections.UniqueApplications)).
                              filter(lambda y: y['right'][AppsKey.Hidden] ==
                                     CommonKeys.NO).count())
                }).pluck(AppsKey.Name, AppsKey.AppId, AppsKey.Hidden,
                         AppsKey.RvSeverity, AppsKey.ReleaseDate,
                         'count').order_by(r.desc(
                             AppsKey.ReleaseDate)).limit(count).run(conn))

        results = (GenericResults(username, uri,
                                  method).information_retrieved(data, count))

    except Exception as e:
        results = (GenericResults(username, uri, method).something_broke(
            'recently released os apps', 'widget', e))
        logger.exception(results)

    return (results)
Exemple #6
0
def customer_stats_by_os(username,
                         customer_name,
                         uri,
                         method,
                         count=3,
                         conn=None):
    try:
        stats = (
            r.table(AppCollections.AppsPerAgent, use_outdated=True).get_all(
                [CommonAppKeys.AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer).eq_join(
                    AppsKey.AppId, r.table(AppCollections.UniqueApplications)).
            filter(lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO).map({
                AppsPerAgentKey.AppId:
                r.row['left'][AppsPerAgentKey.AppId],
                AppsPerAgentKey.AgentId:
                r.row['left'][AppsPerAgentKey.AgentId],
            }).eq_join(AgentKey.AgentId, r.table(AgentCollections.Agents)).map(
                {
                    AppsKey.AppId: r.row['left'][AppsKey.AppId],
                    AgentKey.OsString: r.row['right'][AgentKey.OsString]
                }).pluck(AppsKey.AppId,
                         AgentKey.OsString).distinct().group(
                             AgentKey.OsString).count().ungroup().map(
                                 lambda x: {
                                     'os': x['group'],
                                     'count': x['reduction']
                                 }).order_by(
                                     r.desc('count')).limit(count).run(conn))
        data = []
        #if stats:
        #    data = app_stats_by_os(stats)

        results = (GenericResults(username, uri,
                                  method).information_retrieved(stats, count))

    except Exception as e:
        results = (GenericResults(username, uri, method).something_broke(
            'widget stats', 'widget', e))
        logger.exception(results)

    return (results)
Exemple #7
0
def tag_stats_by_os(username, customer_name,
                    uri, method, tag_id,
                    count=3, conn=None):
    try:
        stats = (
            r
            .table(TagsPerAgentCollection, use_outdated=True)
            .get_all(tag_id, index=TagsPerAgentIndexes.TagId)
            .pluck(TagsPerAgentKey.AgentId)
            .eq_join(
                lambda x: [
                    CommonAppKeys.AVAILABLE,
                    x[AppsPerAgentKey.AgentId]
                ],
                r.table(AppCollections.AppsPerAgent),
                index=AppsPerAgentIndexes.StatusAndAgentId
            )
            .zip()
            .eq_join(AgentKey.AgentId, r.table(AgentCollections.Agents))
            .zip()
            .eq_join(AppsPerAgentKey.AppId, r.table(AppCollections.UniqueApplications))
            .filter(
                lambda x: x['right'][AppsKey.Hidden] == CommonKeys.NO
            )
            .zip()
            .pluck(CommonAppKeys.APP_ID, AgentKey.OsString)
            .distinct()
            .group(AgentKey.OsString)
            .count()
            .ungroup()
            .map(
                lambda x:
                {
                    'os': x['group'],
                    'count': x['reduction']
                }
            )
            .order_by(r.desc('count'))
            .limit(count)
            .run(conn)
        )

        #data = []
        #if stats:
        #    data = app_stats_by_os(stats)

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(stats, count)
        )

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('tag widget stats', 'widget', e)
        )
        logger.exception(results)

    return(results)
Exemple #8
0
def recently_released_packages(username, customer_name,
                               uri, method, count=5, conn=None):

    data=[]

    try:
        data = list(
            r
            .table(AppCollections.AppsPerAgent, use_outdated=True)
            .get_all(
                [
                    CommonAppKeys.AVAILABLE, customer_name
                ],
                index=AppsPerAgentIndexes.StatusAndCustomer
            )
            .eq_join(AppsKey.AppId, r.table(AppCollections.UniqueApplications))
            .map(
                lambda x:
                {
                    AppsKey.Name: x['right'][AppsKey.Name],
                    AppsKey.AppId: x['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: x['right'][AppsKey.RvSeverity],
                    AppsKey.Hidden: x['right'][AppsKey.Hidden],
                    AppsKey.ReleaseDate: x['right'][AppsKey.ReleaseDate].to_epoch_time(),
                    'count': (
                        r
                        .table(AppCollections.AppsPerAgent)
                        .get_all(
                            [x['right'][AppsKey.AppId], CommonAppKeys.AVAILABLE],
                            index=AppsPerAgentIndexes.AppIdAndStatus
                        )
                        .eq_join(AppsKey.AppId, r.table(AppCollections.UniqueApplications))
                        .filter(
                            lambda y: y['right'][AppsKey.Hidden] == CommonKeys.NO
                        )
                        .count()
                    )
                }
            )
            .pluck(
                AppsKey.Name, AppsKey.AppId,AppsKey.Hidden,
                AppsKey.RvSeverity, AppsKey.ReleaseDate, 'count'
            )
            .order_by(r.desc(AppsKey.ReleaseDate))
            .limit(count)
            .run(conn)
        )

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, count)
        )

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('recently released os apps', 'widget', e)
        )
        logger.exception(results)

    return(results)