Helge Jung 10 лет назад
Родитель
Сommit
c11f995dae
3 измененных файлов с 19 добавлено и 11 удалено
  1. 14 6
      ffstatus/__init__.py
  2. 3 3
      ffstatus/basestorage.py
  3. 2 2
      ffstatus/server.py

+ 14 - 6
ffstatus/__init__.py

@@ -84,6 +84,7 @@ def merge_alfred_batman(alfreddata, batmandata):
 
 no_ipblock_resolves_until = None
 
+
 def resolve_ipblock(ipaddr):
     """Resolve the given IP address to its inetnum entry at RIPE."""
     global no_ipblock_resolves_until
@@ -92,7 +93,9 @@ def resolve_ipblock(ipaddr):
         if no_ipblock_resolves_until < time.time():
             no_ipblock_resolves_until = None
         else:
-            logger.info('IP-Block-Resolving suspended for {0} seconds. Won\'t resolve \'{1}\' now.'.format(int(no_ipblock_resolves_until-time.time()), ipaddr))
+            logger.info('IP-Block-Resolving suspended for %d seconds. ' +
+                        'Won\'t resolve \'%s\' now.',
+                        int(no_ipblock_resolves_until-time.time()), ipaddr)
             return None
 
     url = 'http://rest.db.ripe.net/search.json?query-string=' + str(ipaddr)
@@ -115,12 +118,17 @@ def resolve_ipblock(ipaddr):
 
     except urllib2.URLError as err:
         output = err.read()
-        logger.error('Error "{1}" querying ip \'{0}\' from RIPE API: {2}'.format(ipaddr, err, output))
+        logger.error('Error "%s" querying ip \'%s\' from RIPE API: %s',
+                     err, ipaddr, output)
         if 'Retry-After' in err.headers:
             retry = int(err.headers['Retry-After'])
-            logger.warn('I won\'t resolve IPs for {0} seconds as requested by RIPE API (header=\'{1}\').'.format(retry, err.header['Retry-After']))
-            no_ipblock_resolves_until = time.time() + int(err.headers['Retry-After'])
+            logger.warn(
+                'I won\'t resolve IPs for %d seconds as requested by RIPE API' +
+                ' (header=\'%s\').',
+                retry, err.header['Retry-After'])
+            no_ipblock_resolves_until = \
+                time.time() + int(err.headers['Retry-After'])
         else:
-            logger.warn('I won\'t resolve IPs for the next hour (API didn\'t give better hint).')
+            logger.warn('I won\'t resolve IPs for the next hour ' +
+                        '(API didn\'t give better hint).')
             no_ipblock_resolves_until = time.time() + 3600
-

+ 3 - 3
ffstatus/basestorage.py

@@ -94,10 +94,10 @@ class BaseStorage(object):
             sum_clients += node.get('clientcount', 0)
             nodemacs = [x for x in node.get('macs', [])]
             if 'mac' in node:
-		nodemacs.add(node['mac'])
+                nodemacs.add(node['mac'])
             for client in node.get('clients', []):
-		if client in nodemacs:
-			continue
+                if client in nodemacs:
+                    continue
                 clients.add(client)
 
         return {

+ 2 - 2
ffstatus/server.py

@@ -231,8 +231,8 @@ class BatcaveHttpRequestHandler(BaseHTTPRequestHandler):
         sortkey = query['sort'] if 'sort' in query else None
         data = self.server.storage.get_nodes(sortby=sortkey)
         for node in data:
-            nodeid = node['node_id']
-            nodename = node['hostname'] if 'hostname' in node else '&lt;?&gt;'
+            nodeid = node.get('node_id')
+            nodename = node.get('hostname', '&lt;?&gt;')
 
             self.wfile.write('<tr>\n')
             self.wfile.write('  <td><a href="/node/{0}.json">{0}</a></td>\n'.format(nodeid))