Skip to content
Snippets Groups Projects
Commit 144fe561 authored by Nico Vermaas's avatar Nico Vermaas
Browse files

service resume/hold buttons (in progress)

parent 827c0c4c
No related branches found
No related tags found
2 merge requests!244Master,!241594 improve monitoring page
...@@ -34,7 +34,7 @@ TD { ...@@ -34,7 +34,7 @@ TD {
} }
.error,.failed,.staging_failed,.staged_failed,.processed_failed,.scrubbed_failed,.stored_failed,.archived_failed { .error,.failed,.staging_failed,.staged_failed,.processed_failed,.scrubbed_failed,.stored_failed,.archived_failed,.on_hold {
color: red; color: red;
font-weight: bold; font-weight: bold;
} }
......
...@@ -226,6 +226,14 @@ class LatestMonitor(models.Model): ...@@ -226,6 +226,14 @@ class LatestMonitor(models.Model):
status = models.CharField(max_length=50, default="ok", null=True) status = models.CharField(max_length=50, default="ok", null=True)
metadata = models.JSONField(null=True, blank=True) metadata = models.JSONField(null=True, blank=True)
@property
def enabled(self):
try:
enabled = self.metadata['enabled']
return enabled
except:
return None
# the representation of the value in the REST API # the representation of the value in the REST API
def __str__(self): def __str__(self):
return str(self.name) + ' - ('+ self.hostname+') - '+str(self.timestamp) + ' - ' + self.status return str(self.name) + ' - ('+ self.hostname+') - '+str(self.timestamp) + ' - ' + self.status
...@@ -246,11 +254,20 @@ class Monitor(models.Model): ...@@ -246,11 +254,20 @@ class Monitor(models.Model):
# in the LatestMonitor, and update if it is newer. # in the LatestMonitor, and update if it is newer.
try: try:
latestMonitor = LatestMonitor.objects.get(name=self.name,hostname=self.hostname) latestMonitor = LatestMonitor.objects.get(name=self.name,hostname=self.hostname)
# carry over the metadata, if possible
latest_metadata = latestMonitor.metadata
latestMonitor.delete() latestMonitor.delete()
except: except:
pass pass
# this combination of name and hostname didn't yet exist, create it. # this combination of name and hostname didn't yet exist, create it.
metadata = self.metadata
try:
if latest_metadata:
metadata = latest_metadata
except:
pass
latestMonitor = LatestMonitor( latestMonitor = LatestMonitor(
name=self.name, name=self.name,
type=self.type, type=self.type,
...@@ -259,7 +276,7 @@ class Monitor(models.Model): ...@@ -259,7 +276,7 @@ class Monitor(models.Model):
process_id = self.process_id, process_id = self.process_id,
description = self.description, description = self.description,
status = self.status, status = self.status,
metadata = self.metadata metadata = metadata
) )
latestMonitor.save() latestMonitor.save()
......
...@@ -288,19 +288,27 @@ def convert_monitor_to_html(request, monitor_data): ...@@ -288,19 +288,27 @@ def convert_monitor_to_html(request, monitor_data):
line += "<td><b>" + link_to_service_history + "</b></td>" line += "<td><b>" + link_to_service_history + "</b></td>"
line += "<td>" + str(record.hostname) + "</td>" line += "<td>" + str(record.hostname) + "</td>"
if record.enabled=="True":
button_html = '<a href="service_hold_resume/' + str(record.pk) + '/False"' + 'class="btn btn-warning btn-sm" role="button"><i class="fas fa-pause"></i> Hold</a>'
else:
button_html = '<a href="service_hold_resume/' + str(record.pk) + '/True"' + 'class="btn btn-success btn-sm" role="button"><i class="fas fa-play"></i> Resume</a>'
# if the heartbeat is 30 minutes late, show '(late)' in red # if the heartbeat is 30 minutes late, show '(late)' in red
if delta.seconds > 1800: if delta.seconds > 1800:
line += '<td>' + button_html + str(record.enabled) + "</td>"
line += "<td><i>unknown</i></td>" line += "<td><i>unknown</i></td>"
line += '<td class="error">' + str(record.timestamp.strftime(TIME_FORMAT)) + " - (late)</td>" line += '<td class="error">' + str(record.timestamp.strftime(TIME_FORMAT)) + " - (late)</td>"
else: else:
line += '<td>' + button_html + str(record.enabled) + "</td>"
line += '<td class="' + record.status + '" >' + str(record.status) + "</td>" line += '<td class="' + record.status + '" >' + str(record.status) + "</td>"
line += '<td>' + str(record.timestamp.strftime(TIME_FORMAT)) + "</td>" line += '<td>' + str(record.timestamp.strftime(TIME_FORMAT)) + "</td>"
line += "<td>" + str(record.process_id) + "</td>" line += "<td>" + str(record.process_id) + "</td>"
line += "<td>" + str(record.description) + "</td>" line += "<td>" + str(record.description) + "</td>"
line += "</tr>" line += "</tr>"
results = results + line results = results + line
except: except Exception as e:
results = "<tr><td>no data</td></tr>" results = "<tr><td>no data</td></tr>"
return results return results
......
...@@ -34,7 +34,7 @@ TD { ...@@ -34,7 +34,7 @@ TD {
} }
.error,.failed,.staging_failed,.staged_failed,.processed_failed,.scrubbed_failed,.stored_failed,.archived_failed { .error,.failed,.staging_failed,.staged_failed,.processed_failed,.scrubbed_failed,.stored_failed,.archived_failed,.on_hold {
color: red; color: red;
font-weight: bold; font-weight: bold;
} }
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
</p> </p>
{% endif %} {% endif %}
<table class="table table-striped"> <table class="table table-striped">
<th>LDV-Service</th><th>Host</th><th>Status</th><th>Timestamp</th><th>Process id</th><th>Description</th> <th>LDV-Service</th><th>Host</th><th>Enabled</th><th>Status</th><th>Timestamp</th><th>Process id</th><th>Description</th>
<tbody> <tbody>
{{ monitor_results | safe }} {{ monitor_results | safe }}
</tbody> </tbody>
......
...@@ -72,7 +72,7 @@ urlpatterns = [ ...@@ -72,7 +72,7 @@ urlpatterns = [
path('monitor/<int:pk>/', views.MonitorDetailsViewAPI.as_view(),name='monitor-detail-view-api'), path('monitor/<int:pk>/', views.MonitorDetailsViewAPI.as_view(),name='monitor-detail-view-api'),
path('latest_monitor/', views.LatestMonitorListViewAPI.as_view(),name='latest-monitor-detail-view-api'), path('latest_monitor/', views.LatestMonitorListViewAPI.as_view(),name='latest-monitor-detail-view-api'),
path('monitor/clear_inactive_services/', views.ClearInactiveServices, name='clear-inactive-services'), path('monitor/clear_inactive_services/', views.ClearInactiveServices, name='clear-inactive-services'),
path('monitoring/service_hold_resume/<int:pk>/<enabled>', views.ServiceHoldResume, name='service-hold-resume'),
# --- custom requests --- # --- custom requests ---
# /atdb/get_size?status__in=defined,staged # /atdb/get_size?status__in=defined,staged
...@@ -108,5 +108,7 @@ urlpatterns = [ ...@@ -108,5 +108,7 @@ urlpatterns = [
path('tasks/<int:pk>/hold/<hold_it>', views.Hold, name='task-hold-resume'), path('tasks/<int:pk>/hold/<hold_it>', views.Hold, name='task-hold-resume'),
path('tasks/<int:pk>/query-hold/<hold_it>/<query_params>', views.HoldQuery, name='query-hold-resume'), path('tasks/<int:pk>/query-hold/<hold_it>/<query_params>', views.HoldQuery, name='query-hold-resume'),
path('tasks/<int:pk>/hold/<hold_it>/<page>', views.Hold, name='service-hold-resume'),
path('hello/', views.HelloView.as_view(), name='hello'), path('hello/', views.HelloView.as_view(), name='hello'),
] ]
...@@ -41,7 +41,6 @@ from .serializers import \ ...@@ -41,7 +41,6 @@ from .serializers import \
PostProcessingRuleSerializer, \ PostProcessingRuleSerializer, \
MonitorSerializer, LatestMonitorSerializer MonitorSerializer, LatestMonitorSerializer
from .services import algorithms from .services import algorithms
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -156,6 +155,15 @@ class MonitorFilter(filters.FilterSet): ...@@ -156,6 +155,15 @@ class MonitorFilter(filters.FilterSet):
'timestamp': ['icontains'], 'timestamp': ['icontains'],
} }
class LatestMonitorFilter(filters.FilterSet):
class Meta:
model = LatestMonitor
fields = {
'name': ['exact', 'icontains', 'in'],
'hostname': ['exact', 'icontains', 'in'],
}
# ---------- Tables2 Views (experimental) ----------- # ---------- Tables2 Views (experimental) -----------
class QueryView(SingleTableMixin, FilterView): class QueryView(SingleTableMixin, FilterView):
table_class = TaskTable table_class = TaskTable
...@@ -903,7 +911,7 @@ class LatestMonitorListViewAPI(generics.ListCreateAPIView): ...@@ -903,7 +911,7 @@ class LatestMonitorListViewAPI(generics.ListCreateAPIView):
serializer_class = LatestMonitorSerializer serializer_class = LatestMonitorSerializer
filter_backends = (filters.DjangoFilterBackend,) filter_backends = (filters.DjangoFilterBackend,)
filter_class = MonitorFilter filter_class = LatestMonitorFilter
@login_required @login_required
...@@ -945,6 +953,19 @@ def HoldQuery(request, pk, hold_it, query_params): ...@@ -945,6 +953,19 @@ def HoldQuery(request, pk, hold_it, query_params):
current_query_params = convert_query_params_to_url(query_params) current_query_params = convert_query_params_to_url(query_params)
return redirect('/atdb/query/?' + current_query_params) return redirect('/atdb/query/?' + current_query_params)
@login_required
def ServiceHoldResume(request, pk, enabled):
model = LatestMonitor
service = LatestMonitor.objects.get(pk=pk)
metadata = service.metadata
if not metadata:
metadata = {}
metadata['enabled'] = enabled
service.metadata = metadata
service.save()
return redirect('/atdb/monitoring')
@login_required @login_required
def TaskSetStatus(request, pk, new_status, page=0): def TaskSetStatus(request, pk, new_status, page=0):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment