mirror of
https://github.com/FAUSheppy/icinga-webhook-gateway
synced 2026-04-26 14:12:29 +02:00
feat: group identical reports
This commit is contained in:
44
server.py
44
server.py
@@ -39,6 +39,21 @@ app.config['TIME_ZONE'] = zoneinfo.ZoneInfo(os.getenv("TIME_ZONE", "UTC"))
|
||||
app.config['AUTH_HEADER'] = os.environ.get("AUTH_HEADER") or "X-Forwarded-Preferred-Username"
|
||||
db = SQLAlchemy(app)
|
||||
|
||||
from urllib.parse import urlparse
|
||||
|
||||
def split_url(url: str):
|
||||
parsed = urlparse(url)
|
||||
|
||||
http_vhost = parsed.hostname
|
||||
http_uri = parsed.path or "/"
|
||||
http_ssl = parsed.scheme == "https"
|
||||
|
||||
return {
|
||||
"http_vhost": http_vhost,
|
||||
"http_uri": http_uri,
|
||||
"http_ssl": http_ssl
|
||||
}
|
||||
|
||||
class Service(db.Model):
|
||||
|
||||
__tablename__ = "services"
|
||||
@@ -49,6 +64,11 @@ class Service(db.Model):
|
||||
owner = Column(String)
|
||||
special_type = Column(String)
|
||||
|
||||
# web checks #
|
||||
url = Column(String)
|
||||
accepted_codes = Column(String)
|
||||
http_expect = Column(String)
|
||||
|
||||
staticly_configured = Column(Boolean)
|
||||
|
||||
class Status(db.Model):
|
||||
@@ -179,8 +199,28 @@ def service_details():
|
||||
return ("Services is not owned by {}".format(user))
|
||||
|
||||
status_list_query = db.session.query(Status).filter(Status.service==service.service)
|
||||
status_list = status_list_query.order_by(sqlalchemy.desc(Status.timestamp)).limit(20).all()
|
||||
status_list = status_list_query.order_by(sqlalchemy.desc(Status.timestamp)).limit(200).all()
|
||||
|
||||
# build status tupel (repeats, status) #
|
||||
current_tupel = None
|
||||
prev_status = None
|
||||
tupel_list = []
|
||||
for s in status_list:
|
||||
|
||||
# set initial #
|
||||
if not current_tupel:
|
||||
current_tupel = [1, s]
|
||||
tupel_list.append(current_tupel)
|
||||
continue
|
||||
|
||||
if current_tupel[1].info_text == s.info_text:
|
||||
current_tupel[0] += 1
|
||||
else:
|
||||
current_tupel = [1, s]
|
||||
tupel_list.append(current_tupel)
|
||||
|
||||
|
||||
print(tupel_list)
|
||||
icinga_link = icingatools.build_icinga_link_for_service(user, service.service,
|
||||
service.staticly_configured, app)
|
||||
|
||||
@@ -188,7 +228,7 @@ def service_details():
|
||||
smart_entry = smart_entry_list.order_by(SMARTStatus.timestamp.desc()).first()
|
||||
|
||||
return flask.render_template("service_info.html", service=service, flask=flask,
|
||||
user=user, status_list=status_list, icinga_link=icinga_link, smart=smart_entry)
|
||||
user=user, status_list=tupel_list, icinga_link=icinga_link, smart=smart_entry)
|
||||
|
||||
|
||||
@app.route("/entry-form", methods=["GET", "POST", "DELETE"])
|
||||
|
||||
@@ -56,8 +56,8 @@
|
||||
|
||||
<div class="last-status">
|
||||
{% if status_list | length > 0 %}
|
||||
<p class="{{ status_list[0].status }}">
|
||||
{{ status_list[0].status }} submitted on {{ status_list[0].human_date() }}
|
||||
<p class="{{ status_list[0][1].status }}">
|
||||
{{ status_list[0][1].status }} submitted on {{ status_list[0][1].human_date() }}
|
||||
</p>
|
||||
{% else %}
|
||||
<p style="color: darkred;">No status for this service submitted</p>
|
||||
@@ -169,12 +169,19 @@
|
||||
</thead>
|
||||
|
||||
<tbody class="mt-2">
|
||||
{% for status in status_list %}
|
||||
{% for status_tupel in status_list %}
|
||||
<tr>
|
||||
<td>{{ status.human_date() }}</td>
|
||||
<td class="{{ status.status }}">{{ status.status }}</td>
|
||||
<td>{{ status.info_text }}</td>
|
||||
<td>{{ status_tupel[1].human_date() }}</td>
|
||||
<td class="{{ status_tupel[1].status }}">{{ status_tupel[1].status }}</td>
|
||||
<td>{{ status_tupel[1].info_text }}</td>
|
||||
</tr>
|
||||
{% if status_tupel[0] > 1 %}
|
||||
<tr>
|
||||
<td>---</td>
|
||||
<td><i> + {{ status_tupel[0] }} identical reports</i></td>
|
||||
<td>|</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user