Exemple #1
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: [AVAILABLE, x[AppsPerAgentKey.AgentId]],
                r.table(AppsPerAgentCollection),
                index=AppsPerAgentIndexes.StatusAndAgentId,
            )
            .zip()
            .eq_join(AgentKey.AgentId, r.table(AgentsCollection))
            .zip()
            .pluck(APP_ID, AgentKey.OsString)
            .distinct()
            .group_by(AgentKey.OsString, r.count)
            .order_by(r.desc("reduction"))
            .limit(count)
            .run(conn)
        )

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

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

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

    return results
Exemple #2
0
def customer_stats_by_os(username, customer_name, uri, method, count=3, conn=None):
    try:
        stats = (
            r.table(AppsPerAgentCollection, use_outdated=True)
            .get_all([AVAILABLE, customer_name], index=AppsPerAgentIndexes.StatusAndCustomer)
            .eq_join(AgentKey.AgentId, r.table(AgentsCollection))
            .map({AppsKey.AppId: r.row["left"][AppsKey.AppId], AgentKey.OsString: r.row["right"][AgentKey.OsString]})
            .pluck(AppsKey.AppId, AgentKey.OsString)
            .distinct()
            .group_by(AgentKey.OsString, r.count)
            .order_by(r.desc("reduction"))
            .limit(count)
            .run(conn)
        )

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

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

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

    return results
Exemple #3
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: [AVAILABLE, x[AppsPerAgentKey.AgentId]],
                r.table(AppsPerAgentCollection),
                index=AppsPerAgentIndexes.StatusAndAgentId,
            )
            .map({AppsKey.AppId: r.row["right"][AppsKey.AppId]})
            .eq_join(AppsKey.AppId, r.table(AppsCollection))
            .map({AppsKey.AppId: r.row["right"][AppsKey.AppId], AppsKey.RvSeverity: r.row["right"][AppsKey.RvSeverity]})
            .group_by(AppsKey.RvSeverity, r.count)
            .order_by(r.desc("reduction"))
            .run(conn)
        )
        data = app_stats_by_severity(sevs)

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

    except Exception as e:
        results = GenericResults(username, uri, method).something_broke("widget severity stats", "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: [
                    AVAILABLE,
                    x[AppsPerAgentKey.AgentId]
                ],
                r.table(AppsPerAgentCollection),
                index=AppsPerAgentIndexes.StatusAndAgentId
            )
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                }
            )
            .eq_join(AppsKey.AppId, r.table(AppsCollection))
            .map(
                {
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: r.row['right'][AppsKey.RvSeverity]
                }
            )
            .group_by(AppsKey.RvSeverity, r.count)
            .order_by(r.desc('reduction'))
            .run(conn)
        )
        data = app_stats_by_severity(sevs)

        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(data, len(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 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: [
                    AVAILABLE,
                    x[AppsPerAgentKey.AgentId]
                ],
                r.table(AppsPerAgentCollection),
                index=AppsPerAgentIndexes.StatusAndAgentId
            )
            .zip()
            .eq_join(AgentKey.AgentId, r.table(AgentsCollection))
            .zip()
            .pluck(APP_ID, AgentKey.OsString)
            .distinct()
            .group_by(AgentKey.OsString, r.count)
            .order_by(r.desc('reduction'))
            .limit(count)
            .run(conn)
        )

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

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

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

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

    apps_needed = []

    try:
        appid_needed = (
            r.table(AppsPerAgentCollection)
            .get_all([AVAILABLE, customer_name], index=AppsPerAgentIndexes.StatusAndCustomer)
            .group_by(AppsPerAgentKey.AppId, r.count)
            .order_by(r.desc("reduction"))
            .run(conn)
        )

        for i in xrange(len(appid_needed)):
            app_info = (
                r.table(AppsCollection)
                .get_all(appid_needed[i]["group"][AppsPerAgentKey.AppId], index=AppsIndexes.AppId)
                .pluck(AppsKey.Name, AppsKey.AppId, AppsKey.RvSeverity, AppsKey.ReleaseDate, AppsKey.Hidden)
                .map(
                    {
                        AppsKey.Name: r.row[AppsKey.Name],
                        AppsKey.AppId: r.row[AppsKey.AppId],
                        AppsKey.Hidden: r.row[AppsKey.Hidden],
                        AppsKey.RvSeverity: r.row[AppsKey.RvSeverity],
                        AppsKey.ReleaseDate: r.row[AppsKey.ReleaseDate].to_epoch_time(),
                        "count": appid_needed[i]["reduction"],
                    }
                )
                .run(conn)[0]
            )

            if app_info[AppsKey.Hidden] == "no":
                apps_needed.append(app_info)

            if len(apps_needed) == count:
                break

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

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

    return results
Exemple #7
0
def customer_stats_by_os(username, customer_name,
                         uri, method, count=3, conn=None):
    try:
        stats = (
            r
            .table(AppsPerAgentCollection, use_outdated=True)
            .get_all(
                [AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer
            )
            .eq_join(AgentKey.AgentId, r.table(AgentsCollection))
            .map(
                {
                    AppsKey.AppId: r.row['left'][AppsKey.AppId],
                    AgentKey.OsString: r.row['right'][AgentKey.OsString]
                }
            )
            .pluck(AppsKey.AppId, AgentKey.OsString)
            .distinct()
            .group_by(AgentKey.OsString, r.count)
            .order_by(r.desc('reduction'))
            .limit(count)
            .run(conn)
        )

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

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

    except Exception as e:
        results = (
            GenericResults(
                username, uri, method
            ).something_broke('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):

    app_needed = []

    try:
        data = list(
            r.table(AppsPerAgentCollection, use_outdated=True)
            .get_all([AVAILABLE, customer_name], index=AppsPerAgentIndexes.StatusAndCustomer)
            .eq_join(AppsKey.AppId, r.table(AppsCollection))
            .map(
                {
                    AppsKey.Name: r.row["right"][AppsKey.Name],
                    AppsKey.AppId: r.row["right"][AppsKey.AppId],
                    AppsKey.RvSeverity: r.row["right"][AppsKey.RvSeverity],
                    AppsKey.Hidden: r.row["right"][AppsKey.Hidden],
                    AppsKey.ReleaseDate: r.row["right"][AppsKey.ReleaseDate].to_epoch_time(),
                    "count": (
                        r.table(AppsPerAgentCollection)
                        .get_all([r.row["right"][AppsKey.AppId], AVAILABLE], index=AppsPerAgentIndexes.AppIdAndStatus)
                        .count()
                    ),
                }
            )
            .pluck(AppsKey.Name, AppsKey.AppId, AppsKey.Hidden, AppsKey.RvSeverity, AppsKey.ReleaseDate, "count")
            .order_by(r.desc(AppsKey.ReleaseDate))
            .run(conn)
        )

        for i in xrange(len(data)):
            if data[i][AppsKey.Hidden] == "no":
                app_needed.append(data[i])
            if len(app_needed) == count:
                break

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

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

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

    app_needed=[]

    try:
        data = list(
            r
            .table(AppsPerAgentCollection, use_outdated=True)
            .get_all(
                [
                    AVAILABLE, customer_name
                ],
                index=AppsPerAgentIndexes.StatusAndCustomer
            )
            .eq_join(AppsKey.AppId, r.table(AppsCollection))
            .map(
                {
                    AppsKey.Name: r.row['right'][AppsKey.Name],
                    AppsKey.AppId: r.row['right'][AppsKey.AppId],
                    AppsKey.RvSeverity: r.row['right'][AppsKey.RvSeverity],
                    AppsKey.Hidden: r.row['right'][AppsKey.Hidden],
                    AppsKey.ReleaseDate: r.row['right'][AppsKey.ReleaseDate].to_epoch_time(),
                    'count': (
                        r
                        .table(AppsPerAgentCollection)
                        .get_all(
                            [r.row['right'][AppsKey.AppId], AVAILABLE],
                            index=AppsPerAgentIndexes.AppIdAndStatus
                        )
                        .count()
                    )
                }
            )
            .pluck(
                AppsKey.Name, AppsKey.AppId,AppsKey.Hidden,
                AppsKey.RvSeverity, AppsKey.ReleaseDate, 'count'
            )
            .order_by(r.desc(AppsKey.ReleaseDate))
            .run(conn)
        )

        for i in xrange(len(data)):
            if data[i][AppsKey.Hidden] == 'no':
                app_needed.append(data[i])
            if len(app_needed) == count:
                break;
                
        
        results = (
            GenericResults(
                username, uri, method
            ).information_retrieved(app_needed, count)
        )

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

    return(results)
Exemple #10
0
def top_packages_needed(username, customer_name,
                        uri, method, count=5, conn=None):
    
    apps_needed=[]
    
    try:
        appid_needed = (
            r
            .table(AppsPerAgentCollection)
            .get_all(
                [AVAILABLE, customer_name],
                index=AppsPerAgentIndexes.StatusAndCustomer
            )
            .group_by(AppsPerAgentKey.AppId, r.count)
            .order_by(r.desc('reduction'))
            .run(conn)
        )

        for i in xrange(len(appid_needed)):
            app_info = (
                r
                .table(AppsCollection)
                .get_all(
                    appid_needed[i]['group'][AppsPerAgentKey.AppId],
                    index=AppsIndexes.AppId)
                .pluck(
                    AppsKey.Name, AppsKey.AppId,
                    AppsKey.RvSeverity, AppsKey.ReleaseDate,
                    AppsKey.Hidden,
                )
                .map(
                    {
                        AppsKey.Name: r.row[AppsKey.Name],
                        AppsKey.AppId: r.row[AppsKey.AppId],
                        AppsKey.Hidden: r.row[AppsKey.Hidden],
                        AppsKey.RvSeverity: r.row[AppsKey.RvSeverity],
                        AppsKey.ReleaseDate: r.row[AppsKey.ReleaseDate].to_epoch_time(),
                        'count': appid_needed[i]['reduction']
                    }
                )
                .run(conn)[0]
            )

            if app_info[AppsKey.Hidden] == 'no':
                apps_needed.append(app_info)

            if len(apps_needed) == count:
                break;

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

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

    return(results)