nginx-lens 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
commands/graph.py CHANGED
@@ -16,7 +16,14 @@ def graph(
16
16
  Пример:
17
17
  nginx-lens graph /etc/nginx/nginx.conf
18
18
  """
19
- tree = parse_nginx_config(config_path)
19
+ try:
20
+ tree = parse_nginx_config(config_path)
21
+ except FileNotFoundError:
22
+ console.print(f"[red]Файл {config_path} не найден. Проверьте путь к конфигу.[/red]")
23
+ return
24
+ except Exception as e:
25
+ console.print(f"[red]Ошибка при разборе {config_path}: {e}[/red]")
26
+ return
20
27
  routes = []
21
28
  # Для каждого server/location строим маршрут
22
29
  def walk(d, chain, upstreams):
commands/health.py CHANGED
@@ -19,7 +19,14 @@ def health(
19
19
  nginx-lens health /etc/nginx/nginx.conf
20
20
  nginx-lens health /etc/nginx/nginx.conf --timeout 5 --retries 3
21
21
  """
22
- tree = parse_nginx_config(config_path)
22
+ try:
23
+ tree = parse_nginx_config(config_path)
24
+ except FileNotFoundError:
25
+ console.print(f"[red]Файл {config_path} не найден. Проверьте путь к конфигу.[/red]")
26
+ return
27
+ except Exception as e:
28
+ console.print(f"[red]Ошибка при разборе {config_path}: {e}[/red]")
29
+ return
23
30
  upstreams = tree.get_upstreams()
24
31
  results = check_upstreams(upstreams, timeout=timeout, retries=retries)
25
32
  table = Table(show_header=True, header_style="bold blue")
commands/logs.py CHANGED
@@ -26,28 +26,36 @@ def logs(
26
26
  Пример:
27
27
  nginx-lens logs /var/log/nginx/access.log --top 20
28
28
  """
29
+ try:
30
+ with open(log_path) as f:
31
+ lines = list(f)
32
+ except FileNotFoundError:
33
+ console.print(f"[red]Файл {log_path} не найден. Проверьте путь к логу.[/red]")
34
+ return
35
+ except Exception as e:
36
+ console.print(f"[red]Ошибка при чтении {log_path}: {e}[/red]")
37
+ return
29
38
  status_counter = Counter()
30
39
  path_counter = Counter()
31
40
  ip_counter = Counter()
32
41
  user_agent_counter = Counter()
33
42
  errors = defaultdict(list)
34
- with open(log_path) as f:
35
- for line in f:
36
- m = log_line_re.search(line)
37
- if m:
38
- ip = m.group('ip')
39
- path = m.group('path')
40
- status = m.group('status')
41
- status_counter[status] += 1
42
- path_counter[path] += 1
43
- ip_counter[ip] += 1
44
- if status.startswith('4') or status.startswith('5'):
45
- errors[status].append(path)
46
- # user-agent (если есть)
47
- if '" "' in line:
48
- ua = line.rsplit('" "', 1)[-1].strip().strip('"')
49
- if ua:
50
- user_agent_counter[ua] += 1
43
+ for line in lines:
44
+ m = log_line_re.search(line)
45
+ if m:
46
+ ip = m.group('ip')
47
+ path = m.group('path')
48
+ status = m.group('status')
49
+ status_counter[status] += 1
50
+ path_counter[path] += 1
51
+ ip_counter[ip] += 1
52
+ if status.startswith('4') or status.startswith('5'):
53
+ errors[status].append(path)
54
+ # user-agent (если есть)
55
+ if '" "' in line:
56
+ ua = line.rsplit('" "', 1)[-1].strip().strip('"')
57
+ if ua:
58
+ user_agent_counter[ua] += 1
51
59
  # Топ статусов
52
60
  table = Table(title="Top HTTP Status Codes", show_header=True, header_style="bold blue")
53
61
  table.add_column("Status")
commands/route.py CHANGED
@@ -6,19 +6,22 @@ from parser.nginx_parser import parse_nginx_config
6
6
  import glob
7
7
  import os
8
8
 
9
- app = typer.Typer()
9
+ app = typer.Typer(help="Показывает, какой server/location обслуживает указанный URL. По умолчанию ищет во всех .conf в /etc/nginx/. Для кастомного пути используйте -c/--config.")
10
10
  console = Console()
11
11
 
12
12
  def route(
13
- config_path: str = typer.Argument(None, help="Путь к nginx.conf (если не указан — поиск по всем .conf в /etc/nginx)", show_default=False),
14
- url: str = typer.Argument(..., help="URL для маршрутизации (например, http://host/path)")
13
+ url: str = typer.Argument(..., help="URL для маршрутизации (например, http://host/path)"),
14
+ config_path: str = typer.Option(None, "-c", "--config", help="Путь к кастомному nginx.conf (если не указан — поиск по всем .conf в /etc/nginx)")
15
15
  ):
16
16
  """
17
17
  Показывает, какой server/location обслуживает указанный URL.
18
18
 
19
- Пример:
20
- nginx-lens route /etc/nginx/nginx.conf http://example.com/api/v1
19
+ По умолчанию ищет во всех .conf в /etc/nginx/.
20
+ Для кастомного пути используйте опцию -c/--config.
21
+
22
+ Примеры:
21
23
  nginx-lens route http://example.com/api/v1
24
+ nginx-lens route -c /etc/nginx/nginx.conf http://example.com/api/v1
22
25
  """
23
26
  configs = []
24
27
  if config_path:
commands/syntax.py CHANGED
@@ -37,6 +37,8 @@ def syntax(
37
37
  console.print(f"[red]Файл {config_path} не найден. Проверьте путь к конфигу.[/red]")
38
38
  return
39
39
  cmd = [nginx_path, "-t", "-c", os.path.abspath(config_path)]
40
+ if hasattr(os, 'geteuid') and os.geteuid() != 0:
41
+ cmd = ["sudo"] + cmd
40
42
  try:
41
43
  result = subprocess.run(cmd, capture_output=True, text=True, check=False)
42
44
  if result.returncode == 0:
@@ -1,15 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nginx-lens
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: CLI-инструмент для анализа, визуализации и диагностики конфигураций Nginx
5
5
  Author: Daniil Astrouski
6
6
  Author-email: shelovesuastra@gmail.com
7
7
  Requires-Python: >=3.8
8
+ License-File: LICENSE
8
9
  Requires-Dist: typer[all]>=0.9.0
9
10
  Requires-Dist: rich>=13.0.0
10
11
  Requires-Dist: requests>=2.25.0
11
12
  Dynamic: author
12
13
  Dynamic: author-email
14
+ Dynamic: license-file
13
15
  Dynamic: requires-dist
14
16
  Dynamic: requires-python
15
17
  Dynamic: summary
@@ -14,23 +14,24 @@ commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  commands/analyze.py,sha256=W6begSgXNjgKJGoGeguR3WKgHPLkClWXxxpDcqvsJdc,8343
15
15
  commands/cli.py,sha256=9HwDJ-po5al0ceb4Wkyw5F2wzqxbJTo0CbHQ2AQ8obo,722
16
16
  commands/diff.py,sha256=C7gRIWh6DNWHzjiQBPVTn-rZ40m2KCY75Zd6Q4URJIE,2076
17
- commands/graph.py,sha256=fvYDUvj_BXdIAm8eg52v5VxhkZijb2YDkCw7D21ZK-M,4650
18
- commands/health.py,sha256=d2bBui0qauQtO4Ll9cjniKR1Y5dYJBQzG9CECDnsUQ4,1365
17
+ commands/graph.py,sha256=8CnpKqVx9yUpDMcjDX-kN_SqUrS9dFqCUTrsalm-iMg,4967
18
+ commands/health.py,sha256=SuD2gOeMf9ZaoUfeqx1Nip0xQDBkDus6z872Fhw2Z9w,1682
19
19
  commands/include.py,sha256=5PTYG5C00-AlWfIgpQXLq9E7C9yTFSv7HrZkM5ogDps,2224
20
- commands/logs.py,sha256=8tnGsgNy_B97S3O0D_6bvOVfNvAyqeUNotlDOdjltgw,3420
21
- commands/route.py,sha256=H_xMk9KoqwesutzT9ewiTsakfdjmu01kka9ZQc14faY,2222
22
- commands/syntax.py,sha256=gABzFvml92bHqYa6YdRx78bmrtd9v2ORT_Hz-gfQu1U,3336
20
+ commands/logs.py,sha256=RkPUdIpbO9dOVL56lemreYRuAjMjcqqMxRCKOFv2gC4,3691
21
+ commands/route.py,sha256=DfevWTwJfup1Ifmd99pYeuRteFNaldkAvISV8hC5a-c,2650
22
+ commands/syntax.py,sha256=ZWFdaL8LVv9S694wlk2aV3HJKb0OSKjw3wNgTlNvFR8,3418
23
23
  commands/tree.py,sha256=mDfx0Aeg1EDQSYQoJ2nJIkSd_uP7ZR7pEqy7Cw3clQ0,2161
24
24
  exporter/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
25
25
  exporter/graph.py,sha256=WYUrqUgCaK6KihgxAcRHaQn4oMo6b7ybC8yb_36ZIsA,3995
26
26
  exporter/html.py,sha256=uquEM-WvBt2aV9GshgaI3UVhYd8sD0QQ-OmuNtvYUdU,798
27
27
  exporter/markdown.py,sha256=_0mXQIhurGEZ0dO-eq9DbsuKNrgEDIblgtL3DAgYNo8,724
28
+ nginx_lens-0.1.7.dist-info/licenses/LICENSE,sha256=g8QXKdvZZC56rU8E12vIeYF6R4jeTWOsblOnYAda3K4,1073
28
29
  parser/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
29
30
  parser/nginx_parser.py,sha256=JqZ3clNy4Nf-bmbsx_rJUL7EgRoB79b87eEu_isMeqg,3577
30
31
  upstream_checker/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
31
32
  upstream_checker/checker.py,sha256=9-6CMUTN7gXUACP8EwX722QogfujZyV-WWWUeM3a79k,455
32
- nginx_lens-0.1.6.dist-info/METADATA,sha256=FhO8QQOa9YfJzMUtNq313YcaNQAhHr2UEMNHXDIJkBU,476
33
- nginx_lens-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
34
- nginx_lens-0.1.6.dist-info/entry_points.txt,sha256=qEcecjSyLqcJjbIVlNlTpqAhPqDyaujUV5ZcBTAr3po,48
35
- nginx_lens-0.1.6.dist-info/top_level.txt,sha256=mxLJO4rZg0rbixVGhplF3fUNFs8vxDIL25ronZNvRy4,51
36
- nginx_lens-0.1.6.dist-info/RECORD,,
33
+ nginx_lens-0.1.7.dist-info/METADATA,sha256=eN2OiSpnQpDN8kRzVdynuAwJamWiMme1UlIr-cXvfC4,520
34
+ nginx_lens-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
35
+ nginx_lens-0.1.7.dist-info/entry_points.txt,sha256=qEcecjSyLqcJjbIVlNlTpqAhPqDyaujUV5ZcBTAr3po,48
36
+ nginx_lens-0.1.7.dist-info/top_level.txt,sha256=mxLJO4rZg0rbixVGhplF3fUNFs8vxDIL25ronZNvRy4,51
37
+ nginx_lens-0.1.7.dist-info/RECORD,,
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Daniil Astrouski
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.