-
-
Save nicksan2c/645773057ba165a3576d0459ae1ba77d to your computer and use it in GitHub Desktop.
Verify Splunk Regex Matches Against Your Entire Log File
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python | |
| # usage ./verify_splunk_coverage.py <log_file> | |
| # set these from splunk-apps/apps/<service-name>/default/props.conf | |
| BREAK_ONLY_BEFORE_REGEX=r'^\d\d:\d\d:\d\d\s\[[^\]]+\]' | |
| EXTRACT_REGEX=r'^\d?\d:\d\d:\d\d\s\[(?P<thread>[^\]]+)\]\s\[(?P<loglevel>\w+)\]\s\[(?P<class>[^\]]+)\]\s\[(?P<username>[^\]]*)\](?P<message>.*)$' | |
| import re,sys | |
| f = open(sys.argv[1]) | |
| s = f.readline() | |
| while True: | |
| n = f.readline() | |
| if not n: | |
| if not re.match(EXTRACT_REGEX, s): | |
| print "Failed to match line " + s | |
| sys.exit(0) | |
| if not re.match(BREAK_ONLY_BEFORE_REGEX, n): | |
| s = s + n | |
| else: | |
| if not re.match(EXTRACT_REGEX, s): | |
| print "Failed to match line:\n", s | |
| s = n |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment