示例#1
0
    def __init__(self):
        self.config.populate()
        threading.current_thread(
        ).name = self.config.name  # rename main thread

        self.attach_signals()

        # init database connections different ones for different threads
        self._db = LibreNMS.DB(self.config)  # main
        self._services_db = LibreNMS.DB(self.config)  # services dispatch
        self._discovery_db = LibreNMS.DB(self.config)  # discovery dispatch

        self._lm = self.create_lock_manager()
        self.daily_timer = LibreNMS.RecurringTimer(
            self.config.update_frequency, self.run_maintenance, 'maintenance')
        self.stats_timer = LibreNMS.RecurringTimer(
            self.config.poller.frequency, self.log_performance_stats,
            'performance')
        self.is_master = False

        self.performance_stats = {
            'poller': PerformanceCounter(),
            'discovery': PerformanceCounter(),
            'services': PerformanceCounter()
        }
示例#2
0
    def __init__(self):
        self.start_time = time.time()
        self.config.populate()
        self._db = LibreNMS.DB(self.config)
        self.config.load_poller_config(self._db)

        threading.current_thread(
        ).name = self.config.name  # rename main thread
        self.attach_signals()

        self._lm = self.create_lock_manager()
        self.daily_timer = LibreNMS.RecurringTimer(
            self.config.update_frequency, self.run_maintenance, 'maintenance')
        self.stats_timer = LibreNMS.RecurringTimer(
            self.config.poller.frequency, self.log_performance_stats,
            'performance')
        if self.config.watchdog_enabled:
            info("Starting watchdog timer for log file: {}".format(
                self.config.watchdog_logfile))
            self.watchdog_timer = LibreNMS.RecurringTimer(
                self.config.poller.frequency, self.logfile_watchdog,
                'watchdog')
        else:
            info("Watchdog is disabled.")
        self.is_master = False
示例#3
0
    def __init__(self):
        self.config.populate()
        threading.current_thread().name = self.config.name  # rename main thread

        self.attach_signals()

        self._db = LibreNMS.DB(self.config)

        self._lm = self.create_lock_manager()
        self.daily_timer = LibreNMS.RecurringTimer(self.config.update_frequency, self.run_maintenance, 'maintenance')
        self.stats_timer = LibreNMS.RecurringTimer(self.config.poller.frequency, self.log_performance_stats, 'performance')
        self.is_master = False
示例#4
0
    def __init__(self, config, lock_manager):
        """
        A TimedQueueManager with two timers dispatching poll billing and calculate billing to the same work queue

        :param config: LibreNMS.ServiceConfig reference to the service config object
        :param lock_manager: the single instance of lock manager
        """
        TimedQueueManager.__init__(self, config, lock_manager, 'billing')
        self.calculate_timer = LibreNMS.RecurringTimer(
            self.get_poller_config().calculate,
            self.dispatch_calculate_billing, 'calculate_billing_timer')
示例#5
0
 def __init__(self, config, type_desc, work_function, dispatch_function, auto_start=True):
     """
     A queue manager that periodically dispatches work to the queue
     The times are normalized like they started at 0:00
     :param config: LibreNMS.ServiceConfig reference to the service config object
     :param type_desc: description for this queue manager type
     :param work_function: function that will be called to perform the task
     :param dispatch_function: function that will be called when the timer is up, should call post_work()
     :param auto_start: automatically start worker threads
     """
     QueueManager.__init__(self, config, type_desc, work_function, auto_start)
     self.timer = LibreNMS.RecurringTimer(self.get_poller_config().frequency, dispatch_function)
示例#6
0
    def __init__(self, config, work_function, poll_dispatch_function, calculate_dispatch_function,
                 auto_start=True):
        """
        A TimedQueueManager with two timers dispatching poll billing and calculate billing to the same work queue

        :param config: LibreNMS.ServiceConfig reference to the service config object
        :param work_function: function that will be called to perform the task
        :param poll_dispatch_function: function that will be called when the timer is up, should call post_work()
        :param calculate_dispatch_function: function that will be called when the timer is up, should call post_work()
        :param auto_start: automatically start worker threads
        """
        TimedQueueManager.__init__(self, config, 'billing', work_function, poll_dispatch_function, auto_start)
        self.calculate_timer = LibreNMS.RecurringTimer(self.get_poller_config().calculate, calculate_dispatch_function, 'calculate_billing_timer')
示例#7
0
 def __init__(self,
              config,
              lock_manager,
              type_desc,
              uses_groups=False,
              auto_start=True):
     """
     A queue manager that periodically dispatches work to the queue
     The times are normalized like they started at 0:00
     :param config: LibreNMS.ServiceConfig reference to the service config object
     :param type_desc: description for this queue manager type
     :param uses_groups: If this queue respects assigned groups or there is only one group
     :param auto_start: automatically start worker threads
     """
     QueueManager.__init__(self, config, lock_manager, type_desc,
                           uses_groups, auto_start)
     self.timer = LibreNMS.RecurringTimer(
         self.get_poller_config().frequency, self.do_dispatch)
示例#8
0
 def test_recurring_timer(self):
     self.assertEqual(0, self.counter)
     timer = LibreNMS.RecurringTimer(0.5, self.count)
     timer.start()
     self.assertEqual(0, self.counter)
     sleep(0.5)
     self.assertEqual(1, self.counter)
     self.assertEqual(1, self.counter)
     sleep(0.5)
     self.assertEqual(2, self.counter)
     timer.stop()
     self.assertTrue(timer._event.is_set())
     sleep(0.5)
     self.assertEqual(2, self.counter)
     timer.start()
     sleep(0.5)
     self.assertEqual(3, self.counter)
     timer.stop()