check mime types against known-good list
Alexey Vekshin committed
May 22, 2018 at 21:01 UTC
4dbe4a9032c2ef02a7ec1ff352a38950272e4e7d
1 file changed
+5
-4
python.d/web_log.chart.py
+5
-4
@@ -261,6 +261,7 @@ SQUID_CODES = dict(TCP='squid_transport_methods', UDP='squid_transport_methods',
261
262
REQUEST_REGEX = re.compile(r'(?P<method>[A-Z]+) (?P<url>[^ ]+) [A-Z]+/(?P<http_version>\d(?:.\d)?)')
263
264
+MIME_TYPES = ['application', 'audio', 'example', 'font', 'image', 'message', 'model', 'multipart', 'text', 'video']
265
266
class Service(LogService):
267
def __init__(self, configuration=None, name=None):
@@ -808,15 +809,15 @@ class Squid:
809
return False
810
self.storage['unique_all_time'] = list()
811
self.storage['regex'] = re.compile(r'[0-9.]+\s+(?P<duration>[0-9]+)'
811
- r' (?P<client_address>[\da-f.:]+)'
812
+ r' (?P<client_address>[\dA-Za-z.:_-]+)'
813
r' (?P<squid_code>[A-Z_]+)/'
814
r'(?P<http_code>[0-9]+)'
815
r' (?P<bytes>[0-9]+)'
816
r' (?P<method>[A-Z_]+)'
817
r' (?P<url>[^ ]+)'
818
r' (?P<user>[^ ]+)'
818
- r' (?P<hier_code>[A-Z_]+)/[\da-f.:-]+'
819
- r' (?P<mime_type>[A-Za-z0-9-]+)')
819
+ r' (?P<hier_code>[A-Z_]+)/[\da-z.:-]+'
820
+ r' (?P<mime_type>[A-Za-z-]*)')
821
822
match = self.storage['regex'].search(last_line)
823
if not match:
@@ -837,7 +838,7 @@ class Squid:
838
'func_dim': None},
839
'mime_type': {
840
'chart': 'squid_mime_type',
840
- 'func_dim_id': lambda v: v.split('/')[0],
841
+ 'func_dim_id': lambda v: str.lower(v) if str.lower(v) in MIME_TYPES else 'unknown',
842
'func_dim': None}}
843
if not self.configuration.get('all_time', True):
844
self.order.remove('squid_clients_all')