diff --git a/core/datastream/decorator.py b/core/datastream/decorator.py index 089d91155b94242b7907093c456f2da50869ea93..10284cba6748454a35e5da368b486ea7841d4b91 100644 --- a/core/datastream/decorator.py +++ b/core/datastream/decorator.py @@ -54,7 +54,7 @@ def _on_model_change(sender, instance, *args, **kwargs): def _on_document_change(sender, document, *args, **kwargs): - _on_change(document, changed_fields=document._changed_fields) + _on_change(document, changed_fields=getattr(document, "_changed_fields", {})) def _on_change(obj, changed_fields=None): diff --git a/inv/models/subinterface.py b/inv/models/subinterface.py index 102cc288e17c5037d39fb38148b688e0f90d30d9..c2f7f94c3042c7def3e828fa52b0bdbafde4b974 100644 --- a/inv/models/subinterface.py +++ b/inv/models/subinterface.py @@ -101,6 +101,10 @@ class SubInterface(Document): def iter_changed_datastream(self, changed_fields=None): if config.datastream.enable_managedobject: yield "managedobject", self.managed_object.id + if config.datastream.enable_cfgsyslog and "ipv4_addresses" in changed_fields: + yield "cfgsyslog", self.managed_object.id + if config.datastream.enable_cfgtrap and "ipv4_addresses" in changed_fields: + yield "cfgtrap", self.managed_object.id @property def effective_vc_domain(self): diff --git a/main/models/timepatternterm.py b/main/models/timepatternterm.py index 33a549a7aeb3c923c288e9e5278d9654b8242b31..d4ab14f8751cf35b6c6af9dec0ba357f032bc058 100644 --- a/main/models/timepatternterm.py +++ b/main/models/timepatternterm.py @@ -16,9 +16,13 @@ from django.db import models # NOC modules from noc.core.model.base import NOCModel from noc.lib.timepattern import TimePattern as TP +from noc.core.model.decorator import on_init +from noc.core.datastream.decorator import datastream from .timepattern import TimePattern +@on_init +@datastream @six.python_2_unicode_compatible class TimePatternTerm(NOCModel): """ @@ -53,3 +57,10 @@ class TimePatternTerm(NOCModel): """ TimePatternTerm.check_syntax(self.term) super(TimePatternTerm, self).save(*args, **kwargs) + + def iter_changed_datastream(self, changed_fields=None): + from noc.sa.models.managedobject import ManagedObject + + for mo in ManagedObject.objects.filter(time_pattern=self.time_pattern): + for c in mo.iter_changed_datastream(changed_fields=changed_fields): + yield c diff --git a/sa/models/managedobject.py b/sa/models/managedobject.py index 758a2b6d4a2a1f2863bb9abc69ea62d9b0b0d93e..d311e23ca0386d5751ed2a0170192cada81aad01 100644 --- a/sa/models/managedobject.py +++ b/sa/models/managedobject.py @@ -529,27 +529,27 @@ class ManagedObject(NOCModel): return None def iter_changed_datastream(self, changed_fields=None): - if ( - config.datastream.enable_managedobject - and "managed_object_profile" not in changed_fields - ): + if config.datastream.enable_managedobject: yield "managedobject", self.id if config.datastream.enable_cfgping and changed_fields.intersection( { - "report_ping_rtt", - "enable_ping", - "ping_interval", - "ping_policy", - "ping_size", - "ping_count", - "ping_timeout_ms", - "report_ping_attempts", + "name", + "bi_id", + "is_managed", + "pool", + "address", + "time_pattern", "event_processing_policy", } ): yield "cfgping", self.id if config.datastream.enable_cfgsyslog and changed_fields.intersection( { + "name", + "bi_id", + "is_managed", + "pool", + "address", "event_processing_policy", "syslog_archive_policy", "syslog_source_type", @@ -558,7 +558,16 @@ class ManagedObject(NOCModel): ): yield "cfgsyslog", self.id if config.datastream.enable_cfgtrap and changed_fields.intersection( - {"event_processing_policy", "trap_source_type", "trap_source_ip"} + { + "name", + "bi_id", + "is_managed", + "pool", + "address", + "event_processing_policy", + "trap_source_type", + "trap_source_ip", + } ): yield "cfgtrap", self.id diff --git a/sa/models/managedobjectprofile.py b/sa/models/managedobjectprofile.py index 3279386e4fb130d72104f8727a991ec1724df037..6e3fadc332aa614a2abfa783ba42ada4c04cb0a5 100644 --- a/sa/models/managedobjectprofile.py +++ b/sa/models/managedobjectprofile.py @@ -19,6 +19,7 @@ import cachetools # NOC modules from noc.core.model.base import NOCModel +from noc.config import config from noc.main.models.style import Style from noc.core.stencil import stencil_registry from noc.core.model.fields import TagsField, PickledField, DocumentReferenceField @@ -572,11 +573,42 @@ class ManagedObjectProfile(NOCModel): def iter_changed_datastream(self, changed_fields=None): from noc.sa.models.managedobject import ManagedObject - for mo in ManagedObject.objects.filter(object_profile=self): - for c in mo.iter_changed_datastream( - changed_fields={"managed_object_profile"}.union(changed_fields) + if config.datastream.enable_managedobject and changed_fields.intersection( + {"name", "remote_system", "remote_id"} + ): + for mo_id in ManagedObject.objects.filter(object_profile=self).values_list( + "id", flat=True + ): + yield "managedobject", mo_id + if config.datastream.enable_cfgping and changed_fields.intersection( + { + "enable_ping", + "ping_interval", + "ping_policy", + "ping_size", + "ping_count", + "ping_timeout_ms", + "report_ping_rtt", + "report_ping_attempts", + "event_processing_policy", + } + ): + for mo_id in ManagedObject.objects.filter(object_profile=self).values_list( + "id", flat=True + ): + yield "cfgping", mo_id + if config.datastream.enable_cfgsyslog and changed_fields.intersection( + {"event_processing_policy", "syslog_archive_policy"} + ): + for mo_id in ManagedObject.objects.filter(object_profile=self).values_list( + "id", flat=True + ): + yield "cfgsyslog", mo_id + if config.datastream.enable_cfgtrap and "event_processing_policy" in changed_fields: + for mo_id in ManagedObject.objects.filter(object_profile=self).values_list( + "id", flat=True ): - yield c + yield "cfgtrap", mo_id def iter_pools(self): """ @@ -601,7 +633,6 @@ class ManagedObjectProfile(NOCModel): box_changed=box_changed, periodic_changed=periodic_changed, ) - if access_changed: cache.delete_many( ["cred-%s" % x for x in self.managedobject_set.values_list("id", flat=True)] @@ -669,7 +700,6 @@ def apply_discovery_jobs(profile_id, box_changed, periodic_changed): profile = ManagedObjectProfile.objects.get(id=profile_id) except ManagedObjectProfile.DoesNotExist: return - for mo_id, is_managed, pool in iter_objects(): if box_changed: if profile.enable_box_discovery and is_managed: