class ValueChangeThresholdInstance(MetricThresholdInstance):
    """
    Threshold that emits an event when a value changes from its previous value. Does not send clear events.
    """

    lastValues = Map.Locked(Map.Timed({}, 60 * 60 * 24))  # 24-hour timeout

    def _checkImpl(self, dataPoint, value):
        dpKey = self._getDpKey(dataPoint)
        lastValue = ValueChangeThresholdInstance.lastValues.get(dpKey, None)
        # get also updates the access time, so only set if the value changes.
        if lastValue != value:
            # Update the value in the map.
            ValueChangeThresholdInstance.lastValues[dpKey] = value
            # .. Only create a change event if this isn't the first collection
            if lastValue != None:
                event = dict(device=self.context().deviceName,
                             summary="Value changed from %s to %s" %
                             (lastValue, value),
                             eventKey=self.id,
                             eventClass=self.eventClass,
                             component=self.context().componentName,
                             current=value,
                             previous=lastValue,
                             severity=self.severity)
                return (event, )
        return tuple()

    def _getDpKey(self, dp):
        return ':'.join(self.context().key()) + ':' + dp

    def getGraphValues(self, relatedGps, context):
        # currently, no visualization implemented for this threshold type
        return ()
Esempio n. 2
0

def manage_addRenderServer(context, id, REQUEST = None):
    """
    Make a RenderServer
    """
    rs = RenderServer(id)
    context._setObject(id, rs)
    if REQUEST is not None:
        REQUEST['RESPONSE'].redirect(context.absolute_url()+'/manage_main')


addRenderServer = DTMLFile('dtml/addRenderServer',globals())

DEFAULT_TIMEOUT=300
_cache = Map.Locked(Map.Timed({}, DEFAULT_TIMEOUT))


class RenderServer(RRDToolItem):
    """
    Base class for turning graph requests into graphics.
    NB: Any log messages get logged into the event.log file.
    """

    meta_type = "RenderServer"

    cacheName = 'RRDRenderCache'

    security = ClassSecurityInfo()

    def __init__(self, id, tmpdir = '/tmp/renderserver', cachetimeout=DEFAULT_TIMEOUT):
Esempio n. 3
0
import json
import logging
from datetime import datetime
from dateutil.relativedelta import relativedelta
log = logging.getLogger("zen.MetricMixin")

from Acquisition import aq_chain
from Products.ZenUtils import Map
from Products.ZenUtils.metrics import SEPARATOR_CHAR
from Products.ZenWidgets import messaging
from Products.ZenUtils.guid.interfaces import IGlobalIdentifier
from Products.Zuul import getFacade

CACHE_TIME = 60.

_cache = Map.Locked(Map.Timed({}, CACHE_TIME))


class MetricMixin(object):
    """
    Mixin to provide hooks to metric service management functions
    """
    def cacheValue(self, dsname, default="Unknown"):
        """
        Cache metric values for up to CACHE_TIME(60) seconds.
        """
        cacheKey = self.getCacheKey(dsname)
        try:
            value = _cache[cacheKey]
        except KeyError:
            try:
Esempio n. 4
0
from twisted.web.http_headers import Headers

import Products.ZenUtils.Map as Map

import Globals
import logging
import sys
from os import environ
import time
# generate random integer values
from random import seed
from random import randint
# seed random number generator
seed(1)

_repRate = Map.Timed({}, 1)
rateLimit = 10      # 10 per timeout specified in Map.Timed() above
agent = Agent(reactor)

if 'DEBUGUT' in environ:
    zlog = logging.getLogger("zen")
    zlog.setLevel(10)
    stream_handler = logging.StreamHandler(sys.stdout)
    formatter = logging.Formatter("%(asctime)s %(levelname)s %(name)s %(message)s")
    stream_handler.setFormatter(formatter)
    zlog.addHandler(stream_handler)


class eDeferredQueue(defer.DeferredQueue):

    def get(self):