Skip to content

Commit

Permalink
Merge branch 'master' into bugfix/validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern authored Oct 1, 2019
2 parents e9371f5 + 39dfdd1 commit 92435e6
Show file tree
Hide file tree
Showing 16 changed files with 607 additions and 507 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Silverback Lite CI

on: [push]

jobs:
build:
runs-on: ubuntu-16.04
strategy:
max-parallel: 4
matrix:
python-version: [3.6, 3.7]
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
- name: Run make liteci
run: |
sudo apt-get install libmysqlclient-dev libpq-dev python-dev
make liteci
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
FROM python:3.7

FROM python:3.7 as silverback-stage-1
MAINTAINER [email protected]
ENV PYTHONUNBUFFERED 1

ARG VERSION=master

RUN mkdir /app

COPY . /app

WORKDIR /app

RUN pip install -r requirements.txt
RUN echo "yes" | python manage.py collectstatic

EXPOSE 8000

CMD ["gunicorn" , "-b", "0.0.0.0:8000", "app.wsgi"]
FROM silverback-stage-1 as silverback-stage-2
WORKDIR /app
EXPOSE 8000
CMD ["gunicorn" , "-b", "0.0.0.0:8000", "app.wsgi"]
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<p align="center">
<a href="https://travis-ci.org/silverbackhq/Silverback"><img src="https://travis-ci.org/silverbackhq/Silverback.svg?branch=master"></a>
<a href='https://coveralls.io/github/silverbackhq/silverback?branch=master'><img src='https://coveralls.io/repos/github/silverbackhq/silverback/badge.svg?branch=master' alt='Coverage Status' /></a>
<a href="https://hub.docker.com/r/clivern/silverback"><img src="https://img.shields.io/badge/Docker-Latest-orange"></a>
<a href="https://github.com/silverbackhq/Silverback/releases"><img src="https://img.shields.io/badge/Version-v1.0.0--alpha.1-blue.svg"></a>
<a href="https://github.com/silverbackhq/Silverback/blob/master/LICENSE"><img src="https://img.shields.io/badge/LICENSE-BSD%203--Clause%20-orange.svg"></a>
</p>
Expand Down
2 changes: 2 additions & 0 deletions app/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# Local Library
from app.modules.entity.option_entity import OptionEntity
from app.modules.core.constants import Constants


def globals(request):
Expand All @@ -27,4 +28,5 @@ def globals(request):
"google_account": option_entity.get_value_by_key("google_analytics_account", ""),
"app_timezone": os.getenv("APP_TIMEZONE", "UTC"),
"activate_notifications": os.getenv("ACTIVATE_NOTIFICATIONS", "false") == "true",
"constants": Constants(),
}
12 changes: 9 additions & 3 deletions app/controllers/api/private/v1/admin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def post(self, request):
"metric_id": ""
})

if request_data["metric_id"] == "" or not self.__metric.get_one_by_id(request_data["metric_id"]):
if request_data["metric_id"] == "" or not self.__metric.get_one_by_id(request_data["metric_id"].replace("m-", "")):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Metric is required.")
Expand Down Expand Up @@ -155,13 +155,19 @@ def post(self, request):
"component_id": ""
})

if request_data["component_id"] == "":
if request_data["component_id"] == "" or ("c-" not in request_data["component_id"] and "g-" not in request_data["component_id"]):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Compnent or compnent group is required.")
}], {}, self.__correlation_id))

if not self.__component.get_one_by_id(request_data["component_id"]) and not self.__component_group.get_one_by_id(request_data["component_id"]):
if "c-" in request_data["component_id"] and not self.__component.get_one_by_id(request_data["component_id"].replace("c-", "")):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Compnent or compnent group is required.")
}], {}, self.__correlation_id))

if "g-" in request_data["component_id"] and not self.__component_group.get_one_by_id(request_data["component_id"].replace("g-", "")):
return JsonResponse(self.__response.send_private_failure([{
"type": "error",
"message": _("Error! Compnent or compnent group is required.")
Expand Down
22 changes: 22 additions & 0 deletions app/modules/core/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
Constants Module
"""


class Constants():

INCIDENT_UPDATE_STATUSES = {
"investigating": "Investigating",
"identified": "Identified",
"monitoring": "Monitoring",
"update": "Update",
"resolved": "Resolved",
}

COMPONENT_STATUSES = {
"operational": "Operational",
"degraded_performance": "Degraded Performance",
"partial_outage": "Partial Outage",
"major_outage": "Major Outage",
"maintenance": "Maintenance",
}
95 changes: 60 additions & 35 deletions app/modules/core/status_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
from app.modules.entity.component_group_entity import ComponentGroupEntity
from app.modules.entity.incident_update_entity import IncidentUpdateEntity
from app.modules.entity.incident_update_component_entity import IncidentUpdateComponentEntity
from app.modules.core.constants import Constants


class StatusPage():

def __init__(self):
self.__option_entity = OptionEntity()
self.__incident_entity = IncidentEntity()
Expand All @@ -47,13 +48,55 @@ def __init__(self):
self.__component_group_entity = ComponentGroupEntity()
self.__component_entity = ComponentEntity()
self.__metric_entity = MetricEntity()
self.__load_system_status()

def __load_system_status(self):
open_incidents = self.__incident_entity.get_by_status("open")

self.__system_status = {
"affected_components_map": {},
"affected_components_status": {},
"affected_groups_map": {},
"affected_groups_status": {},
"overall_status": Constants.COMPONENT_STATUSES["operational"],
}

for open_incident in open_incidents:
updates = self.__incident_update_entity.get_all(open_incident.id, 0, 1)
for update in updates:
update_components = self.__incident_update_component_entity.get_all(update.id)
for update_component in update_components:
if update_component.component.name not in self.__system_status["affected_components_status"].keys():
self.__system_status["affected_components_status"][update_component.component.name] = update_component.type
if update_component.component.group:
self.__system_status["affected_groups_status"][update_component.component.group.name] = update_component.type
if update_component.component.name not in self.__system_status["affected_components_map"].keys():
self.__system_status["affected_components_map"][update_component.component.name] = update_component.component.id
if update_component.component.group:
self.__system_status["affected_groups_map"][update_component.component.group.name] = update_component.component.group.id

if "major_outage" in self.__system_status["affected_components_status"].values():
self.__system_status["overall_status"] = Constants.COMPONENT_STATUSES["major_outage"]

elif "partial_outage" in self.__system_status["affected_components_status"].values():
self.__system_status["overall_status"] = Constants.COMPONENT_STATUSES["partial_outage"]

elif "degraded_performance" in self.__system_status["affected_components_status"].values():
self.__system_status["overall_status"] = Constants.COMPONENT_STATUSES["degraded_performance"]

elif "maintenance" in self.__system_status["affected_components_status"].values():
self.__system_status["overall_status"] = Constants.COMPONENT_STATUSES["maintenance"]

def get_system_status(self):
# Get Open Incidents
# if it has no resolved update
# Check the last incident updates
# Check it has any component is affected
return "operational"

affected_components = len(self.__system_status["affected_components_map"].keys())

if affected_components == 0:
return "normal"
elif affected_components <= 2:
return "medium"
elif affected_components > 2:
return "high"

def get_about_site(self):
option = self.__option_entity.get_one_by_key("builder_about")
Expand All @@ -74,7 +117,6 @@ def get_incident_by_uri(self, uri):
if incident:
incident_data = {
"headline": incident.name,
"headline_class": "text-danger",
"status": incident.status,
"sub_headline": _("Incident Report for %s") % (app_name.value),
"affected_components": [],
Expand Down Expand Up @@ -291,8 +333,7 @@ def get_services(self):
services.append({
"name": component.name,
"description": component.description,
"current_status": self.get_status(component.id, "component"),
"current_status_class": "bg-green",
"current_status": self.get_status(component.name, "component"),
"uptime_chart": self.get_uptime_chart(component.id, "component"),
"sub_services": []
})
Expand All @@ -301,8 +342,7 @@ def get_services(self):
services.append({
"name": group.name,
"description": group.description,
"current_status": self.get_status(group.id, "group"),
"current_status_class": "bg-green",
"current_status": self.get_status(group.name, "group"),
"uptime_chart": self.get_uptime_chart(group.id, "group"),
"sub_services": self.get_sub_services(group.id)
})
Expand All @@ -316,35 +356,20 @@ def get_sub_services(self, group_id):
services.append({
"name": item.name,
"description": item.description,
"current_status": self.get_status(item.id, "component"),
"current_status_class": "bg-green",
"current_status": self.get_status(item.name, "component"),
"uptime_chart": self.get_uptime_chart(item.id, "component"),
"sub_services": []
})
return services

def get_status(self, id, type):
# Get Open Incidents
# if it has no resolved update
# Check the last incident updates
# Check if the component is affected
if type == "component":
return "Operational"

# Get Group Components
# Get Open Incidents
# if it has no resolved update
# Check the last incident updates
# Check if one of the group components is affected
elif type == "group":
return "Operational"

def __get_affectd_components(self):
# Get Open Incidents
# if it has no resolved update
# Check the last incident updates
# Create a list of affected components
return {}
def get_status(self, name, type):
if type == "component" and name in self.__system_status["affected_components_status"].keys():
return Constants.COMPONENT_STATUSES[self.__system_status["affected_components_status"][name]]

elif type == "group" and name in self.__system_status["affected_groups_status"].keys():
return Constants.COMPONENT_STATUSES[self.__system_status["affected_groups_status"][name]]

return Constants.COMPONENT_STATUSES["operational"]

def get_uptime_chart(self, id, type, period=90):
return []
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ pyvalitron==1.1.3
feedgen==0.8.0
python-dateutil==2.8.0
psycopg2-binary==2.8.3
whitenoise==4.1.3
whitenoise==4.1.4
4 changes: 2 additions & 2 deletions themes/default/templates/admin/incident/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ <h3 class="card-title">{% trans "Add a New Incident" %}</h3>
</div>
<div class="form-group">
<label class="form-label">{% trans "Datetime" %} ({{ app_timezone }})<span class="form-required">*</span></label>
<input type="text" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" required>
<small class="form-text text-muted">{% trans "For example" %} <code>2019-01-15 19:00:00</code></small>
<input type="text" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" value="{% now "Y-m-d H:i:s" %}" required>
<small class="form-text text-muted">{% trans "For example" %} <code>{% now "Y-m-d H:i:s" %}</code></small>
</div>
<div class="form-group">
<label class="form-label">{% trans "Status" %}<span class="form-required">*</span></label>
Expand Down
2 changes: 1 addition & 1 deletion themes/default/templates/admin/incident/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h3 class="card-title">{% trans "Edit Incident" %}</h3>
<div class="form-group">
<label class="form-label">{% trans "Datetime" %} ({{ app_timezone }})<span class="form-required">*</span></label>
<input type="text" value="{{ incident.datetime|date:'Y-m-d H:i:s' }}" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" required>
<small class="form-text text-muted">{% trans "For example" %} <code>2019-01-15 19:00:00</code></small>
<small class="form-text text-muted">{% trans "For example" %} <code>{% now "Y-m-d H:i:s" %}</code></small>
</div>
<div class="form-group">
<label class="form-label">{% trans "Status" %}<span class="form-required">*</span></label>
Expand Down
4 changes: 2 additions & 2 deletions themes/default/templates/admin/incident/update/add.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ <h3 class="card-title">{% trans "Add a New Update" %}</h3>
<div class="col-md-12 col-lg-12">
<div class="form-group">
<label class="form-label">{% trans "Datetime" %} ({{ app_timezone }})<span class="form-required">*</span></label>
<input type="text" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" required>
<small class="form-text text-muted">{% trans "For example" %} <code>2019-01-15 19:00:00</code></small>
<input type="text" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" value="{% now "Y-m-d H:i:s" %}" required>
<small class="form-text text-muted">{% trans "For example" %} <code>{% now "Y-m-d H:i:s" %}</code></small>
</div>
<div class="form-group">
<label class="form-label">{% trans "Status" %}<span class="form-required">*</span></label>
Expand Down
2 changes: 1 addition & 1 deletion themes/default/templates/admin/incident/update/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h3 class="card-title">{% trans "Edit Update" %}</h3>
<div class="form-group">
<label class="form-label">{% trans "Datetime" %} ({{ app_timezone }})<span class="form-required">*</span></label>
<input type="text" value="{{ update.datetime|date:'Y-m-d H:i:s' }}" name="datetime" class="form-control" data-mask="0000-00-00 00:00:00" data-mask-clearifnotmatch="true" placeholder="0000-00-00 00:00:00" required>
<small class="form-text text-muted">{% trans "For example" %} <code>2019-01-15 19:00:00</code></small>
<small class="form-text text-muted">{% trans "For example" %} <code>{% now "Y-m-d H:i:s" %}</code></small>
</div>
<div class="form-group">
<label class="form-label">{% trans "Status" %}<span class="form-required">*</span></label>
Expand Down
1 change: 1 addition & 0 deletions themes/default/templates/admin/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ <h3 class="card-title">{% trans "Settings" %}</h3>
{% trans "Version" %}
<a href="{{ current.download_url }}" class="tag-addon tag-success" target="_blank">{{ current.version }}</a>
</div>
<br/><br/>
<div class="tag">
{% trans "Latest" %}
<a href="{{ latest.download_url }}" class="tag-addon tag-info" target="_blank">{{ latest.version }}</a>
Expand Down
Loading

0 comments on commit 92435e6

Please sign in to comment.