Commit 1ff60790 authored by Aleksey Shirokih's avatar Aleksey Shirokih
Browse files

show subinterfaces graphs. introduce description bad chars cleaner

parent 8b1cb5ae
......@@ -6,10 +6,13 @@
# See LICENSE for details
# ---------------------------------------------------------------------
import logging
# Python modules
import os
import ujson
import logging
BAD_CHARS = u'!"%\'()+,:;<>?@\^`{|}~\\\n\r'
class BaseDashboard(object):
......@@ -79,3 +82,8 @@ class BaseDashboard(object):
self.logger.error("Dashboard template file %s not contains valid JSON" % fl)
continue
return t
def str_cleanup(self, data, translate_to=None):
remove_letters = BAD_CHARS
translate_table = dict((ord(char), translate_to) for char in remove_letters)
return data.translate(translate_table)
......@@ -9,7 +9,6 @@
"""
import demjson
from jinja2 import Environment, FileSystemLoader
from noc.config import config
from noc.sa.models.managedobject import ManagedObject
......@@ -30,12 +29,12 @@ class IPSLADashboard(BaseDashboard):
def render(self):
context = {
"device": self.object.name.replace('\"', ''),
"device": self.str_cleanup(self.object.name),
"ip": self.object.address,
"device_id": self.object.id,
"bi_id": self.object.bi_id,
"segment": self.object.segment.id,
"probes": [{"name": probe.name.replace('\"', ''), "value": probe.target} for
"probes": [{"name": self.str_cleanup(probe.name), "value": probe.target} for
probe in SLAProbe.objects.filter(managed_object=self.object.id)]
}
self.logger.info("Context with data: %s" % context)
......
......@@ -9,7 +9,6 @@
"""
import demjson
from jinja2 import Environment, FileSystemLoader
from noc.config import config
from noc.inv.models.link import Link
......@@ -30,9 +29,9 @@ class LinkDashboard(BaseDashboard):
def render(self):
mos = self.object
if mos.interfaces[0].description:
mos.interfaces[0].description = mos.interfaces[0].description.replace('\"', '')
mos.interfaces[0].description = self.str_cleanup(mos.interfaces[0].description)
if mos.interfaces[1].description:
mos.interfaces[1].description = mos.interfaces[1].description.replace('\"', '')
mos.interfaces[1].description = self.str_cleanup(mos.interfaces[1].description)
context = {
"device_a": mos.interfaces[0].managed_object.name.replace('\"', ''),
"device_b": mos.interfaces[1].managed_object.name.replace('\"', ''),
......
......@@ -7,10 +7,10 @@
# ---------------------------------------------------------------------
import demjson
from jinja2 import Environment, FileSystemLoader
from noc.config import config
from noc.inv.models.interface import Interface
from noc.inv.models.subinterface import SubInterface
# NOC modules
from noc.lib.text import split_alnum
from noc.pm.models.metrictype import MetricType
......@@ -41,6 +41,7 @@ class MODashboard(BaseDashboard):
port_types = []
object_metrics = []
lags = []
subif = []
# Get all interface profiles with configurable metrics
all_ifaces = list(Interface.objects.filter(
......@@ -54,17 +55,20 @@ class MODashboard(BaseDashboard):
ifaces = [i for i in all_ifaces if i.profile == profile]
ports = []
for iface in sorted(ifaces, key=lambda el: split_alnum(el.name)):
if iface.description:
iface.description = iface.description.replace('\"', '')
if iface.type == u"aggregated" and iface.lag_members:
lags += [{
"name": iface.name,
"ports": [i.name for i in iface.lag_members],
"descr": iface.description or "No description",
"descr": self.str_cleanup(iface.description) or "No description",
"status": ["status : ".join([i.name, i.status]) for i in iface.lag_members]
}]
continue
ports += [{"name": iface.name, "descr": iface.description, "status": iface.status}]
ports += [{"name": iface.name, "descr": self.str_cleanup(iface.description), "status": iface.status}]
if iface.profile.allow_subinterface_metrics:
subif += [{
"name": si.name,
"descr": self.str_cleanup(si.description)
} for si in SubInterface.objects.filter(interface=iface)]
if not ports:
continue
port_types += [{"type": profile.id, "name": profile.name,
......@@ -80,7 +84,8 @@ class MODashboard(BaseDashboard):
return {"port_types": port_types,
"object_metrics": object_metrics,
"lags": lags}
"lags": lags,
"subifaces": subif}
def render(self):
......@@ -95,6 +100,7 @@ class MODashboard(BaseDashboard):
"firmare_version": self.object.version.version if self.object.version else None,
"segment": self.object.segment.id,
"vendor": self.object.vendor or "Unknown version",
"subifaces": self.object_data["subifaces"],
"bi_id": self.object.bi_id,
"pool": self.object.pool.name,
"ping_interval": self.object.object_profile.ping_interval,
......
......@@ -38,6 +38,11 @@
{% endfor -%},
{% endif %}
{% if subifaces %}
{% from "template_subiface.j2" import subiface -%}
{{ subiface(subifaces) }},
{% endif %}
{% include "template_device.j2" with context -%},
{% include "template_vendor.j2" with context -%},
{% include "template_platform.j2" with context -%},
......@@ -133,6 +138,23 @@
}
{%- endfor %}
{%endif%}
{%if subifaces %}
,
{% set comma = joiner(",") -%}
{
"collapse": false,
"editable": false,
"height": "250px",
"showTitle": true,
"title": "SubInterfaces",
"internal_comment": "subif_row",
"panels": [
{% from "graph_subinterface_load.j2" import subinterface -%}
{{subinterface()}}
]
}
{%endif%}
{%if lags %}
,
{% set comma = joiner(",") -%}
......@@ -157,6 +179,8 @@
,
{% include "row_errors.j2" with context -%}
{%endif%}
{%if object_metrics%}
,
{
......
......@@ -32,7 +32,6 @@
"targets": [
{
"query": "SELECT $timeSeries as t, avg(rtt) `Ping | RTT`, avg(attempts) `Ping | Attempts` FROM $table WHERE managed_object=$bi_id and $timeFilter GROUP BY t ORDER BY t",
"formattedQuery": "<font color=\"darkorange\">SELECT</font> <font color=\"darkcyan\">$timeSeries</font> <font color=\"darkorange\">as</font> t, <font color=\"navajowhite\">avg</font>(rtt) <font color=\"lightgreen\">`Ping | RTT`</font>,  <font color=\"navajowhite\">avg</font>(attempts) <font color=\"lightgreen\">`Ping | Attempts`</font> <font color=\"darkorange\">FROM</font> <font color=\"darkcyan\">$table</font> <font color=\"darkorange\">WHERE</font> managed_object<font color=\"yellow\">=</font><font color=\"darkcyan\">$bi_id</font> <font color=\"yellow\">and</font> <font color=\"darkcyan\">$timeFilter</font> <font color=\"darkorange\">GROUP BY</font> t <font color=\"darkorange\">ORDER BY</font> t",
"database": "noc",
"tableLoading": false,
"table": "ping",
......
{% macro subinterface() -%}
{
"title": "$SubInterfaces",
"aliasColors": {},
"bars": false,
"internal_comment":"graph_subinterface_load.j2",
"datasource": null,
"repeat": "SubInterfaces",
"fill": 1,
"grid": {
"threshold1": null,
"threshold1Color": "rgba(216, 200, 27, 0.27)",
"threshold2": null,
"threshold2Color": "rgba(234, 112, 112, 0.22)"
},
"id": "",
"legend": {
"alignAsTable": true,
"avg": true,
"current": true,
"max": true,
"min": true,
"show": true,
"sortDesc": true,
"total": false,
"values": true
},
"lines": true,
"linewidth": 2,
"links": [],
"minSpan": 6,
"nullPointMode": "connected",
"percentage": false,
"pointradius": 5,
"points": false,
"renderer": "flot",
"scopedVars": {
},
"seriesOverrides": [
{
"alias": "Input",
"transform": "negative-Y"
},
{
"alias": "Oper status",
"yaxis": 2,
"fill": 0
},
{
"alias": "Admin status",
"yaxis": 2,
"fill": 0
}
],
"span": 12,
"stack": false,
"steppedLine": false,
"targets": [
{
"intervalFactor": 1,
"query": "SELECT $timeSeries as t, avg(load_in) as Input, avg(load_out) as Output FROM $table WHERE managed_object = $bi_id and path[5]=toString($SubInterfaces) and $timeFilter GROUP BY t ORDER BY t",
"refId": "A",
"resultFormat": "time_series",
"database": "noc",
"tableLoading": false,
"table": "interface",
"dateLoading": false,
"datetimeLoading": false,
"dateColDataType": "date",
"dateTimeColDataType": "ts"
}
],
"timeFrom": null,
"timeShift": null,
"tooltip": {
"msResolution": false,
"shared": true,
"sort": 0,
"value_type": "cumulative"
},
"type": "graph",
"xaxis": {
"show": true
},
"y-axis": true,
"yaxes": [
{
"format": "bps",
"label": "bit/s",
"logBase": 1,
"max": null,
"min": null,
"show": true
},
{
"logBase": 1,
"show": false,
"max": null,
"format": "short",
"min": null,
"label": null
}
]
}
{%- endmacro %}
{% macro subiface(subifaces) -%}
{% set comma = joiner(",") -%}
{
"current": {
"selected": true,
"tags": [],
"text": "All",
"value": [
"$__all"
]
},
"datasource": null,
"hide": 0,
"includeAll": true,
"label": "SubInterfaces",
"multi": true,
"name": "SubInterfaces",
"options": [
{
"selected": false,
"text": "All",
"value": "$__all"
},
{%for port in subifaces -%}
{{ comma() }}{
"selected": false,
"text": "{%- if port.descr -%}{{port.name}} ({{port.descr}}){%else%}{{port.name}}{%- endif -%}",
"value": "{{port.name}}"
}
{%- endfor %}
],
"query": "{%- for port in subifaces %}{{port.name}},{% endfor %}",
"refresh": 0,
"type": "custom"
}
{%- endmacro %}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment