mirror of https://github.com/yandex/gixy
Merge pull request #16 from yandex/fix-broken-config
Issue #15: Better nginx config detectionpull/18/head
commit
d2b3cc9390
|
@ -92,11 +92,6 @@ def _get_cli_parser():
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
def _is_nginx_file(file_path):
|
|
||||||
s = open(file_path).read()
|
|
||||||
return 'server {' in s or 'http {' in s
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
parser = _get_cli_parser()
|
parser = _get_cli_parser()
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -108,10 +103,6 @@ def main():
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if not _is_nginx_file(path):
|
|
||||||
sys.stderr.write('This is nginx config? Rly?\n')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
severity = gixy.severity.ALL[args.level]
|
severity = gixy.severity.ALL[args.level]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
|
|
|
@ -28,8 +28,14 @@ class NginxParser(object):
|
||||||
|
|
||||||
if not root:
|
if not root:
|
||||||
root = block.Root()
|
root = block.Root()
|
||||||
parser = raw_parser.RawParser()
|
|
||||||
parsed = parser.parse(file_path)
|
try:
|
||||||
|
parser = raw_parser.RawParser()
|
||||||
|
parsed = parser.parse(file_path)
|
||||||
|
except ParseException as e:
|
||||||
|
LOG.error('Failed to parse config "{file}": {error}'.format(file=file_path, error=str(e)))
|
||||||
|
return root
|
||||||
|
|
||||||
if len(parsed) and parsed[0].getName() == 'file_delimiter':
|
if len(parsed) and parsed[0].getName() == 'file_delimiter':
|
||||||
# Were parse nginx dump
|
# Were parse nginx dump
|
||||||
LOG.info('Switched to parse nginx configuration dump.')
|
LOG.info('Switched to parse nginx configuration dump.')
|
||||||
|
@ -104,10 +110,7 @@ class NginxParser(object):
|
||||||
for file_path in glob.iglob(path):
|
for file_path in glob.iglob(path):
|
||||||
include = block.IncludeBlock('include', [file_path])
|
include = block.IncludeBlock('include', [file_path])
|
||||||
parent.append(include)
|
parent.append(include)
|
||||||
try:
|
self.parse(file_path, include)
|
||||||
self.parse(file_path, include)
|
|
||||||
except ParseException as e:
|
|
||||||
LOG.error('Failed to parse include "{file}": {error}'.format(file=file_path, error=str(e)))
|
|
||||||
|
|
||||||
if not file_path:
|
if not file_path:
|
||||||
LOG.warning("File not found: {}".format(path))
|
LOG.warning("File not found: {}".format(path))
|
||||||
|
@ -120,10 +123,7 @@ class NginxParser(object):
|
||||||
founded = True
|
founded = True
|
||||||
include = block.IncludeBlock('include', [file_path])
|
include = block.IncludeBlock('include', [file_path])
|
||||||
parent.append(include)
|
parent.append(include)
|
||||||
try:
|
self.parse_block(parsed, include)
|
||||||
self.parse_block(parsed, include)
|
|
||||||
except ParseException as e:
|
|
||||||
LOG.error('Failed to parse include "{file}": {error}'.format(file=file_path, error=str(e)))
|
|
||||||
|
|
||||||
if not founded:
|
if not founded:
|
||||||
LOG.warning("File not found: {}".format(path))
|
LOG.warning("File not found: {}".format(path))
|
||||||
|
|
Loading…
Reference in New Issue