Beispiel #1
0
class TestInternalMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "1"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.daemon._internal_publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteInternalMetric(self):
        metric = ["name", 0.0, "now", {}]
        internal_metric = ["name", 0.0, "now", {"internal": True}]
        self.metric_writer.write_metric(*metric)
        self.metric_writer.write_metric(*internal_metric)
        self.assertEquals([tuple(internal_metric)],
                          self.daemon._internal_publisher.queue)
        self.assertEquals(
            [tuple(metric), tuple(internal_metric)],
            self.daemon._publisher.queue)

    def testInternalPublisherIsNone(self):
        self.daemon._internal_publisher = None
        del os.environ["CONTROLPLANE_CONSUMER_URL"]
        self.assertIsNone(self.daemon.internalPublisher())

    def testInternalPublisherIsInstance(self):
        self.daemon._internal_publisher = None
        os.environ["CONTROLPLANE_CONSUMER_URL"] = "http://localhost"
        publisher = self.daemon.internalPublisher()
        from Products.ZenHub.metricpublisher.publisher import HttpPostPublisher
        self.assertIsInstance(publisher, HttpPostPublisher)
class TestInternalMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "1"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.daemon._internal_publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteInternalMetric(self):
        metric = ["name", 0.0, "now", {}]
        internal_metric = ["name", 0.0, "now", {"internal": True}]
        self.metric_writer.write_metric(*metric)
        self.metric_writer.write_metric(*internal_metric)
        self.assertEquals([tuple(internal_metric)], self.daemon._internal_publisher.queue)
        self.assertEquals([tuple(metric), tuple(internal_metric)], self.daemon._publisher.queue)

    def testInternalPublisherIsNone(self):
        self.daemon._internal_publisher = None
        del os.environ["CONTROLPLANE_CONSUMER_URL"]
        self.assertIsNone(self.daemon.internalPublisher())

    def testInternalPublisherIsInstance(self):
        self.daemon._internal_publisher = None
        os.environ["CONTROLPLANE_CONSUMER_URL"] = "http://localhost"
        publisher = self.daemon.internalPublisher()
        from Products.ZenHub.metricpublisher.publisher import HttpPostPublisher

        self.assertIsInstance(publisher, HttpPostPublisher)
 def buildOptions(self):
     PBDaemon.buildOptions(self)
     self.parser.add_option('--statcycle',
                            dest='statcycle',
                            type='int',
                            help='Number of seconds between the writing of statistics',
                            default=0)
Beispiel #4
0
 def buildOptions(self):
     PBDaemon.buildOptions(self)
     self.parser.add_option(
         '--statcycle',
         dest='statcycle',
         type='int',
         help='Number of seconds between the writing of statistics',
         default=0)
 def buildOptions(self):
     """
     Command-line options to add
     """
     PBDaemon.buildOptions(self)
     self.parser.add_option('-d', '--device',
                            dest='device',
                            default='',
                            help="Specify a device ID to monitor")
Beispiel #6
0
 def buildOptions(self):
     """
     Build our list of command-line options
     """
     PBDaemon.buildOptions(self)
     self.parser.add_option('--debug',
             dest='debug', action="store_true", default=False,
             help="Don't fork threads for processing")
     self.parser.add_option('--nowmi',
             dest='nowmi', action="store_true", default=not USE_WMI,
             help="Do not execute WMI plugins")
     self.parser.add_option('--parallel', dest='parallel',
             type='int', default=defaultParallel,
             help="Number of devices to collect from in parallel")
     self.parser.add_option('--cycletime',
             dest='cycletime', type='int',
             help="Run collection every x minutes")
     self.parser.add_option('--ignore',
             dest='ignorePlugins',default="",
             help="Modeler plugins to ignore. Takes a regular expression")
     self.parser.add_option('--collect',
             dest='collectPlugins',default="",
             help="Modeler plugins to use. Takes a regular expression")
     self.parser.add_option('-p', '--path', dest='path',
             help="Start class path for collection ie /NetworkDevices")
     self.parser.add_option('-d', '--device', dest='device',
             help="Fully qualified device name ie www.confmon.com")
     self.parser.add_option('--startat', dest='startat',
             help="Start string in cron(8) format")
     self.parser.add_option('-a', '--collage',
             dest='collage', default=0, type='float',
             help="Do not collect from devices whose collect date " +
                     "is within this many minutes")
     self.parser.add_option('--writetries',
             dest='writetries',default=2,type='int',
             help="Number of times to try to write if a "
                  "read conflict is found")
     # FIXME: cleanup --force option #2660
     self.parser.add_option("-F", "--force",
                 dest="force", action='store_true', default=True,
                 help="Force collection of config data (deprecated)")
     self.parser.add_option('--portscantimeout', dest='portscantimeout',
             type='int', default=defaultPortScanTimeout,
             help="Time to wait for connection failures when port scanning")
     self.parser.add_option('--now',
             dest='now', action="store_true", default=False,
             help="Start daemon now, do not sleep before starting")
     self.parser.add_option('--communities',
             dest='discoverCommunity', action="store_true", default=False,
             help="If an snmp connection fails try and rediscover it's connection info")
     self.parser.add_option('--checkstatus',
             dest='checkStatus', action="store_true", default=False,
             help="Don't model if the device is ping or snmp down")
     TCbuildOptions(self.parser, self.usage)
     if USE_WMI:
         addNTLMv2Option(self.parser)
Beispiel #7
0
    def __init__(self, single=False):
        """
        Initalizer

        @param single: collect from a single device?
        @type single: boolean
        """
        PBDaemon.__init__(self)
        # FIXME: cleanup --force option #2660
        self.options.force = True
        self.start = None
        self.startat = None
        self.rrdStats = DaemonStats()
        self.single = single
        if self.options.device:
            self.single = True
        self.modelerCycleInterval = self.options.cycletime
        # get the minutes and convert to fraction of a day
        self.collage = float(self.options.collage) / 1440.0
        self.pendingNewClients = False
        self.clients = []
        self.finished = []
        self.devicegen = None
        self.counters = collections.Counter()
        self.configFilter = None
        self.configLoaded = False

        # Make sendEvent() available to plugins
        zope.component.provideUtility(self, IEventService)

        # Delay start for between 10 and 60 seconds when run as a daemon.
        self.started = False
        self.startDelay = 0
        self.immediate = 1
        if self.options.daemon or self.options.cycle:
            if self.options.now:
                self.log.debug('option "now" specified, starting immediately.')
            else:
                # self.startDelay = randint(10, 60) * 60
                self.startDelay = randint(10, 60) * 1
                self.immediate = 0
                self.log.info(
                    'option "now" not specified, waiting %s seconds to start.'
                    % self.startDelay)
        else:
            self.log.debug("Run in foreground, starting immediately.")

        # ZEN-26637
        self.collectorLoopIteration = 0
        self.mainLoopGotDeviceList = False

        self.isMainScheduled = False

        self._modeledDevicesMetric = Metrology.meter(
            "zenmodeler.modeledDevices")
        self._failuresMetric = Metrology.counter("zenmodeler.failures")
Beispiel #8
0
 def buildOptions(self):
     """
     Command-line options to add
     """
     PBDaemon.buildOptions(self)
     self.parser.add_option('-d',
                            '--device',
                            dest='device',
                            default='',
                            help="Specify a device ID to monitor")
Beispiel #9
0
 def heartbeat(self):
     """Since we don't do anything on a regular basis, just
     push heartbeats regularly"""
     seconds = self.heartbeatTimeout / 3
     reactor.callLater(self.heartbeatTimeout / 3, self.heartbeat)
     PBDaemon.heartbeat(self)
     totalTime, totalEvents, maxTime = self.stats.report()
     for ev in (self.rrdStats.counter('events', seconds, totalEvents) +
                self.rrdStats.counter('totalTime', seconds,
                                      int(totalTime * 1000))):
         self.sendEvent(ev)
Beispiel #10
0
    def __init__(self, name, noopts=False):
        """
        Initializer

        @param name: name of the daemon
        @type name: string
        @param noopts: process command-line arguments?
        @type noopts: boolean
        """
        self.events = []
        PBDaemon.__init__(self, noopts, name=name)
        self.thresholds = Thresholds()
Beispiel #11
0
    def __init__(self, single=False ):
        """
        Initalizer

        @param single: collect from a single device?
        @type single: boolean
        """
        PBDaemon.__init__(self)
        # FIXME: cleanup --force option #2660
        self.options.force = True
        self.start = None
        self.startat = None
        self.rrdStats = DaemonStats()
        self.single = single
        if self.options.device:
            self.single = True
        self.modelerCycleInterval = self.options.cycletime
        # get the minutes and convert to fraction of a day
        self.collage = float( self.options.collage ) / 1440.0
        self.pendingNewClients = False
        self.clients = []
        self.finished = []
        self.devicegen = None
        self.counters = collections.Counter()
        self.configFilter = None
        self.configLoaded = False

        # Make sendEvent() available to plugins
        zope.component.provideUtility(self, IEventService)

        # Delay start for between 10 and 60 seconds when run as a daemon.
        self.started = False
        self.startDelay = 0
        self.immediate = 1
        if self.options.daemon or self.options.cycle:
            if self.options.now:
                self.log.debug('option "now" specified, starting immediately.')
            else:
                # self.startDelay = randint(10, 60) * 60
                self.startDelay = randint(10, 60) * 1
                self.immediate = 0
                self.log.info('option "now" not specified, waiting %s seconds to start.' %
                              self.startDelay)
        else:
            self.log.debug("Run in foreground, starting immediately.")


        # ZEN-26637
        self.collectorLoopIteration = 0
        self.mainLoopGotDeviceList = False

        self._modeledDevicesMetric = Metrology.meter("zenmodeler.modeledDevices")
        self._failuresMetric = Metrology.counter("zenmodeler.failures")
    def __init__(self, name, noopts=False):
        """
        Initializer

        @param name: name of the daemon
        @type name: string
        @param noopts: process command-line arguments?
        @type noopts: boolean
        """
        self.events = []
        PBDaemon.__init__(self, noopts, name=name)
        self.thresholds = Thresholds()
 def heartbeat(self):
     """Since we don't do anything on a regular basis, just
     push heartbeats regularly"""
     seconds = self.heartbeatTimeout / 3
     reactor.callLater(self.heartbeatTimeout / 3, self.heartbeat)
     PBDaemon.heartbeat(self)
     totalTime, totalEvents, maxTime = self.stats.report()
     for ev in (self.rrdStats.counter('events',
                                      seconds,
                                      totalEvents) +
                self.rrdStats.counter('totalTime',
                                      seconds,
                                      int(totalTime * 1000))):
         self.sendEvent(ev)
Beispiel #14
0
    def __init__(self, single=False):
        """
        Initalizer

        @param single: collect from a single device?
        @type single: boolean
        """
        PBDaemon.__init__(self)
        # FIXME: cleanup --force option #2660
        self.options.force = True
        self.start = None
        self.startat = None
        self.rrdStats = DaemonStats()
        self.single = single
        if self.options.device:
            self.single = True
        self.modelerCycleInterval = self.options.cycletime
        self.collage = float(self.options.collage) / 1440.0
        self.pendingNewClients = False
        self.clients = []
        self.finished = []
        self.devicegen = None
        self.counters = collections.Counter()

        # Make sendEvent() available to plugins
        zope.component.provideUtility(self, IEventService)

        # Delay start for between 10 and 60 seconds when run as a daemon.
        self.started = False
        self.startDelay = 0
        self.immediate = 1
        if self.options.daemon:
            if self.options.now:
                self.log.debug("Run as a daemon, starting immediately.")
            else:
                # self.startDelay = randint(10, 60) * 60
                self.startDelay = randint(10, 60) * 1
                self.immediate = 0
                self.log.info("Run as a daemon, waiting %s seconds to start." %
                              self.startDelay)
        else:
            self.log.debug("Run in foreground, starting immediately.")

        # load performance counters
        self.loadCounters()
Beispiel #15
0
    def __init__(self, single=False ):
        """
        Initalizer

        @param single: collect from a single device?
        @type single: boolean
        """
        PBDaemon.__init__(self)
        # FIXME: cleanup --force option #2660
        self.options.force = True
        self.start = None
        self.startat = None
        self.rrdStats = DaemonStats()
        self.single = single
        if self.options.device:
            self.single = True
        self.modelerCycleInterval = self.options.cycletime
        self.collage = float( self.options.collage ) / 1440.0
        self.pendingNewClients = False
        self.clients = []
        self.finished = []
        self.devicegen = None
        self.counters = collections.Counter()

        # Make sendEvent() available to plugins
        zope.component.provideUtility(self, IEventService)

        # Delay start for between 10 and 60 seconds when run as a daemon.
        self.started = False
        self.startDelay = 0
        self.immediate = 1
        if self.options.daemon:
            if self.options.now:
                self.log.debug("Run as a daemon, starting immediately.")
            else:
                # self.startDelay = randint(10, 60) * 60
                self.startDelay = randint(10, 60) * 1
                self.immediate = 0
                self.log.info("Run as a daemon, waiting %s seconds to start." %
                              self.startDelay)
        else:
            self.log.debug("Run in foreground, starting immediately.")

        # load performance counters
        self.loadCounters()
Beispiel #16
0
class TestMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "0"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteMetric(self):
        metric = ["name", 0.0, "now", {}]
        self.metric_writer.write_metric(*metric)
        self.assertEquals([tuple(metric)], self.daemon._publisher.queue)
Beispiel #17
0
class TestMetricWriter(BaseTestCase):
    def setUp(self):
        os.environ["CONTROLPLANE"] = "0"
        self.daemon = PBDaemon()
        self.daemon._publisher = Publisher()
        self.metric_writer = self.daemon.metricWriter()

    def testWriteMetric(self):
        metric = ["name", 0.0, "now", {}]
        self.metric_writer.write_metric(*metric)
        self.assertEquals([tuple(metric)], self.daemon._publisher.queue)
Beispiel #18
0
 def buildOptions(self):
     """
     stores the command-line/config file options
     """
     PBDaemon.buildOptions(self)
     self.parser.add_option('-a', '--app',
         dest='singleInstance',
         default=None,
         help="single GAE App to collect from")
     self.parser.add_option('--debug',
         dest='debug',
         default=False,
         action='store_true',
         help="turn on additional debugging")
     self.parser.add_option('--configCycleInterval',
         dest='configCycleInterval',
         default=60 * 4,  # EVERY 4 HOURS
         type='int',
         help="Period between modeling in minutes")
     self.parser.add_option('--showHttp',
         dest='showHttp',
         action='store_true',
         help="Show all http interactions")
Beispiel #19
0
 def __init__(self):
     PBDaemon.__init__(self)
     self.instanceInventory = []
     self.modelRunning = False
 def sendEvent(self, event, **kw):
     # FIXME: get real event processing stats
     if 'firstTime' in event:
         self.stats.add(min(time.time() - event['firstTime'], 0))
     PBDaemon.sendEvent(self, event, **kw)
Beispiel #21
0
    def buildOptions(self):
        """
        Build our list of command-line options
        """
        PBDaemon.buildOptions(self)
        self.parser.add_option('--debug',
                               dest='debug',
                               action="store_true",
                               default=False,
                               help="Don't fork threads for processing")
        self.parser.add_option('--nowmi',
                               dest='nowmi',
                               action="store_true",
                               default=not USE_WMI,
                               help="Do not execute WMI plugins")
        self.parser.add_option(
            '--parallel',
            dest='parallel',
            type='int',
            default=defaultParallel,
            help="Number of devices to collect from in parallel")
        self.parser.add_option('--cycletime',
                               dest='cycletime',
                               type='int',
                               help="Run collection every x minutes")
        self.parser.add_option(
            '--ignore',
            dest='ignorePlugins',
            default="",
            help="Modeler plugins to ignore. Takes a regular expression")
        self.parser.add_option(
            '--collect',
            dest='collectPlugins',
            default="",
            help="Modeler plugins to use. Takes a regular expression")
        self.parser.add_option(
            '-p',
            '--path',
            dest='path',
            help="Start class path for collection ie /NetworkDevices")
        self.parser.add_option(
            '-d',
            '--device',
            dest='device',
            help="Fully qualified device name ie www.confmon.com")
        self.parser.add_option('--startat',
                               dest='startat',
                               help="Start string in cron(8) format")
        self.parser.add_option(
            '-a',
            '--collage',
            dest='collage',
            default=0,
            type='float',
            help="Do not collect from devices whose collect date " +
            "is within this many minutes")
        self.parser.add_option('--writetries',
                               dest='writetries',
                               default=2,
                               type='int',
                               help="Number of times to try to write if a "
                               "read conflict is found")
        # FIXME: cleanup --force option #2660
        self.parser.add_option(
            "-F",
            "--force",
            dest="force",
            action='store_true',
            default=True,
            help="Force collection of config data (deprecated)")
        self.parser.add_option(
            '--portscantimeout',
            dest='portscantimeout',
            type='int',
            default=defaultPortScanTimeout,
            help="Time to wait for connection failures when port scanning")
        self.parser.add_option(
            '--now',
            dest='now',
            action="store_true",
            default=False,
            help="Start daemon now, do not sleep before starting")
        self.parser.add_option(
            '--communities',
            dest='discoverCommunity',
            action="store_true",
            default=False,
            help=
            "If an snmp connection fails try and rediscover it's connection info"
        )
        self.parser.add_option(
            '--checkstatus',
            dest='checkStatus',
            action="store_true",
            default=False,
            help="Don't model if the device is ping or snmp down")

        self.parser.add_option(
            '--save_raw_results',
            dest='save_raw_results',
            action="store_true",
            default=False,
            help="Save raw results for replay purposes in /tmp")
        self.parser.add_option(
            '--save_processed_results',
            dest='save_processed_results',
            action="store_true",
            default=False,
            help="Save modeler plugin outputs for replay purposes in /tmp")

        addWorkerOptions(self.parser)

        TCbuildOptions(self.parser, self.usage)
        if USE_WMI:
            addNTLMv2Option(self.parser)
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))

        password = self.options.jabber_pass
        chatrooms = self.options.chatrooms
        username = self.options.jabber_user
        server = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        resource = self.options.resource

        self.client = TwistedJabberClient(server=server, username=username, password=password,
                                 port=port,
                                 groupServer=groupServer,
                                 chatrooms=chatrooms, ssl=wants_ssl,
                                 realHost=realHost, resource=resource)

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]

        self.log.debug("xmppBot loading pugins  %s" % ', '.join(plugins))
        initPluginSystem(pluginPath=pluginPath, plugins=plugins, jabberClient=self.client)

        # connect to the jabber server
        self.log.info('Connecting to server')
        reactor = self.client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        reactor.suggestThreadPoolSize(10)
        reactor.run()
Beispiel #23
0
 def setUp(self):
     os.environ["CONTROLPLANE"] = "1"
     self.daemon = PBDaemon()
     self.daemon._publisher = Publisher()
     self.daemon._internal_publisher = Publisher()
     self.metric_writer = self.daemon.metricWriter()
Beispiel #24
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error(
                'SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.'
            )
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error(
                    '--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]'
                )
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error(
                    '--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]'
                )
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(
            Event.Event(device=self.options.monitor,
                        eventClass=App_Start,
                        summary='Jabber Bot started',
                        severity=0,
                        component='xmppbot'))

        password = self.options.jabber_pass
        chatrooms = self.options.chatrooms
        username = self.options.jabber_user
        server = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        resource = self.options.resource

        self.client = TwistedJabberClient(server=server,
                                          username=username,
                                          password=password,
                                          port=port,
                                          groupServer=groupServer,
                                          chatrooms=chatrooms,
                                          ssl=wants_ssl,
                                          realHost=realHost,
                                          resource=resource)

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [
            pluginFile.split('/')[-1].split('.py')[0]
            for pluginFile in glob.glob(os.path.join(pluginPath, '*.py'))
        ]

        self.log.debug("xmppBot loading pugins  %s" % ', '.join(plugins))
        initPluginSystem(pluginPath=pluginPath,
                         plugins=plugins,
                         jabberClient=self.client)

        # connect to the jabber server
        self.log.info('Connecting to server')
        reactor = self.client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        reactor.suggestThreadPoolSize(10)
        reactor.run()
Beispiel #25
0
 def __init__(self):
     PBDaemon.__init__(self, keeproot=True)
     self.stats = Stats()
     self.rrdStats = DaemonStats()
Beispiel #26
0
 def sendEvent(self, event, **kw):
     # FIXME: get real event processing stats
     if 'firstTime' in event:
         self.stats.add(min(time.time() - event['firstTime'], 0))
     PBDaemon.sendEvent(self, event, **kw)
Beispiel #27
0
 def setUp(self):
     os.environ["CONTROLPLANE"] = "1"
     self.daemon = PBDaemon()
     self.daemon._publisher = Publisher()
     self.daemon._internal_publisher = Publisher()
     self.metric_writer = self.daemon.metricWriter()
Beispiel #28
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)
                
            if zenUser and jabberId:    
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))
        self.adapter = JabberAdapter(True)
        password = self.options.jabber_pass
        chatroom = self.options.chatroom
        username = self.options.jabber_user
        host = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        server = '%s:%s' % (host, port)

        client = TwistedJabberClient(dialogHandler = self.adapter, 
        server = server,
        userId = username, userPassword = password, 
        firstRoom = chatroom, debug = True, 
        groupServer = groupServer, realHost = realHost, wants_ssl = wants_ssl)

        self.adapter.client = client

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]
        initPluginSystem({'pluginPath': pluginPath, 'plugins': plugins})

        self.log.info('started')

        # connect to the jabber server
        jabber_reactor = client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        # start event loop which will process jabber messages and zenevents
        jabber_reactor.run()
Beispiel #29
0
    def __init__(self):
        PBDaemon.__init__(self, keeproot=True)
        ZCmdBase.__init__(self)

        self.log.info('Starting...')

        wants_ssl = self.options.ssl
        if wants_ssl and not HAVE_SSL:
            self.log.error('SSL was requested for Jabber connection, but pyopenssl is not installed.  Please install it and start the xmppBot again.')
            sys.exit(2)

        if not self.options.jabber_pass:
            self.log.error('--jabber_pass is required')
            sys.exit(2)

        if not self.options.jabber_user:
            self.log.error('--jabber_user is required')
            sys.exit(2)

        if self.options.first_user:
            try:
                zenUser, jabberId = self.options.first_user.split(',')
            except ValueError:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

            if zenUser and jabberId:
                self.setFirstUser(zenUser, jabberId)
            else:
                self.log.error('--first_user option must contain both zenuser and jabberid separated by a comma.  Example: chudler,[email protected]')
                sys.exit(2)

        # taken from zenactions.py
        self.schedule = Schedule(self.options, self.dmd)
        self.actions = []
        self.loadActionRules()
        self.updateCheck = UpdateCheck()

        self.sendEvent(Event.Event(device=self.options.monitor,
        eventClass=App_Start, summary='Jabber Bot started', severity=0, component='xmppbot'))
        self.adapter = JabberAdapter(True)
        password = self.options.jabber_pass
        chatroom = self.options.chatroom
        username = self.options.jabber_user
        host = self.options.jabber_host
        port = self.options.jabber_port
        groupServer = self.options.group_server
        realHost = self.options.im_host
        server = '%s:%s' % (host, port)

        client = TwistedJabberClient(dialogHandler = self.adapter,
        server = server,
        userId = username, userPassword = password,
        firstRoom = chatroom, debug = True,
        groupServer = groupServer, realHost = realHost, wants_ssl = wants_ssl)

        self.adapter.client = client

        path = os.path.realpath(sys.argv[0])
        pluginPath = os.path.dirname(path) + '/Jabber/plugins'
        self.log.info("xmppBot plugins will be loaded from %s" % pluginPath)

        plugins = [pluginFile.split('/')[-1].split('.py')[0] for pluginFile in glob.glob( os.path.join(pluginPath, '*.py') )]
        initPluginSystem({'pluginPath': pluginPath, 'plugins': plugins})

        self.log.info('started')

        # connect to the jabber server
        jabber_reactor = client.connect()

        # begin looking for zenevents
        self.schedule.start()
        self.runCycle()

        # start event loop which will process jabber messages and zenevents
        jabber_reactor.run()
 def __init__(self):
     PBDaemon.__init__(self, keeproot=True)
     self.stats = Stats()
     self.rrdStats = DaemonStats()