Coverage for runmacs/processor/authserver/accesslog.py : 21%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
pass
def logAccess(self, *args, **kwargs): pass
assert database is not None self.host = host self.port = port self.username = username self.password = password self.database = database self.timeout = timeout self.url = 'http://%s:%s@%s:%d/write?db=%s'%(self.username, self.password, self.host, self.port, self.database) self.client = httpclient.AsyncHTTPClient() tags = {"ip": ip, "url": url, "method": method} if user is not None: tags["username"] = user if oid is not None: tags["oid"] = oid if authmode is not None: tags["authmode"] = authmode tagdata = ','.join(['%s=%s'%(k,v.replace(' ', r'\ ').replace(',', r'\,')) for k,v in sorted(tags.items())]) valuedata = 'value=%d'%(1 if authok else 0) body = 'url_access,%s %s\n'%(tagdata, valuedata) request = httpclient.HTTPRequest(self.url, body=body, method="POST") try: yield self.client.fetch(request) except Exception as e: print "WARNING: logging error: %s"%e
assert index is not None self.host = host self.port = port self.username = username self.password = password self.index = index self.timeout = timeout self.url = 'http://%s:%d/%s/url_access/'%(self.host, self.port, self.index) self.client = httpclient.AsyncHTTPClient() tags = {"ip": ip, "url": url, "method": method, "authok": authok} if user is not None: tags["username"] = user if oid is not None: tags["oid"] = oid if authmode is not None: tags["authmode"] = authmode if useragent is not None: tags["useragent"] = useragent now = datetime.datetime.utcnow() ms = int(now.microsecond / 1000) tags["timestamp"] = now.strftime('%Y-%m-%dT%H:%M:%S') + '.%03d'%ms body = json.dumps(tags) print body request = httpclient.HTTPRequest(self.url, body=body, method="POST") try: yield self.client.fetch(request) except Exception as e: print "WARNING: logging error: %s"%e
""" Creates an influxdb access logger, all arguments are passed to the influxdb client. """ import influxdb self.client = influxdb.client.InfluxDBClient(*args, **kwargs) tags = {"ip": ip, "url": url, "method": method}
if user is not None: tags["username"] = user if oid is not None: tags["oid"] = oid if authmode is not None: tags["authmode"] = authmode data = [ {"measurement": "url_access", "tags": tags, "fields": {"value": 1 if authok else 0}, } ] try: self.client.write_points(data) except ConnectionError: pass |