Esempio n. 1
0
    def testAgentConfigurationRetrieving(self):
        """
        Test that getting some agent details (config values from config.Agent
        section) will be correctly propagated into Alert instances.
        Alert instance is obtained via API.getPredefinedAlert factory.

        """
        d = dict(Additional = "detail")
        # instantiate just plain Alert, no configuration to take
        # into account at this point
        a = Alert(**d)
        self.assertEqual(a["HostName"], None)
        self.assertEqual(a["Contact"], None)
        self.assertEqual(a["TeamName"], None)
        self.assertEqual(a["AgentName"], None)
        self.assertEqual(a["Additional"], "detail")
        # instantiate via factory which reads configuration instance
        config = Configuration()
        config.section_("Agent")
        config.Agent.hostName = "some1"
        config.Agent.contact = "some2"
        config.Agent.teamName = "some3"
        config.Agent.agentName = "some4"
        a = alertAPI.getPredefinedAlert(**d)
        self.assertEqual(a["HostName"], "some1")
        self.assertEqual(a["Contact"], "some2")
        self.assertEqual(a["TeamName"], "some3")
        self.assertEqual(a["AgentName"], "some4")
        self.assertEqual(a["Additional"], "detail")
Esempio n. 2
0
 def __init__(self, config, generator):
     threading.Thread.__init__(self)
     # it's particular Poller config only
     self.config = config
     # reference to AlertGenerator instance
     self.generator = generator
     # store levels (critical, soft) for critical, soft thresholds correspondence
     # these values are defined in the AlertProcessor config
     # self.levels and self.thresholds has to have the same corresponding order
     # and critical has to be first - if this threshold is caught, no point
     # testing soft one
     # this belongs to the AlertGenerator and is in fact dependent on AlertProcessor
     # by referencing these two values - not sure if to tolerate such dependecy or
     # configure these two values independently in AlertGenerator itself (surely a
     # possible mismatch would make a bit of chaos)
     self.levels = [self.generator.config.AlertProcessor.critical.level,
                    self.generator.config.AlertProcessor.soft.level]
     
     # critical, soft threshold values
     self.thresholds = [self.config.critical, self.config.soft]
     
     # pre-generated alert values, but before sending always new instance is created
     # these values are used to update the newly created instance
     dictAlert = dict(Type = "WMAgent",
                      Workload = "n/a",
                      Component = self.generator.__class__.__name__,
                      Source = "<to_overwrite>")
     self.preAlert = alertAPI.getPredefinedAlert(**dictAlert)
     # flag controlling run of the Thread
     self._stopFlag = False
     # thread own sleep time
     self._threadSleepTime = 0.2 # seconds
Esempio n. 3
0
    def __init__(self, config, generator):
        threading.Thread.__init__(self)
        # it's particular Poller config only
        self.config = config
        # reference to AlertGenerator instance
        self.generator = generator
        # store levels (critical, soft) for critical, soft thresholds correspondence
        # these values are defined in the AlertProcessor config
        # self.levels and self.thresholds has to have the same corresponding order
        # and critical has to be first - if this threshold is caught, no point
        # testing soft one
        # this belongs to the AlertGenerator and is in fact dependent on AlertProcessor
        # by referencing these two values - not sure if to tolerate such dependecy or
        # configure these two values independently in AlertGenerator itself (surely a
        # possible mismatch would make a bit of chaos)
        self.levels = [
            self.generator.config.AlertProcessor.critical.level,
            self.generator.config.AlertProcessor.soft.level
        ]

        # critical, soft threshold values
        self.thresholds = [self.config.critical, self.config.soft]

        # pre-generated alert values, but before sending always new instance is created
        # these values are used to update the newly created instance
        dictAlert = dict(Type="WMAgent",
                         Workload="n/a",
                         Component=self.generator.__class__.__name__,
                         Source="<to_overwrite>")
        self.preAlert = alertAPI.getPredefinedAlert(**dictAlert)
        # flag controlling run of the Thread
        self._stopFlag = False
        # thread own sleep time
        self._threadSleepTime = 0.2  # seconds
Esempio n. 4
0
    def testAgentConfigurationRetrieving(self):
        """
        Test that getting some agent details (config values from config.Agent
        section) will be correctly propagated into Alert instances.
        Alert instance is obtained via API.getPredefinedAlert factory.

        """
        d = dict(Additional="detail")
        # instantiate just plain Alert, no configuration to take
        # into account at this point
        a = Alert(**d)
        self.assertEqual(a["HostName"], None)
        self.assertEqual(a["Contact"], None)
        self.assertEqual(a["TeamName"], None)
        self.assertEqual(a["AgentName"], None)
        self.assertEqual(a["Additional"], "detail")
        # instantiate via factory which reads configuration instance
        config = Configuration()
        config.section_("Agent")
        config.Agent.hostName = "some1"
        config.Agent.contact = "some2"
        config.Agent.teamName = "some3"
        config.Agent.agentName = "some4"
        a = alertAPI.getPredefinedAlert(**d)
        self.assertEqual(a["HostName"], "some1")
        self.assertEqual(a["Contact"], "some2")
        self.assertEqual(a["TeamName"], "some3")
        self.assertEqual(a["AgentName"], "some4")
        self.assertEqual(a["Additional"], "detail")
Esempio n. 5
0
 def __init__(self, config, generator):
     # it's particular Poller config only
     self.config = config
     # reference to AlertGenerator instance
     self.generator = generator
     # store levels (critical, soft) for critical, soft thresholds correspondence
     # these values are defined in the AlertProcessor config
     # self.levels and self.thresholds has to have the same corresponding order
     # and critical has to be first - if this threshold is caught, no point testing soft one
     self.levels = [self.generator.config.AlertProcessor.critical.level,
                    self.generator.config.AlertProcessor.soft.level]
     # critical, soft threshold values
     self.thresholds = [self.config.critical, self.config.soft]
     
     # pre-generated alert values, but before sending always new instance is created
     # these values are used to update the newly created instance
     dictAlert = dict(Type = "WMAgent",
                      Workload = "n/a",
                      Component = self.generator.__class__.__name__,
                      Source = "<to_overwrite>")
     self.preAlert = alertAPI.getPredefinedAlert(**dictAlert) 
Esempio n. 6
0

import sys
import time

from WMCore.Alerts import API as alertAPI
from WMCore.Alerts.Alert import Alert
from WMCore.Alerts.ZMQ.Sender import Sender

machine = "maxatest.cern.ch"

target = "tcp://%s:6557" % machine
targetController = "tcp://%s:6559" % machine
if len(sys.argv) > 2:
    target = sys.argv[1]
    targetController = sys.argv[2]

dictAlert = dict(Type="AlertTestClient", Workload="n/a", Component=__name__, Source=__name__)
preAlert = alertAPI.getPredefinedAlert(**dictAlert)
sender = Sender(target, targetController, "AlertTestClient")
print ("created Sender client for alerts target: %s  controller: %s" % (target, targetController))


sender.register()
a = Alert(**preAlert)
a["Timestamp"] = time.time()
a["Level"] = 6
print "sending alert:\n'%s'" % a
sender(a)
sender.unregister()
Esempio n. 7
0
import time

from WMCore.Alerts import API as alertAPI
from WMCore.Alerts.Alert import Alert
from WMCore.Alerts.ZMQ.Sender import Sender

machine = "maxatest.cern.ch"

target = "tcp://%s:6557" % machine
targetController = "tcp://%s:6559" % machine
if len(sys.argv) > 2:
    target = sys.argv[1]
    targetController = sys.argv[2]

dictAlert = dict(Type="AlertTestClient",
                 Workload="n/a",
                 Component=__name__,
                 Source=__name__)
preAlert = alertAPI.getPredefinedAlert(**dictAlert)
sender = Sender(target, targetController, "AlertTestClient")
print("created Sender client for alerts target: %s  controller: %s" %
      (target, targetController))

sender.register()
a = Alert(**preAlert)
a["Timestamp"] = time.time()
a["Level"] = 6
print "sending alert:\n'%s'" % a
sender(a)
sender.unregister()