Commit b5551126 authored by Andrey Vertiprahov's avatar Andrey Vertiprahov Committed by Юрий Дегтярёв
Browse files

noc/noc#1515 Add Sensor ETL model.

parent bc0615c1
# ----------------------------------------------------------------------
# Sensor loader
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# NOC modules
from .base import BaseLoader
from ..models.sensor import Sensor
from noc.inv.models.object import Object
from noc.inv.models.sensor import Sensor as SensorModel
from noc.pm.models.measurementunits import MeasurementUnits
class SensorLoader(BaseLoader):
"""
Sensor loader
"""
name = "sensor"
model = SensorModel
data_model = Sensor
discard_deferred = True
workflow_event_model = True
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.clean_map["units"] = lambda x: MeasurementUnits.get_by_name(x) if x else None
def find_object(self, v):
"""
Find object by remote system/remote id
:param v:
:return:
"""
r = super().find_object(v)
if not r:
oo = Object.get_managed(v["managed_object"])
find_query = {"local_id": v["local_id"], "object": oo}
r = self.model.objects.filter(**find_query).first()
return r
# ----------------------------------------------------------------------
# SensorModel
# ----------------------------------------------------------------------
# Copyright (C) 2007-2020 The NOC Project
# See LICENSE for details
# ----------------------------------------------------------------------
# Python modules
from typing import Optional, List
# NOC modules
from .base import BaseModel, Reference
from .object import Object
from .managedobject import ManagedObject
class Sensor(BaseModel):
id: str
local_id: str
units: Optional[str]
object: Optional[Reference["Object"]]
managed_object: Reference["ManagedObject"]
# Workflow state
state: Optional[str]
labels: List[str] = []
......@@ -31,6 +31,7 @@ class BaseRemoteSystem(object):
"project",
"managedobject",
"link",
"sensor",
"subscriberprofile",
"subscriber",
"serviceprofile",
......
......@@ -14,7 +14,15 @@ from typing import Dict, Optional, Iterable, List
# Third-party modules
from mongoengine.document import Document
from mongoengine.fields import StringField, IntField, LongField, ListField, DateTimeField, DictField
from mongoengine.fields import (
StringField,
IntField,
LongField,
ListField,
DateTimeField,
DictField,
ReferenceField,
)
import cachetools
# NOC modules
......@@ -22,6 +30,7 @@ from noc.core.wf.decorator import workflow
from noc.core.bi.decorator import bi_sync
from noc.core.mongo.fields import PlainReferenceField, ForeignKeyField
from noc.main.models.label import Label
from noc.main.models.remotesystem import RemoteSystem
from noc.inv.models.object import Object
from noc.sa.models.managedobject import ManagedObject
from noc.pm.models.measurementunits import MeasurementUnits
......@@ -63,7 +72,9 @@ class Sensor(Document):
)
local_id = StringField()
state = PlainReferenceField(State)
units = PlainReferenceField(MeasurementUnits)
units = PlainReferenceField(
MeasurementUnits, default=MeasurementUnits.get_default_measurement_units
)
label = StringField()
dashboard_label = StringField()
# Sources that find sensor
......@@ -79,6 +90,11 @@ class Sensor(Document):
modbus_format = StringField(choices=MODBUS_FORMAT)
snmp_oid = StringField()
ipmi_id = StringField()
# Integration with external NRI and TT systems
# Reference to remote system object has been imported from
remote_system = ReferenceField(RemoteSystem)
# Object id in remote system
remote_id = StringField()
bi_id = LongField(unique=True)
# Labels
labels = ListField(StringField())
......
......@@ -61,6 +61,7 @@ class EnvItem(EmbeddedDocument):
("inv.NetworkSegment", "remote_system"),
("inv.NetworkSegmentProfile", "remote_system"),
("inv.ResourceGroup", "remote_system"),
("inv.Sensor", "remote_system"),
("inv.Object", "remote_system"),
("ip.AddressProfile", "remote_system"),
("ip.PrefixProfile", "remote_system"),
......@@ -105,6 +106,7 @@ class RemoteSystem(Document):
enable_networksegment = BooleanField()
enable_networksegmentprofile = BooleanField()
enable_object = BooleanField()
enable_sensor = BooleanField()
enable_service = BooleanField()
enable_serviceprofile = BooleanField()
enable_street = BooleanField()
......
......@@ -118,6 +118,11 @@ Ext.define("NOC.main.remotesystem.Application", {
xtype: "checkbox",
boxLabel: __("Object")
},
{
name: "enable_sensor",
xtype: "checkbox",
boxLabel: __("Sensor")
},
{
name: "enable_service",
xtype: "checkbox",
......
......@@ -80,6 +80,10 @@ Ext.define("NOC.main.remotesystem.Model", {
name: "enable_object",
type: "boolean"
},
{
name: "enable_sensor",
type: "boolean"
},
{
name: "enable_service",
type: "boolean"
......
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