Browse Source

[2883] add counters as a keyword argument into NotifyOut

Naoki Kambe 12 years ago
parent
commit
695d7c75d5
2 changed files with 14 additions and 13 deletions
  1. 1 1
      src/bin/xfrout/xfrout.py.in
  2. 13 12
      src/lib/python/isc/notify/notify_out.py

+ 1 - 1
src/bin/xfrout/xfrout.py.in

@@ -1047,7 +1047,7 @@ class XfroutServer:
 
 
     def _start_notifier(self):
     def _start_notifier(self):
         datasrc = self._unix_socket_server.get_db_file()
         datasrc = self._unix_socket_server.get_db_file()
-        self._notifier = notify_out.NotifyOut(datasrc)
+        self._notifier = notify_out.NotifyOut(datasrc, counters=self._counters)
         if 'also_notify' in self._config_data:
         if 'also_notify' in self._config_data:
             for slave in self._config_data['also_notify']:
             for slave in self._config_data['also_notify']:
                 address = self._default_notify_address
                 address = self._default_notify_address

+ 13 - 12
src/lib/python/isc/notify/notify_out.py

@@ -128,7 +128,7 @@ class NotifyOut:
     notify message to its slaves). notify service can be started by
     notify message to its slaves). notify service can be started by
     calling  dispatcher(), and it can be stopped by calling shutdown()
     calling  dispatcher(), and it can be stopped by calling shutdown()
     in another thread. '''
     in another thread. '''
-    def __init__(self, datasrc_file, verbose=True):
+    def __init__(self, datasrc_file, counters=None, verbose=True):
         self._notify_infos = {} # key is (zone_name, zone_class)
         self._notify_infos = {} # key is (zone_name, zone_class)
         self._waiting_zones = []
         self._waiting_zones = []
         self._notifying_zones = []
         self._notifying_zones = []
@@ -143,7 +143,7 @@ class NotifyOut:
         # Use nonblock event to eliminate busy loop
         # Use nonblock event to eliminate busy loop
         # If there are no notifying zones, clear the event bit and wait.
         # If there are no notifying zones, clear the event bit and wait.
         self._nonblock_event = threading.Event()
         self._nonblock_event = threading.Event()
-        self._counters = Counters()
+        self._counters = counters
 
 
     def _init_notify_out(self, datasrc_file):
     def _init_notify_out(self, datasrc_file):
         '''Get all the zones name and its notify target's address.
         '''Get all the zones name and its notify target's address.
@@ -508,16 +508,17 @@ class NotifyOut:
             sock = zone_notify_info.create_socket(addrinfo[0])
             sock = zone_notify_info.create_socket(addrinfo[0])
             sock.sendto(render.get_data(), 0, addrinfo)
             sock.sendto(render.get_data(), 0, addrinfo)
             # count notifying by IPv4 or IPv6 for statistics
             # count notifying by IPv4 or IPv6 for statistics
-            if zone_notify_info.get_socket().family == socket.AF_INET:
+            if self._counters is not None:
-                self._counters.inc('zones',
+                if zone_notify_info.get_socket().family == socket.AF_INET:
-                                   zone_notify_info.zone_class,
+                    self._counters.inc('zones',
-                                   zone_notify_info.zone_name,
+                                       zone_notify_info.zone_class,
-                                  'notifyoutv4')
+                                       zone_notify_info.zone_name,
-            elif zone_notify_info.get_socket().family == socket.AF_INET6:
+                                      'notifyoutv4')
-                self._counters.inc('zones',
+                elif zone_notify_info.get_socket().family == socket.AF_INET6:
-                                   zone_notify_info.zone_class,
+                    self._counters.inc('zones',
-                                   zone_notify_info.zone_name,
+                                       zone_notify_info.zone_class,
-                                  'notifyoutv6')
+                                       zone_notify_info.zone_name,
+                                      'notifyoutv6')
             logger.info(NOTIFY_OUT_SENDING_NOTIFY, AddressFormatter(addrinfo))
             logger.info(NOTIFY_OUT_SENDING_NOTIFY, AddressFormatter(addrinfo))
         except (socket.error, addr.InvalidAddress) as err:
         except (socket.error, addr.InvalidAddress) as err:
             logger.error(NOTIFY_OUT_SOCKET_ERROR, AddressFormatter(addrinfo),
             logger.error(NOTIFY_OUT_SOCKET_ERROR, AddressFormatter(addrinfo),