Created
August 26, 2018 01:34
-
-
Save sdebnath/833a30de5ed1cc86198153b060031f68 to your computer and use it in GitHub Desktop.
bridgegate.py
This file contains 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 | |
# Permission to use, copy, modify, and/or distribute this software for any | |
# purpose with or without fee is hereby granted. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
import sys | |
import re | |
from optparse import OptionParser | |
required="filename".split() | |
parser = OptionParser() | |
parser.add_option("-f", "--file", action="store", type="string", dest="filename", | |
help="read panic report from FILE", metavar="FILE") | |
(options, args) = parser.parse_args() | |
for r in required: | |
if options.__dict__[r] is None: | |
parser.error("parameter %s required"%r) | |
f = open(options.filename,"r") | |
panic = f.read() | |
# Declare our variables | |
build = '' | |
product = '' | |
kernel = '' | |
incidentId = '' | |
threadId = '' | |
component = '' | |
# Search using regex | |
m = re.search("\"build\" : \"(.*?)\",", panic) | |
if m: | |
build = m.group(1) | |
m = re.search("\"product\" : \"(.*?)\",", panic) | |
if m: | |
product = m.group(1) | |
m = re.search("\"kernel\" : \"(.*?)\",", panic) | |
if m: | |
kernel = m.group(1) | |
m = re.search("\"incident\" : \"([a-zA-z0-9\-]+)\",", panic) | |
if m: | |
incidentId = m.group(1) | |
m = re.search("tid: (\d+)", panic) | |
if m: | |
threadId = m.group(1) | |
m = re.search("\"" + threadId + "\":{[^\}]+\"name\":\"([a-zA-Z]+)\"[^\}]+}", panic) | |
if m: | |
component = m.group(1) | |
# Print out values | |
print "build: {}".format(build) | |
print "product: {}".format(product) | |
print "kernel: {}".format(kernel) | |
print "incidentId: {}".format(incidentId) | |
print "component: {}".format(component) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment