mirror of
https://github.com/alerta/alerta.git
synced 2025-01-23 00:40:19 +00:00
This reverts commit 4664cd2d88
.
This commit is contained in:
parent
e10287142f
commit
d50131b9e6
4 changed files with 8 additions and 34 deletions
|
@ -632,14 +632,14 @@ class Backend(Database):
|
|||
|
||||
# ENVIRONMENTS
|
||||
|
||||
def get_environments(self, query=None, page=None, page_size=None):
|
||||
def get_environments(self, query=None, topn=1000):
|
||||
query = query or Query()
|
||||
select = f"""
|
||||
SELECT environment, severity, status, count(1) FROM alerts
|
||||
WHERE {query.where}
|
||||
GROUP BY environment, CUBE(severity, status)
|
||||
"""
|
||||
result = self._fetchall(select, query.vars, limit=page_size)
|
||||
result = self._fetchall(select, query.vars, limit=topn)
|
||||
|
||||
severity_count = defaultdict(list)
|
||||
status_count = defaultdict(list)
|
||||
|
@ -654,7 +654,7 @@ class Backend(Database):
|
|||
total_count[row.environment] = row.count
|
||||
|
||||
select = """SELECT DISTINCT environment FROM alerts"""
|
||||
environments = self._fetchall(select, {}, limit=page_size, offset=(page - 1) * page_size)
|
||||
environments = self._fetchall(select, {})
|
||||
return [
|
||||
{
|
||||
'environment': e.environment,
|
||||
|
@ -663,14 +663,6 @@ class Backend(Database):
|
|||
'count': total_count[e.environment]
|
||||
} for e in environments]
|
||||
|
||||
def get_environments_count(self, query=None):
|
||||
query = query or Query()
|
||||
select = """
|
||||
SELECT COUNT(DISTINCT environment) FROM alerts
|
||||
WHERE {where}
|
||||
""".format(where=query.where)
|
||||
return self._fetchone(select, query.vars).count
|
||||
|
||||
# SERVICES
|
||||
|
||||
def get_services(self, query=None, topn=1000):
|
||||
|
|
|
@ -204,10 +204,7 @@ class Database(Base):
|
|||
|
||||
# ENVIRONMENTS
|
||||
|
||||
def get_environments(self, query=None, page=1, page_size=100):
|
||||
raise NotImplementedError
|
||||
|
||||
def get_environments_count(query: Query = None) -> int:
|
||||
def get_environments(self, query=None, topn=1000):
|
||||
raise NotImplementedError
|
||||
|
||||
# SERVICES
|
||||
|
|
|
@ -542,12 +542,8 @@ class Alert:
|
|||
|
||||
# get environments
|
||||
@staticmethod
|
||||
def get_environments(query: Query = None, page: int = 1, page_size: int = 100) -> List[str]:
|
||||
return db.get_environments(query, page, page_size)
|
||||
|
||||
@staticmethod
|
||||
def get_environments_count(query: Query = None) -> int:
|
||||
return db.get_environments_count(query)
|
||||
def get_environments(query: Query = None) -> List[str]:
|
||||
return db.get_environments(query)
|
||||
|
||||
# get services
|
||||
@staticmethod
|
||||
|
|
|
@ -480,30 +480,19 @@ def get_topn_standing():
|
|||
@jsonp
|
||||
def get_environments():
|
||||
query = qb.alerts.from_params(request.args, customers=g.customers)
|
||||
total = Alert.get_environments_count(query)
|
||||
paging = Page.from_params(request.args, total)
|
||||
environments = Alert.get_environments(query, page=paging.page, page_size=paging.page_size)
|
||||
environments = Alert.get_environments(query)
|
||||
|
||||
if environments:
|
||||
return jsonify(
|
||||
status='ok',
|
||||
environments=environments,
|
||||
page=paging.page,
|
||||
pageSize=paging.page_size,
|
||||
pages=paging.pages,
|
||||
more=paging.has_more,
|
||||
total=total
|
||||
|
||||
total=len(environments)
|
||||
)
|
||||
else:
|
||||
return jsonify(
|
||||
status='ok',
|
||||
message='not found',
|
||||
environments=[],
|
||||
page=paging.page,
|
||||
pageSize=paging.page_size,
|
||||
pages=paging.pages,
|
||||
more=paging.has_more,
|
||||
total=0
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue