예제 #1
0
 def message_user(self, request, message):
     """
     Send a message to user
     """
     if "noc_user" in request.COOKIES:
         session_id = request.COOKIES["noc_user"].rsplit("|", 1)[-1]
         key = "msg-%s" % session_id
         cache.set(key, ujson.dumps([message]), ttl=30, version=1)
예제 #2
0
 def __init__(self, ids, cache_key=None, ignore_profiles=None):
     self.ids = ids
     self.ignore_profiles = ignore_profiles
     if cache_key:
         self.out = cache.get(key=cache_key)
         if not self.out:
             self.out = self.load(self.ids, self.ignore_profiles)
             cache.set(cache_key, self.out, ttl=28800)
     else:
         self.out = self.load(self.ids, self.ignore_profiles)
예제 #3
0
 def dispose_event(self, event):
     self.logger.info("[%s|%s|%s] Disposing", event.id,
                      event.managed_object.name,
                      event.managed_object.address)
     # Heat up cache
     cache.set("activeent-%s" % event.id, event, ttl=900)
     # @todo: Use config.pool instead
     self.pub("correlator.dispose.%s" % event.managed_object.pool.name, {
         "event_id": str(event.id),
         "event": event.to_json()
     })
     metrics[CR_DISPOSED] += 1
예제 #4
0
파일: views.py 프로젝트: nbashev/noc
 def __init__(self,
              ids,
              cache_key=None,
              ignore_profiles=None,
              filter_exists_link=False):
     self.ids = ids
     self.ignore_profiles = ignore_profiles
     self.filter_exists_link = filter_exists_link
     if cache_key:
         self.out = cache.get(key=cache_key)
         if not self.out:
             self.out = self.load(self.ids, self.ignore_profiles,
                                  self.filter_exists_link)
             cache.set(cache_key, self.out, ttl=28800)
     else:
         self.out = self.load(self.ids, self.ignore_profiles,
                              self.filter_exists_link)
예제 #5
0
 def cached_neighbors(self, mo, key, iter_neighbors):
     """
     Cache iter_neighbors results according to profile settings
     :param mo:
     :param key:
     :param iter_neighbors:
     :return:
     """
     ttl = mo.object_profile.neighbor_cache_ttl
     if not ttl:
         # Disabled cache
         metrics["neighbor_cache_misses"] += 1
         neighbors = iter_neighbors(mo)
         if isinstance(neighbors, types.GeneratorType):
             neighbors = list(iter_neighbors(mo))
         return neighbors
     # Cached version
     neighbors = cache.get(key, version=self.NEIGHBOR_CACHE_VERSION)
     self.logger.debug("Use neighbors cache")
     if neighbors is None:
         neighbors = iter_neighbors(mo)
         if isinstance(neighbors, types.GeneratorType):
             neighbors = list(iter_neighbors(mo))
         cache.set(key,
                   neighbors,
                   ttl=ttl,
                   version=self.NEIGHBOR_CACHE_VERSION)
         if self.interface_aliases:
             alias_cache = {(mo.id, n[0]):
                            self.interface_aliases[(mo.id, n[0])]
                            for n in neighbors
                            if (mo.id, n[0]) in self.interface_aliases}
             cache.set("%s-aliases" % key,
                       alias_cache,
                       ttl=ttl,
                       version=self.NEIGHBOR_CACHE_VERSION)
         metrics["neighbor_cache_misses"] += 1
     else:
         alias_cache = cache.get("%s-aliases" % key,
                                 version=self.NEIGHBOR_CACHE_VERSION)
         self.logger.debug("Alias cache is %s", alias_cache)
         if alias_cache:
             self.interface_aliases.update(alias_cache)
         metrics["neighbor_cache_hits"] += 1
     return neighbors