Commit de05b991 authored by MaksimSmile13's avatar MaksimSmile13
Browse files

Fix erros_out -> errors_out

parent b2920ce1
......@@ -2,12 +2,11 @@
# ---------------------------------------------------------------------
# ManagedObject card handler
# ---------------------------------------------------------------------
# Copyright (C) 2007-2017 The NOC Project
# Copyright (C) 2007-2018 The NOC Project
# See LICENSE for details
# ---------------------------------------------------------------------
from collections import defaultdict
from __future__ import absolute_import
# Python modules
import datetime
import operator
......@@ -34,6 +33,7 @@ from noc.core.pm.utils import get_interface_metrics, get_objects_metrics
from noc.pm.models.metrictype import MetricType
from noc.core.perf import metrics
class ManagedObjectCard(BaseCard):
name = "managedobject"
default_template_name = "managedobject"
......@@ -177,9 +177,12 @@ class ManagedObjectCard(BaseCard):
if objects_metrics.get("") is not None:
for key in objects_metrics.get("").keys():
if metric_type_name[key] in ["bytes", "bit/s", "bool"]:
objects_metrics.get("")[key] = {"type": metric_type_name[key], "value": self.humanize_speed(objects_metrics.get("")[key], metric_type_name[key])}
objects_metrics.get("")[key] = {"type": metric_type_name[key],
"value": self.humanize_speed(objects_metrics.get("")[key],
metric_type_name[key])}
else:
objects_metrics.get("")[key] = {"type": metric_type_name[key], "value": objects_metrics.get("")[key]}
objects_metrics.get("")[key] = {"type": metric_type_name[key],
"value": objects_metrics.get("")[key]}
meta = objects_metrics.get("")
else:
meta = {}
......@@ -191,39 +194,44 @@ class ManagedObjectCard(BaseCard):
errors_in = "-"
errors_out = "-"
iface_get_link_name = iface_metrics.get(str(i.name))
if iface_get_link_name != None:
if iface_get_link_name is not None:
for key in iface_get_link_name.keys():
meta_type = metric_type_name.get(key) or metric_type_field.get(key)
iface_get_link_name[key] = {"type": meta_type, "value": self.humanize_speed(str(iface_get_link_name[key]), meta_type)}
if key in ['Interface | Load | In', 'Interface | Load | Out', 'Interface | Errors | In', 'Interface | Errors | Out']:
iface_get_link_name[key] = {"type": meta_type,
"value": self.humanize_speed(str(iface_get_link_name[key]),
meta_type)}
if key in ['Interface | Load | In', 'Interface | Load | Out', 'Interface | Errors | In',
'Interface | Errors | Out']:
try:
load_in = iface_get_link_name['Interface | Load | In']["value"] + iface_get_link_name['Interface | Load | In']["type"]
load_out = iface_get_link_name['Interface | Load | Out']["value"] + iface_get_link_name['Interface | Load | Out']["type"]
load_in = iface_get_link_name['Interface | Load | In']["value"] + \
iface_get_link_name['Interface | Load | In']["type"]
load_out = iface_get_link_name['Interface | Load | Out']["value"] + \
iface_get_link_name['Interface | Load | Out']["type"]
errors_in = iface_get_link_name['Interface | Errors | In']["value"]
erros_out = iface_get_link_name['Interface | Errors | Out']["value"]
errors_out = iface_get_link_name['Interface | Errors | Out']["value"]
except TypeError:
pass
else:
iface_get_link_name = {}
interfaces += [{
"id": i.id,
"name": i.name,
"admin_status": i.admin_status,
"oper_status": i.oper_status,
"mac": i.mac or "",
"full_duplex": i.full_duplex,
"load_in": load_in,
"load_out": load_out,
"errors_in": errors_in,
"errors_out": errors_out,
"speed": max([i.in_speed or 0, i.out_speed or 0]) / 1000,
"untagged_vlan": None,
"tagged_vlan": None,
"profile": i.profile,
"service": i.service,
"service_summary": service_summary.get("interface").get(i.id, {})
"id": i.id,
"name": i.name,
"admin_status": i.admin_status,
"oper_status": i.oper_status,
"mac": i.mac or "",
"full_duplex": i.full_duplex,
"load_in": load_in,
"load_out": load_out,
"errors_in": errors_in,
"errors_out": errors_out,
"speed": max([i.in_speed or 0, i.out_speed or 0]) / 1000,
"untagged_vlan": None,
"tagged_vlan": None,
"profile": i.profile,
"service": i.service,
"service_summary": service_summary.get("interface").get(i.id, {})
}]
si = list(i.subinterface_set.filter(enabled_afi="BRIDGE"))
......@@ -252,7 +260,8 @@ class ManagedObjectCard(BaseCard):
"duration": now - a.timestamp,
"subject": a.subject,
"managed_object": a.managed_object,
"service_summary": {"service": SummaryItem.items_to_dict(a.total_services), "subscriber": SummaryItem.items_to_dict(a.total_subscribers)},
"service_summary": {"service": SummaryItem.items_to_dict(a.total_services),
"subscriber": SummaryItem.items_to_dict(a.total_subscribers)},
"alarm_class": a.alarm_class
}]
alarm_list = sorted(alarm_list, key=operator.itemgetter("timestamp"))
......@@ -260,9 +269,9 @@ class ManagedObjectCard(BaseCard):
# Maintenance
maintenance = []
for m in Maintenance.objects.filter(
affected_objects__object=self.object.id,
is_completed=False,
start__lte=now + datetime.timedelta(hours=1)
affected_objects__object=self.object.id,
is_completed=False,
start__lte=now + datetime.timedelta(hours=1)
):
maintenance += [{
"maintenance": m,
......@@ -285,7 +294,7 @@ class ManagedObjectCard(BaseCard):
else:
platform = "Unknown"
if self.object.version is not None:
version = self.object.version.version
version = self.object.version.version
else:
version = ""
......@@ -294,8 +303,8 @@ class ManagedObjectCard(BaseCard):
"object": self.object,
"name": self.object.name,
"address": self.object.address,
"platform": platform, #self.object.platform.name if self.object.platform else "Unknown",
"version": version, #self.object.version.version if self.object.version else "",
"platform": platform, # self.object.platform.name if self.object.platform else "Unknown",
"version": version, # self.object.version.version if self.object.version else "",
"description": self.object.description,
"object_profile": self.object.object_profile.id,
"object_profile_name": self.object.object_profile.name,
......@@ -413,28 +422,28 @@ class ManagedObjectCard(BaseCard):
result = "-"
try:
speed = int(speed)
except:
except Exception:
pass
if type_speed == "bit/s":
speed = int(speed)
speed = int(speed)
if speed < 1000 and speed > 0:
result = "%s " % speed
if speed < 1000 and speed > 0:
result = "%s " % speed
for t, n in [(1000000000, "G"), (1000000, "M"), (1000, "k")]:
if speed >= t:
if speed // t * t == speed:
return "%d&nbsp;%s" % (speed // t, n)
else:
return "%.2f&nbsp;%s" % (float(speed) / t, n)
for t, n in [(1000000000, "G"), (1000000, "M"), (1000, "k")]:
if speed >= t:
if speed // t * t == speed:
return "%d&nbsp;%s" % (speed // t, n)
else:
return "%.2f&nbsp;%s" % (float(speed) / t, n)
if type_speed == "bytes":
try:
speed = float(speed)
except:
except Exception:
pass
#speed = speed / 8.0
# speed = speed / 8.0
if speed < 1024:
result = speed
......@@ -451,11 +460,11 @@ class ManagedObjectCard(BaseCard):
if result == speed:
result = speed
return result
@staticmethod
def get_root(_root):
for value in _root:
if value.root != None:
if value.root is not None:
return value.root
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