def get_severity_bar_chart_stats_for_customer(username, customer_name, uri, method, conn=None): try: sevs = ( r.table(AppCollections.AppsPerAgent, use_outdated=True).get_all( [CommonAppKeys.AVAILABLE, customer_name], index=AppsPerAgentIndexes.StatusAndCustomer).pluck( AppsKey.AppId).distinct().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.asc('group')).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)
def get_severity_bar_chart_stats_for_customer(username, customer_name, uri, method, conn=None): try: sevs = ( r .table(AppCollections.AppsPerAgent, use_outdated=True) .get_all( [CommonAppKeys.AVAILABLE, customer_name], index=AppsPerAgentIndexes.StatusAndCustomer ) .pluck(AppsKey.AppId) .distinct() .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.asc('group')) .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)
def filter_by_status_and_sev(self, pkg_status, sev, conn=None): try: pkg = ( r .table(self.CurrentAppsCollection, use_outdated=True) .get(self.app_id) .run(conn) ) if pkg: if pkg_status in CommonAppKeys.ValidPackageStatuses: if sev in CommonSeverityKeys.ValidRvSeverities: agents = list( r .table(self.CurrentAppsPerAgentCollection) .get_all( [self.app_id, pkg_status], index=self.CurrentAppsPerAgentIndexes.AppIdAndStatus ) .eq_join( self.CurrentAppsPerAgentKey.AppId, r.table(self.CurrentAppsCollection) ) .zip() .eq_join( self.CurrentAppsPerAgentKey.AgentId, r.table(AgentsCollection) ) .zip() .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev) .order_by(r.asc(self.CurrentAppsKey.Name)) .skip(self.offset) .limit(self.count) .map(self.map_hash) .run(conn) ) agent_count = ( r .table(self.CurrentAppsPerAgentCollection) .get_all( [self.app_id, pkg_status], index=self.CurrentAppsPerAgentIndexes.AppIdAndStatus ) .eq_join( self.CurrentAppsPerAgentKey.AppId, r.table(self.CurrentAppsCollection) ) .zip() .filter(r.row[self.CurrentAppsKey.RvSeverity] == sev) .count() .run(conn) ) return_status = ( GenericResults( self.username, self.uri, self.method ).information_retrieved(agents, agent_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.app_id, pkg_status) ) else: return_status = ( GenericResults( self.username, self.uri, self.method ).invalid_id(self.app_id, 'os_apps') ) 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)
def query_by_name(self, name, conn=None): try: pkg = ( r .table(self.CurrentAppsCollection, use_outdated=True) .get(self.app_id) .run(conn) ) if pkg: agents = list( r .table(self.CurrentAppsPerAgentCollection) .get_all(self.app_id, index=self.CurrentAppsPerAgentIndexes.AppId) .eq_join( self.CurrentAppsPerAgentKey.AgentId, r.table(AgentsCollection) ) .zip() .filter( r.row[AgentKey.ComputerName].match("(?i)"+name) | r.row[AgentKey.DisplayName].match("(?i)"+name) ) .order_by(r.asc('computer_name')) .skip(self.offset) .limit(self.count) .map(self.map_hash) .run(conn) ) agent_count = ( r .table(self.CurrentAppsPerAgentCollection, use_outdated=True) .get_all(self.app_id, index=self.CurrentAppsPerAgentIndexes.AppId) .eq_join( self.CurrentAppsPerAgentKey.AgentId, r.table(AgentsCollection) ) .zip() .filter( r.row[AgentKey.ComputerName].match("(?i)"+name) | r.row[AgentKey.DisplayName].match("(?i)"+name) ) .count() .run(conn) ) return_status = ( GenericResults( self.username, self.uri, self.method ).information_retrieved(agents, agent_count) ) else: return_status = ( PackageResults( self.username, self.uri, self.method ).invalid_package_id(self.app_id) ) 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)