diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py index 889353377b4..09c83a636f0 100755 --- a/misc/log-analytics/import_logs.py +++ b/misc/log-analytics/import_logs.py @@ -226,20 +226,17 @@ def check_format(self, file): file.seek(0) return + # store the header lines for a later check for IIS + self.header_lines = header_lines + # Parse the 4th 'Fields: ' line to create the regex to use full_regex = [] expected_fields = type(self).fields.copy() # turn custom field mapping into field => regex mapping - # if the --w3c-time-taken-millisecs option is used, make sure the time-taken field is interpreted as seconds + # if the --w3c-time-taken-millisecs option is used, make sure the time-taken field is interpreted as milliseconds if config.options.w3c_time_taken_in_millisecs: expected_fields['time-taken'] = '(?P[\d.]+)' - else: - # check if we're importing IIS logs and if so, issue a warning TODO: should be done after correct format found so only one warning made - if 'generation_time_milli' not in expected_fields['time-taken'] and self._is_iis(header_lines): - logging.info("WARNING: IIS log file being parsed without --w3c-time-taken-milli option. IIS" - " stores millisecond values in the time-taken field. If your logfile does this, the aforementioned" - " option must be used in order to get accurate generation times.") for mapped_field_name, field_name in config.options.custom_w3c_fields.iteritems(): expected_fields[mapped_field_name] = type(self).fields[field_name] @@ -259,8 +256,17 @@ def check_format(self, file): file.seek(0) return self.check_format_line(first_line) - def _is_iis(self, header_lines): - return len([line for line in header_lines if 'internet information services' in line.lower() or 'iis' in line.lower()]) > 0 + def check_for_iis_option(self): + if not config.options.w3c_time_taken_in_millisecs and self._is_time_taken_milli() and self._is_iis(): + logging.info("WARNING: IIS log file being parsed without --w3c-time-taken-milli option. IIS" + " stores millisecond values in the time-taken field. If your logfile does this, the aforementioned" + " option must be used in order to get accurate generation times.") + + def _is_iis(self): + return len([line for line in self.header_lines if 'internet information services' in line.lower() or 'iis' in line.lower()]) > 0 + + def _is_time_taken_milli(self): + return 'generation_time_milli' not in self.regex.pattern class IisFormat(W3cExtendedFormat): @@ -1607,6 +1613,11 @@ def check_format(lineOrFile): else: logging.debug('Format %s does not match', name) + # if the format is W3cExtendedFormat, check if the logs are from IIS and if so, issue a warning if the + # --w3c-time-taken-milli option isn't set + if isinstance(format, W3cExtendedFormat): + format.check_for_iis_option() + return format @staticmethod diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml index 8734e5196a3..c96927245a8 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Live.getLastVisitsDetails_range.xml @@ -1867,6 +1867,7 @@ + unknown Unknown unk Unknown @@ -1878,7 +1879,6 @@ Unknown - unknown 01:13:11 @@ -2660,6 +2660,7 @@ + unknown Unknown unk Unknown @@ -2671,7 +2672,6 @@ Unknown - unknown 23:51:21 @@ -2753,6 +2753,7 @@ + unknown Unknown unk Unknown @@ -2764,7 +2765,6 @@ Unknown - unknown 23:51:20 diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getConfiguration_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getConfiguration_month.xml index 75d278b51bb..de82b8409f6 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getConfiguration_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getConfiguration_month.xml @@ -44,6 +44,17 @@ 2 1 + + + 3 + 3 + 1 + 0 + 3 + 0 + 3 + 0 + 2 @@ -111,13 +122,13 @@ 0 - + 1 1 1 0 1 - 0 + 1 1 0 diff --git a/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getResolution_month.xml b/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getResolution_month.xml index 378996fabca..a8dc2aedb45 100644 --- a/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getResolution_month.xml +++ b/tests/PHPUnit/System/expected/test_ImportLogs__Resolution.getResolution_month.xml @@ -2,13 +2,13 @@ - 29 - 34 + 32 + 37 3 550 - 25 - 27 - 28 + 28 + 28 + 31 2