From 55dd68582cd599e5ee4a474bfbb3586d775c49ea Mon Sep 17 00:00:00 2001 From: Anusha Ramineni Date: Mon, 10 Jul 2017 12:26:49 +0530 Subject: [PATCH] Add Monitoring violations panel This commit adds new panel to monitor violations in congress UI. Assumes each policy would have only one defined error or warning table. This panel lists the errors count and warnings count for each policy if defined. TODO: 1. Add link to policy error table to list the rows 2. Coloring for error and warning 3. Periodic refresh of data. Partial-Bug:#1670520 Change-Id: I24f16df716e58121bc22cf2ae4426de80d06a8ee --- congress_dashboard/api/congress.py | 1 + congress_dashboard/datasources/utils.py | 51 +++++++++++++++++++ congress_dashboard/enabled/_75_monitoring.py | 5 ++ congress_dashboard/monitoring/__init__.py | 0 congress_dashboard/monitoring/panel.py | 25 +++++++++ congress_dashboard/monitoring/tables.py | 31 +++++++++++ .../templates/monitoring/index.html | 13 +++++ congress_dashboard/monitoring/urls.py | 22 ++++++++ congress_dashboard/monitoring/views.py | 40 +++++++++++++++ congress_dashboard/policies/panel.py | 1 - ...add-monitoring-panel-a7fd8a2e93e1f404.yaml | 3 ++ 11 files changed, 191 insertions(+), 1 deletion(-) create mode 100644 congress_dashboard/enabled/_75_monitoring.py create mode 100644 congress_dashboard/monitoring/__init__.py create mode 100644 congress_dashboard/monitoring/panel.py create mode 100644 congress_dashboard/monitoring/tables.py create mode 100644 congress_dashboard/monitoring/templates/monitoring/index.html create mode 100644 congress_dashboard/monitoring/urls.py create mode 100644 congress_dashboard/monitoring/views.py create mode 100644 releasenotes/notes/add-monitoring-panel-a7fd8a2e93e1f404.yaml diff --git a/congress_dashboard/api/congress.py b/congress_dashboard/api/congress.py index 54e4a7f..6f63c3e 100644 --- a/congress_dashboard/api/congress.py +++ b/congress_dashboard/api/congress.py @@ -68,6 +68,7 @@ class PolicyTable(PolicyAPIDictWrapper): def set_policy_details(self, policy): self._apidict['policy_name'] = policy['name'] self._apidict['policy_owner_id'] = policy['owner_id'] + self._apidict['policy_description'] = policy['description'] def congressclient(request): diff --git a/congress_dashboard/datasources/utils.py b/congress_dashboard/datasources/utils.py index 23915c1..3a8f7d2 100644 --- a/congress_dashboard/datasources/utils.py +++ b/congress_dashboard/datasources/utils.py @@ -52,6 +52,57 @@ def _get_policy_tables(request): return all_tables +def _get_policy_violations_tables(request): + """Return error and warning tables info for all policies. """ + try: + # Get all the policies. + policies = congress.policies_list(request) + except Exception as e: + LOG.error('Unable to get list of policies: %s', str(e)) + else: + try: + tables_data = [] + for policy in policies: + policy_name = policy['name'] + policy_table_info = {} + error_warning_tables = [] + # Get all the tables in this policy. + policy_tables = congress.policy_tables_list(request, + policy_name) + for table in policy_tables: + table_name = table['id'] + if congress.TABLE_SEPARATOR in table_name: + continue + if table_name == 'error' or table_name == 'warning': + policy_table_info['policy'] = policy + error_warning_tables.append(table_name) + if error_warning_tables: + policy_table_info['tables'] = error_warning_tables + tables_data.append(policy_table_info) + except Exception as e: + LOG.error('Unable to get tables for policy "%s": %s', + policy_name, str(e)) + return tables_data + + +def get_policy_violations_data(request): + """Get the row count of each error and warning tables. """ + tables_data = _get_policy_violations_tables(request) + violations_table = [] + + for data in tables_data: + policy = data['policy'] + tables = data['tables'] + row = congress.PolicyTable({"id": policy['name']}) + row.set_id_as_name_if_empty() + row.set_policy_details(policy) + for t in tables: + rows = congress.policy_rows_list(request, policy['name'], t) + row.set_value(t, len(rows)) + violations_table.append(row) + return violations_table + + def _get_service_tables(request): # Return all service tables. all_tables = [] diff --git a/congress_dashboard/enabled/_75_monitoring.py b/congress_dashboard/enabled/_75_monitoring.py new file mode 100644 index 0000000..4c5bbe1 --- /dev/null +++ b/congress_dashboard/enabled/_75_monitoring.py @@ -0,0 +1,5 @@ +PANEL = 'monitor' +PANEL_DASHBOARD = 'admin' +PANEL_GROUP = 'policy' +ADD_PANEL = 'congress_dashboard.monitoring.panel.Monitor' +AUTO_DISCOVER_STATIC_FILES = True diff --git a/congress_dashboard/monitoring/__init__.py b/congress_dashboard/monitoring/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/congress_dashboard/monitoring/panel.py b/congress_dashboard/monitoring/panel.py new file mode 100644 index 0000000..d0ae950 --- /dev/null +++ b/congress_dashboard/monitoring/panel.py @@ -0,0 +1,25 @@ +# Copyright 2017 NEC, Corp +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.utils.translation import ugettext_lazy as _ +import horizon +from openstack_dashboard.dashboards.admin import dashboard + + +class Monitor(horizon.Panel): + name = _("Monitoring") + slug = "monitoring" + permissions = ('openstack.roles.admin',) + +dashboard.Admin.register(Monitor) diff --git a/congress_dashboard/monitoring/tables.py b/congress_dashboard/monitoring/tables.py new file mode 100644 index 0000000..eedc5cc --- /dev/null +++ b/congress_dashboard/monitoring/tables.py @@ -0,0 +1,31 @@ +# Copyright 2017 NEC, Corp +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.utils.translation import ugettext_lazy as _ +from horizon import tables + + +class MonitoringTable(tables.DataTable): + errors = tables.Column("error", verbose_name=_("Errors")) + warnings = tables.Column("warning", verbose_name=_("Warnings")) + policy_name = tables.Column("policy_name", + verbose_name=_("violated policy name")) + policy_description = tables.Column("policy_description", + verbose_name=_("Policy Description")) + policy_owner_id = tables.Column("policy_owner_id", + verbose_name=_("Policy Owner")) + + class Meta(object): + name = "monitoring" + verbose_name = _("Monitoring") diff --git a/congress_dashboard/monitoring/templates/monitoring/index.html b/congress_dashboard/monitoring/templates/monitoring/index.html new file mode 100644 index 0000000..b1fc8c2 --- /dev/null +++ b/congress_dashboard/monitoring/templates/monitoring/index.html @@ -0,0 +1,13 @@ +{% extends 'base.html' %} +{% load i18n %} +{% block title %}{% trans "Monitoring" %}{% endblock %} + +{% block page_header %} + {% include "horizon/common/_page_header.html" with title=_("Monitoring") %} +{% endblock page_header %} + +{% block main %} +
+ {{ monitoring_table.render }} +
+{% endblock %} diff --git a/congress_dashboard/monitoring/urls.py b/congress_dashboard/monitoring/urls.py new file mode 100644 index 0000000..4dc6b3b --- /dev/null +++ b/congress_dashboard/monitoring/urls.py @@ -0,0 +1,22 @@ +# Copyright 2017 NEC, Corp +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.conf.urls import url + +from congress_dashboard.monitoring import views + + +urlpatterns = [ + url(r'^$', views.IndexView.as_view(), name='index'), +] diff --git a/congress_dashboard/monitoring/views.py b/congress_dashboard/monitoring/views.py new file mode 100644 index 0000000..31a63bc --- /dev/null +++ b/congress_dashboard/monitoring/views.py @@ -0,0 +1,40 @@ +# Copyright 2017 NEC, Corp +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import logging + +from django.utils.translation import ugettext_lazy as _ +from horizon import messages +from horizon import tables + +import congress_dashboard.datasources.utils as ds_utils +from congress_dashboard.monitoring import tables as monitor_tables + +LOG = logging.getLogger(__name__) + + +class IndexView(tables.DataTableView): + """List policy violations.""" + table_class = monitor_tables.MonitoringTable + template_name = 'admin/monitoring/index.html' + + def get_data(self): + try: + violations_data = ds_utils.get_policy_violations_data(self.request) + return violations_data + except Exception as e: + msg = _('Unable to policy violations data: %s') % str(e) + LOG.exception(msg) + messages.error(self.request, msg) + return [] diff --git a/congress_dashboard/policies/panel.py b/congress_dashboard/policies/panel.py index f95a61e..261ea49 100644 --- a/congress_dashboard/policies/panel.py +++ b/congress_dashboard/policies/panel.py @@ -22,5 +22,4 @@ class Policies(horizon.Panel): slug = "policies" permissions = ('openstack.roles.admin',) - dashboard.Admin.register(Policies) diff --git a/releasenotes/notes/add-monitoring-panel-a7fd8a2e93e1f404.yaml b/releasenotes/notes/add-monitoring-panel-a7fd8a2e93e1f404.yaml new file mode 100644 index 0000000..1976718 --- /dev/null +++ b/releasenotes/notes/add-monitoring-panel-a7fd8a2e93e1f404.yaml @@ -0,0 +1,3 @@ +--- +features: + - New Panel 'Monitoring' added to list the violations for each policy.