mirror of
https://github.com/sileht/bird-lg.git
synced 2024-11-22 06:54:43 +01:00
Add resolv timeout, store asn in memcache
This commit is contained in:
parent
af2c305049
commit
9822e42e25
10
lg.py
10
lg.py
|
@ -20,6 +20,7 @@
|
||||||
#
|
#
|
||||||
###
|
###
|
||||||
|
|
||||||
|
import memcache
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import TimedRotatingFileHandler
|
from logging.handlers import TimedRotatingFileHandler
|
||||||
|
@ -45,6 +46,8 @@ file_handler = TimedRotatingFileHandler(filename=app.config["LOG_FILE"], when="m
|
||||||
file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
|
file_handler.setLevel(getattr(logging, app.config["LOG_LEVEL"].upper()))
|
||||||
app.logger.addHandler(file_handler)
|
app.logger.addHandler(file_handler)
|
||||||
|
|
||||||
|
memcache_server = app.config.get("MEMCACHE_SERVER", "127.0.0.1:11211")
|
||||||
|
mc = memcache.Client([memcache_server])
|
||||||
|
|
||||||
def get_asn_from_as(n):
|
def get_asn_from_as(n):
|
||||||
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
|
asn_zone = app.config.get("ASN_ZONE", "asn.cymru.com")
|
||||||
|
@ -370,7 +373,12 @@ def get_as_name(_as):
|
||||||
if not _as.isdigit():
|
if not _as.isdigit():
|
||||||
return _as.strip()
|
return _as.strip()
|
||||||
|
|
||||||
name = get_asn_from_as(_as)[-1].replace(" ","\r",1)
|
name = mc.get(str('lg_%s' % _as))
|
||||||
|
if not name:
|
||||||
|
app.logger.info("asn for as %s not found in memcache", _as)
|
||||||
|
name = get_asn_from_as(_as)[-1].replace(" ","\r",1)
|
||||||
|
if name:
|
||||||
|
mc.set(str("lg_%s" % _as), str(name), 3600)
|
||||||
return "AS%s | %s" % (_as, name)
|
return "AS%s | %s" % (_as, name)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,12 @@ import socket
|
||||||
import pickle
|
import pickle
|
||||||
import xml.parsers.expat
|
import xml.parsers.expat
|
||||||
|
|
||||||
|
resolv = resolver.Resolver()
|
||||||
|
resolv.timeout = 0.5
|
||||||
|
resolv.lifetime = 1
|
||||||
|
|
||||||
def resolve(n, q):
|
def resolve(n, q):
|
||||||
return str(resolver.query(n,q)[0])
|
return str(resolv.query(n,q)[0])
|
||||||
|
|
||||||
def mask_is_valid(n):
|
def mask_is_valid(n):
|
||||||
if not n:
|
if not n:
|
||||||
|
|
Loading…
Reference in a new issue