Merge "Add Monitoring violations panel"

This commit is contained in:
Jenkins 2017-07-24 05:33:25 +00:00 committed by Gerrit Code Review
commit 12e50f3079
11 changed files with 191 additions and 1 deletions

View File

@ -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):

View File

@ -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 = []

View File

@ -0,0 +1,5 @@
PANEL = 'monitor'
PANEL_DASHBOARD = 'admin'
PANEL_GROUP = 'policy'
ADD_PANEL = 'congress_dashboard.monitoring.panel.Monitor'
AUTO_DISCOVER_STATIC_FILES = True

View File

@ -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)

View File

@ -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")

View File

@ -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 %}
<div id="monitoring">
{{ monitoring_table.render }}
</div>
{% endblock %}

View File

@ -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'),
]

View File

@ -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 []

View File

@ -22,5 +22,4 @@ class Policies(horizon.Panel):
slug = "policies"
permissions = ('openstack.roles.admin',)
dashboard.Admin.register(Policies)

View File

@ -0,0 +1,3 @@
---
features:
- New Panel 'Monitoring' added to list the violations for each policy.