medic-cli 0.1.1__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.
- medic/__init__.py +41 -0
- medic/__main__.py +8 -0
- medic/checks/__init__.py +30 -0
- medic/checks/dns.py +60 -0
- medic/checks/exec.py +90 -0
- medic/checks/http.py +181 -0
- medic/checks/ping.py +226 -0
- medic/checks/ssh.py +246 -0
- medic/checks/system.py +469 -0
- medic/checks/tcp.py +184 -0
- medic/checks/tls.py +255 -0
- medic/cli.py +572 -0
- medic/completion.py +46 -0
- medic/config.py +199 -0
- medic/core/__init__.py +18 -0
- medic/core/base.py +48 -0
- medic/core/enums.py +85 -0
- medic/core/models.py +116 -0
- medic/core/runner.py +212 -0
- medic/formatters/__init__.py +48 -0
- medic/formatters/base.py +14 -0
- medic/formatters/json_formatter.py +26 -0
- medic/formatters/junit_formatter.py +52 -0
- medic/formatters/rich_formatter.py +187 -0
- medic/formatters/text_formatter.py +60 -0
- medic/py.typed +0 -0
- medic_cli-0.1.1.dist-info/METADATA +175 -0
- medic_cli-0.1.1.dist-info/RECORD +32 -0
- medic_cli-0.1.1.dist-info/WHEEL +5 -0
- medic_cli-0.1.1.dist-info/entry_points.txt +2 -0
- medic_cli-0.1.1.dist-info/licenses/LICENSE +21 -0
- medic_cli-0.1.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""Output formatters for medic reports."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from rich.console import Console
|
|
6
|
+
|
|
7
|
+
from medic.core.enums import OutputFormat
|
|
8
|
+
|
|
9
|
+
from .base import BaseFormatter
|
|
10
|
+
from .json_formatter import JSONFormatter
|
|
11
|
+
from .junit_formatter import JUnitFormatter
|
|
12
|
+
from .rich_formatter import RichFormatter
|
|
13
|
+
from .text_formatter import TextFormatter
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_formatter(
|
|
17
|
+
fmt: OutputFormat,
|
|
18
|
+
console: Optional[Console] = None,
|
|
19
|
+
verbose: bool = False,
|
|
20
|
+
show_remediation: bool = True,
|
|
21
|
+
no_color: bool = False,
|
|
22
|
+
) -> BaseFormatter:
|
|
23
|
+
"""Factory function to instantiate appropriate formatter."""
|
|
24
|
+
if fmt == OutputFormat.JSON:
|
|
25
|
+
return JSONFormatter()
|
|
26
|
+
elif fmt == OutputFormat.JUNIT:
|
|
27
|
+
return JUnitFormatter()
|
|
28
|
+
elif fmt == OutputFormat.TEXT:
|
|
29
|
+
return TextFormatter(compact=False)
|
|
30
|
+
elif fmt == OutputFormat.COMPACT:
|
|
31
|
+
return TextFormatter(compact=True)
|
|
32
|
+
else:
|
|
33
|
+
return RichFormatter(
|
|
34
|
+
console=console,
|
|
35
|
+
verbose=verbose,
|
|
36
|
+
show_remediation=show_remediation,
|
|
37
|
+
no_color=no_color,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
__all__ = [
|
|
42
|
+
"BaseFormatter",
|
|
43
|
+
"RichFormatter",
|
|
44
|
+
"JSONFormatter",
|
|
45
|
+
"JUnitFormatter",
|
|
46
|
+
"TextFormatter",
|
|
47
|
+
"get_formatter",
|
|
48
|
+
]
|
medic/formatters/base.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"""Base interface for report formatters."""
|
|
2
|
+
|
|
3
|
+
from abc import ABC, abstractmethod
|
|
4
|
+
|
|
5
|
+
from medic.core.models import MedicReport
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseFormatter(ABC):
|
|
9
|
+
"""Abstract base class for output formatters."""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def render(self, report: MedicReport) -> None:
|
|
13
|
+
"""Render the report to stdout/terminal."""
|
|
14
|
+
raise NotImplementedError
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""JSON output formatter for machine consumption and CI/CD pipelines."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import sys
|
|
5
|
+
from typing import Optional, TextIO
|
|
6
|
+
|
|
7
|
+
from medic.core.models import MedicReport
|
|
8
|
+
|
|
9
|
+
from .base import BaseFormatter
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class JSONFormatter(BaseFormatter):
|
|
13
|
+
"""Formats report as formatted JSON."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, stream: Optional[TextIO] = None, indent: int = 2) -> None:
|
|
16
|
+
self._stream = stream
|
|
17
|
+
self.indent = indent
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def stream(self) -> TextIO:
|
|
21
|
+
return self._stream if self._stream is not None else sys.stdout
|
|
22
|
+
|
|
23
|
+
def render(self, report: MedicReport) -> None:
|
|
24
|
+
payload = report.to_dict()
|
|
25
|
+
self.stream.write(json.dumps(payload, indent=self.indent) + "\n")
|
|
26
|
+
self.stream.flush()
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""JUnit XML output formatter for CI systems."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Optional, TextIO
|
|
5
|
+
from xml.etree import ElementTree as ET
|
|
6
|
+
|
|
7
|
+
from medic.core.enums import CheckStatus
|
|
8
|
+
from medic.core.models import MedicReport
|
|
9
|
+
|
|
10
|
+
from .base import BaseFormatter
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class JUnitFormatter(BaseFormatter):
|
|
14
|
+
"""Formats a report as a JUnit <testsuite>. Warnings are passes with system-out."""
|
|
15
|
+
|
|
16
|
+
def __init__(self, stream: Optional[TextIO] = None) -> None:
|
|
17
|
+
self._stream = stream
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def stream(self) -> TextIO:
|
|
21
|
+
return self._stream if self._stream is not None else sys.stdout
|
|
22
|
+
|
|
23
|
+
def render(self, report: MedicReport) -> None:
|
|
24
|
+
suite = ET.Element(
|
|
25
|
+
"testsuite",
|
|
26
|
+
name="medic",
|
|
27
|
+
tests=str(report.total_count),
|
|
28
|
+
failures=str(report.failed_count),
|
|
29
|
+
errors=str(report.error_count),
|
|
30
|
+
skipped=str(report.skipped_count),
|
|
31
|
+
time=f"{report.duration_ms / 1000.0:.3f}",
|
|
32
|
+
timestamp=report.timestamp.isoformat(),
|
|
33
|
+
)
|
|
34
|
+
for r in report.results:
|
|
35
|
+
case = ET.SubElement(
|
|
36
|
+
suite,
|
|
37
|
+
"testcase",
|
|
38
|
+
classname=r.category.value,
|
|
39
|
+
name=r.name,
|
|
40
|
+
time=f"{(r.latency_ms or 0.0) / 1000.0:.3f}",
|
|
41
|
+
)
|
|
42
|
+
if r.status == CheckStatus.FAILED:
|
|
43
|
+
ET.SubElement(case, "failure", message=r.message).text = r.remediation or r.message
|
|
44
|
+
elif r.status == CheckStatus.ERROR:
|
|
45
|
+
ET.SubElement(case, "error", message=r.message).text = str(r.details.get("traceback", r.message))
|
|
46
|
+
elif r.status == CheckStatus.SKIPPED:
|
|
47
|
+
ET.SubElement(case, "skipped", message=r.message)
|
|
48
|
+
elif r.status == CheckStatus.WARNING:
|
|
49
|
+
ET.SubElement(case, "system-out").text = f"WARNING: {r.message}"
|
|
50
|
+
ET.indent(suite)
|
|
51
|
+
self.stream.write(ET.tostring(suite, encoding="unicode") + "\n")
|
|
52
|
+
self.stream.flush()
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Rich-based colorful and structured terminal output formatter."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional
|
|
4
|
+
|
|
5
|
+
from rich.box import ROUNDED, SIMPLE_HEAVY
|
|
6
|
+
from rich.console import Console, Group
|
|
7
|
+
from rich.panel import Panel
|
|
8
|
+
from rich.table import Table
|
|
9
|
+
from rich.text import Text
|
|
10
|
+
|
|
11
|
+
from medic.core.enums import CheckCategory, CheckStatus
|
|
12
|
+
from medic.core.models import MedicReport
|
|
13
|
+
|
|
14
|
+
from .base import BaseFormatter
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RichFormatter(BaseFormatter):
|
|
18
|
+
"""Renders MedicReports with rich formatting, tables, status colors, and panels."""
|
|
19
|
+
|
|
20
|
+
def __init__(
|
|
21
|
+
self,
|
|
22
|
+
console: Optional[Console] = None,
|
|
23
|
+
verbose: bool = False,
|
|
24
|
+
show_remediation: bool = True,
|
|
25
|
+
no_color: bool = False,
|
|
26
|
+
) -> None:
|
|
27
|
+
self.console = console or Console(no_color=no_color)
|
|
28
|
+
self.verbose = verbose
|
|
29
|
+
self.show_remediation = show_remediation
|
|
30
|
+
|
|
31
|
+
def _category_style(self, category: CheckCategory) -> str:
|
|
32
|
+
return {
|
|
33
|
+
CheckCategory.SYSTEM: "cyan",
|
|
34
|
+
CheckCategory.PING: "blue",
|
|
35
|
+
CheckCategory.TCP: "magenta",
|
|
36
|
+
CheckCategory.HTTP: "green",
|
|
37
|
+
CheckCategory.TLS: "bright_magenta",
|
|
38
|
+
CheckCategory.SSH: "yellow",
|
|
39
|
+
CheckCategory.DOCKER: "bright_blue",
|
|
40
|
+
CheckCategory.DNS: "bright_cyan",
|
|
41
|
+
CheckCategory.EXEC: "bright_white",
|
|
42
|
+
}.get(category, "white")
|
|
43
|
+
|
|
44
|
+
def _status_styled_text(self, status: CheckStatus) -> Text:
|
|
45
|
+
icons = {
|
|
46
|
+
CheckStatus.PASSED: "✔ PASS",
|
|
47
|
+
CheckStatus.WARNING: "⚠ WARN",
|
|
48
|
+
CheckStatus.FAILED: "✖ FAIL",
|
|
49
|
+
CheckStatus.SKIPPED: "⊘ SKIP",
|
|
50
|
+
CheckStatus.ERROR: "⚡ ERR",
|
|
51
|
+
}
|
|
52
|
+
styles = {
|
|
53
|
+
CheckStatus.PASSED: "bold green",
|
|
54
|
+
CheckStatus.WARNING: "bold yellow",
|
|
55
|
+
CheckStatus.FAILED: "bold red",
|
|
56
|
+
CheckStatus.SKIPPED: "dim",
|
|
57
|
+
CheckStatus.ERROR: "bold red on white",
|
|
58
|
+
}
|
|
59
|
+
return Text(icons.get(status, status.value), style=styles.get(status, "white"))
|
|
60
|
+
|
|
61
|
+
def render(self, report: MedicReport) -> None:
|
|
62
|
+
console = self.console
|
|
63
|
+
|
|
64
|
+
# Header Title
|
|
65
|
+
title_text = "🩺 [bold white]MEDIC[/bold white] Health Diagnostic"
|
|
66
|
+
subtitle = f"[dim]Executed {report.total_count} check{'s' if report.total_count != 1 else ''} in {report.duration_ms:.1f}ms • {report.timestamp.strftime('%Y-%m-%d %H:%M:%S UTC')}[/dim]"
|
|
67
|
+
|
|
68
|
+
console.print()
|
|
69
|
+
console.print(Panel(f"{title_text}\n{subtitle}", box=ROUNDED, border_style="cyan", padding=(0, 2)))
|
|
70
|
+
console.print()
|
|
71
|
+
|
|
72
|
+
if not report.results:
|
|
73
|
+
console.print("[yellow]No checks were executed. Specify flags like --all, --system, --http, --ping, etc.[/yellow]\n")
|
|
74
|
+
return
|
|
75
|
+
|
|
76
|
+
# Main Results Table
|
|
77
|
+
table = Table(
|
|
78
|
+
box=ROUNDED,
|
|
79
|
+
header_style="bold bright_white",
|
|
80
|
+
show_header=True,
|
|
81
|
+
expand=True,
|
|
82
|
+
padding=(0, 1),
|
|
83
|
+
)
|
|
84
|
+
|
|
85
|
+
table.add_column("Status", justify="center", width=9)
|
|
86
|
+
table.add_column("Category", justify="left", width=10)
|
|
87
|
+
table.add_column("Check Name", justify="left", style="bold", min_width=18)
|
|
88
|
+
table.add_column("Latency", justify="right", width=11)
|
|
89
|
+
table.add_column("Details / Output", justify="left", ratio=1)
|
|
90
|
+
|
|
91
|
+
for res in report.results:
|
|
92
|
+
cat_style = self._category_style(res.category)
|
|
93
|
+
cat_badge = Text(res.category.display_name, style=f"bold {cat_style}")
|
|
94
|
+
status_text = self._status_styled_text(res.status)
|
|
95
|
+
|
|
96
|
+
lat_str = f"{res.latency_ms:.1f} ms" if res.latency_ms is not None else "—"
|
|
97
|
+
lat_style = "green" if res.latency_ms and res.latency_ms < 150 else ("yellow" if res.latency_ms and res.latency_ms < 600 else "dim")
|
|
98
|
+
latency_text = Text(lat_str, style=lat_style)
|
|
99
|
+
|
|
100
|
+
msg_style = "white" if res.status == CheckStatus.PASSED else ("yellow" if res.status == CheckStatus.WARNING else "red")
|
|
101
|
+
message_text = Text(res.message, style=msg_style)
|
|
102
|
+
|
|
103
|
+
table.add_row(
|
|
104
|
+
status_text,
|
|
105
|
+
cat_badge,
|
|
106
|
+
res.name,
|
|
107
|
+
latency_text,
|
|
108
|
+
message_text,
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
console.print(table)
|
|
112
|
+
console.print()
|
|
113
|
+
|
|
114
|
+
# Detailed Breakdown for Failures / Warnings or when Verbose
|
|
115
|
+
issues = [r for r in report.results if r.status in (CheckStatus.WARNING, CheckStatus.FAILED, CheckStatus.ERROR)]
|
|
116
|
+
if issues and self.show_remediation:
|
|
117
|
+
remediation_items = []
|
|
118
|
+
for issue in issues:
|
|
119
|
+
icon = "✖" if issue.status in (CheckStatus.FAILED, CheckStatus.ERROR) else "⚠"
|
|
120
|
+
color = "red" if issue.status in (CheckStatus.FAILED, CheckStatus.ERROR) else "yellow"
|
|
121
|
+
header = f"[{color}]{icon} {issue.name}[/{color}] ({issue.target or issue.category.value})"
|
|
122
|
+
desc = f" [dim]Issue:[/dim] {issue.message}"
|
|
123
|
+
|
|
124
|
+
fix_hint = ""
|
|
125
|
+
if issue.remediation:
|
|
126
|
+
fix_hint = f"\n [bold cyan]Remediation:[/bold cyan] {issue.remediation}"
|
|
127
|
+
elif issue.details.get("exception"):
|
|
128
|
+
fix_hint = f"\n [dim red]Error:[/dim red] {issue.details.get('error')}"
|
|
129
|
+
|
|
130
|
+
remediation_items.append(f"{header}\n{desc}{fix_hint}")
|
|
131
|
+
|
|
132
|
+
panel_content = "\n\n".join(remediation_items)
|
|
133
|
+
console.print(
|
|
134
|
+
Panel(
|
|
135
|
+
panel_content,
|
|
136
|
+
title="[bold yellow]Action Items & Remediation Hints[/bold yellow]",
|
|
137
|
+
box=ROUNDED,
|
|
138
|
+
border_style="yellow",
|
|
139
|
+
padding=(1, 2),
|
|
140
|
+
)
|
|
141
|
+
)
|
|
142
|
+
console.print()
|
|
143
|
+
|
|
144
|
+
# Verbose details dump
|
|
145
|
+
if self.verbose:
|
|
146
|
+
verbose_tables = []
|
|
147
|
+
for res in report.results:
|
|
148
|
+
if res.details:
|
|
149
|
+
det_table = Table(title=f"Details: {res.name}", box=SIMPLE_HEAVY, show_header=False)
|
|
150
|
+
det_table.add_column("Key", style="cyan")
|
|
151
|
+
det_table.add_column("Value", style="white")
|
|
152
|
+
for k, v in res.details.items():
|
|
153
|
+
if k not in ("traceback", "raw_output", "headers") or self.verbose:
|
|
154
|
+
val_str = str(v)
|
|
155
|
+
if len(val_str) > 120 and not self.verbose:
|
|
156
|
+
val_str = val_str[:120] + "..."
|
|
157
|
+
det_table.add_row(k, val_str)
|
|
158
|
+
verbose_tables.append(det_table)
|
|
159
|
+
|
|
160
|
+
if verbose_tables:
|
|
161
|
+
console.print(Panel(Group(*verbose_tables), title="[bold blue]Diagnostic Details[/bold blue]", box=ROUNDED))
|
|
162
|
+
console.print()
|
|
163
|
+
|
|
164
|
+
# Summary Bar
|
|
165
|
+
summary_parts = [
|
|
166
|
+
f"[bold green]✔ {report.passed_count} passed[/bold green]",
|
|
167
|
+
]
|
|
168
|
+
if report.warning_count > 0:
|
|
169
|
+
summary_parts.append(f"[bold yellow]⚠ {report.warning_count} warning{'s' if report.warning_count != 1 else ''}[/bold yellow]")
|
|
170
|
+
if report.failed_count > 0:
|
|
171
|
+
summary_parts.append(f"[bold red]✖ {report.failed_count} failed[/bold red]")
|
|
172
|
+
if report.error_count > 0:
|
|
173
|
+
summary_parts.append(f"[bold magenta]⚡ {report.error_count} error{'s' if report.error_count != 1 else ''}[/bold magenta]")
|
|
174
|
+
if report.skipped_count > 0:
|
|
175
|
+
summary_parts.append(f"[dim]⊘ {report.skipped_count} skipped[/dim]")
|
|
176
|
+
|
|
177
|
+
summary_text = " ".join(summary_parts)
|
|
178
|
+
|
|
179
|
+
if report.is_healthy:
|
|
180
|
+
status_banner = "[bold white on green] ALL SYSTEMS HEALTHY [/bold white on green]"
|
|
181
|
+
elif report.failed_count == 0 and report.error_count == 0:
|
|
182
|
+
status_banner = "[bold black on yellow] WARNINGS DETECTED [/bold black on yellow]"
|
|
183
|
+
else:
|
|
184
|
+
status_banner = "[bold white on red] HEALTH CHECKS FAILED [/bold white on red]"
|
|
185
|
+
|
|
186
|
+
console.print(f"{status_banner} {summary_text} [dim]({report.duration_ms:.1f}ms total)[/dim]")
|
|
187
|
+
console.print()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"""Plain text and compact console formatters."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from typing import Optional, TextIO
|
|
5
|
+
|
|
6
|
+
from medic.core.enums import CheckStatus
|
|
7
|
+
from medic.core.models import MedicReport
|
|
8
|
+
|
|
9
|
+
from .base import BaseFormatter
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class TextFormatter(BaseFormatter):
|
|
13
|
+
"""Simple plain-text table formatter without rich ANSI dependency."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, stream: Optional[TextIO] = None, compact: bool = False) -> None:
|
|
16
|
+
self._stream = stream
|
|
17
|
+
self.compact = compact
|
|
18
|
+
|
|
19
|
+
@property
|
|
20
|
+
def stream(self) -> TextIO:
|
|
21
|
+
return self._stream if self._stream is not None else sys.stdout
|
|
22
|
+
def render(self, report: MedicReport) -> None:
|
|
23
|
+
out = self.stream
|
|
24
|
+
|
|
25
|
+
if self.compact:
|
|
26
|
+
for r in report.results:
|
|
27
|
+
status_char = "+" if r.status == CheckStatus.PASSED else ("!" if r.status == CheckStatus.WARNING else "-")
|
|
28
|
+
lat = f"{r.latency_ms:.1f}ms" if r.latency_ms is not None else "-"
|
|
29
|
+
out.write(f"[{status_char}] {r.category.value.upper():<6} {r.name:<25} {lat:>8} : {r.message}\n")
|
|
30
|
+
out.write(f"SUMMARY: {report.passed_count} passed, {report.warning_count} warn, {report.failed_count} fail, {report.error_count} err ({report.duration_ms:.1f}ms)\n")
|
|
31
|
+
out.flush()
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
out.write("================================================================================\n")
|
|
35
|
+
out.write(f" MEDIC Health Report - {report.timestamp.isoformat()}\n")
|
|
36
|
+
out.write("================================================================================\n\n")
|
|
37
|
+
|
|
38
|
+
# Table header
|
|
39
|
+
out.write(f"{'STATUS':<8} {'CATEGORY':<10} {'CHECK NAME':<24} {'LATENCY':<10} {'MESSAGE'}\n")
|
|
40
|
+
out.write("-" * 80 + "\n")
|
|
41
|
+
|
|
42
|
+
for r in report.results:
|
|
43
|
+
lat_str = f"{r.latency_ms:.1f}ms" if r.latency_ms is not None else "-"
|
|
44
|
+
out.write(f"{r.status.value.upper():<8} {r.category.display_name:<10} {r.name[:23]:<24} {lat_str:<10} {r.message}\n")
|
|
45
|
+
|
|
46
|
+
out.write("-" * 80 + "\n")
|
|
47
|
+
|
|
48
|
+
# Remediation
|
|
49
|
+
issues = [r for r in report.results if r.status in (CheckStatus.WARNING, CheckStatus.FAILED, CheckStatus.ERROR)]
|
|
50
|
+
if issues:
|
|
51
|
+
out.write("\nAction Items & Remediation:\n")
|
|
52
|
+
for issue in issues:
|
|
53
|
+
out.write(f" * [{issue.status.value.upper()}] {issue.name}: {issue.message}\n")
|
|
54
|
+
if issue.remediation:
|
|
55
|
+
out.write(f" Fix: {issue.remediation}\n")
|
|
56
|
+
out.write("\n")
|
|
57
|
+
|
|
58
|
+
status_word = "HEALTHY" if report.is_healthy else "ISSUES DETECTED"
|
|
59
|
+
out.write(f"\nResult: {status_word} ({report.passed_count} passed, {report.warning_count} warnings, {report.failed_count} failures in {report.duration_ms:.1f}ms)\n")
|
|
60
|
+
out.flush()
|
medic/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: medic-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: Health-check CLI for pipeline checkpoints, CI, and watch-mode monitoring
|
|
5
|
+
Author: Ali
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Rogsiel/medic
|
|
8
|
+
Project-URL: Issues, https://github.com/Rogsiel/medic/issues
|
|
9
|
+
Keywords: healthcheck,monitoring,cli,ci,devops,diagnostics
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Intended Audience :: System Administrators
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
20
|
+
Classifier: Topic :: System :: Monitoring
|
|
21
|
+
Classifier: Topic :: System :: Networking :: Monitoring
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: rich>=12.0.0
|
|
27
|
+
Requires-Dist: psutil>=5.9.0
|
|
28
|
+
Requires-Dist: requests>=2.28.0
|
|
29
|
+
Requires-Dist: cryptography>=38.0.0
|
|
30
|
+
Requires-Dist: argcomplete>=3.0.0
|
|
31
|
+
Requires-Dist: tomli>=2.0.0; python_version < "3.11"
|
|
32
|
+
Provides-Extra: dev
|
|
33
|
+
Requires-Dist: pytest>=7.0.0; extra == "dev"
|
|
34
|
+
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
|
|
35
|
+
Requires-Dist: mypy>=1.0.0; extra == "dev"
|
|
36
|
+
Requires-Dist: ruff>=0.5.0; extra == "dev"
|
|
37
|
+
Requires-Dist: types-requests; extra == "dev"
|
|
38
|
+
Requires-Dist: types-psutil; extra == "dev"
|
|
39
|
+
Requires-Dist: build; extra == "dev"
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# 🩺 medic
|
|
43
|
+
|
|
44
|
+
[](https://github.com/Rogsiel/medic/actions/workflows/ci.yml)
|
|
45
|
+
[](LICENSE)
|
|
46
|
+
|
|
47
|
+
A small health-check CLI. Use it as a **checkpoint in a pipeline** (exit code + JUnit), as a
|
|
48
|
+
**one-off diagnostic**, or as a **live terminal monitor** (`--watch`). No server, no daemon.
|
|
49
|
+
|
|
50
|
+
medic reports problems; it does not fix them.
|
|
51
|
+
|
|
52
|
+

|
|
53
|
+
|
|
54
|
+
## Checks
|
|
55
|
+
|
|
56
|
+
| Type | What it verifies |
|
|
57
|
+
|---|---|
|
|
58
|
+
| `system` | CPU, load, memory, swap, disk per mount, uptime |
|
|
59
|
+
| `ping` | ICMP reachability, packet loss, RTT (uses the system `ping`) |
|
|
60
|
+
| `tcp` | Port reachability, connect latency, optional banner |
|
|
61
|
+
| `http` | Status code, latency, body substring, TLS verification |
|
|
62
|
+
| `tls` | Certificate expiry (days left), issuer, SANs, protocol |
|
|
63
|
+
| `ssh` | Daemon reachability, protocol/banner, optional key auth |
|
|
64
|
+
| `dns` | Name resolution, optional expected addresses |
|
|
65
|
+
| `exec` | Run a command; pass on expected exit code / output |
|
|
66
|
+
|
|
67
|
+
## Install
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pipx install git+https://github.com/Rogsiel/medic.git
|
|
71
|
+
# or from a clone
|
|
72
|
+
pip install .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Requires Python 3.10+. Enable shell completion (bash, zsh, fish) with:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
medic --install-completion
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Quick start
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
medic # local system checks only (no network)
|
|
85
|
+
medic --all # + internet reachability (ping, HTTP, TLS)
|
|
86
|
+
medic --tcp db:5432 --http https://api.example.com/health --http-match ok
|
|
87
|
+
medic --tls example.com --tls-warn-days 30 --tls-crit-days 7
|
|
88
|
+
medic --dns example.com --exec "pg_isready -h db"
|
|
89
|
+
medic --system --disk / --disk /var --cpu-threshold 70,90 --ram-threshold 80,95
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Run `medic --help` for every flag.
|
|
93
|
+
|
|
94
|
+
## Pipelines and CI
|
|
95
|
+
|
|
96
|
+
Exit codes: `0` healthy, `1` a check failed (or warned, with `--fail-on warning`), `2` bad config.
|
|
97
|
+
|
|
98
|
+
Declare checks in TOML. Checks with a higher `stage` are **skipped if any lower stage fails**, which
|
|
99
|
+
gives you checkpoint semantics:
|
|
100
|
+
|
|
101
|
+
```toml
|
|
102
|
+
# medic.toml
|
|
103
|
+
[settings]
|
|
104
|
+
timeout = 6
|
|
105
|
+
fail_on = "failure" # or "warning"
|
|
106
|
+
|
|
107
|
+
[[check]]
|
|
108
|
+
type = "tcp"
|
|
109
|
+
target = "db:5432"
|
|
110
|
+
stage = 0
|
|
111
|
+
|
|
112
|
+
[[check]]
|
|
113
|
+
type = "http"
|
|
114
|
+
name = "API"
|
|
115
|
+
url = "https://api.example.com/health"
|
|
116
|
+
expect_status = [200]
|
|
117
|
+
match = "ok"
|
|
118
|
+
stage = 1
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
```bash
|
|
122
|
+
medic --config medic.toml --format junit > medic.xml
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Check keys by type:
|
|
126
|
+
|
|
127
|
+
| Type | Keys |
|
|
128
|
+
|---|---|
|
|
129
|
+
| `system` | `disks`, `cpu`, `ram`, `disk_threshold` (each `[warn, crit]`) |
|
|
130
|
+
| `ping` | `host`, `count` |
|
|
131
|
+
| `tcp` | `target` (`host:port`) or `host` + `port` |
|
|
132
|
+
| `http` | `url`, `method`, `expect_status`, `match`, `verify_ssl`, `headers` |
|
|
133
|
+
| `tls` | `target` or `host` + `port`, `warn_days`, `crit_days` |
|
|
134
|
+
| `ssh` | `target`, `user`, `key`, `auth` |
|
|
135
|
+
| `dns` | `host`, `expect` |
|
|
136
|
+
| `exec` | `command`, `expect_exit`, `match`, `shell`, `cwd` |
|
|
137
|
+
|
|
138
|
+
All checks also accept `name`, `stage`, `timeout`, `enabled`. Explicit CLI flags override `[settings]`.
|
|
139
|
+
Unknown types or keys are rejected.
|
|
140
|
+
|
|
141
|
+
Every check is bounded by its timeout (+2s grace). A hung check is reported as failed instead of
|
|
142
|
+
blocking the run. `--stop-on-failure` runs sequentially and stops at the first failure.
|
|
143
|
+
|
|
144
|
+
GitHub Actions example:
|
|
145
|
+
|
|
146
|
+
```yaml
|
|
147
|
+
- run: pipx install git+https://github.com/Rogsiel/medic.git
|
|
148
|
+
- run: medic --config medic.toml --format junit > medic.xml
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Watch mode
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
medic --config medic.toml --watch 5
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Re-runs every 5 seconds and redraws the report. Status transitions (e.g. `passed -> failed`) are
|
|
158
|
+
logged to stderr as `[change] ...`. Ctrl-C exits with the last run's exit code.
|
|
159
|
+
|
|
160
|
+
## Output formats
|
|
161
|
+
|
|
162
|
+
`--format rich` (default), `text`, `compact`, `json`, `junit`.
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
pip install -e '.[dev]'
|
|
168
|
+
pytest
|
|
169
|
+
ruff check .
|
|
170
|
+
mypy medic
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## License
|
|
174
|
+
|
|
175
|
+
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
medic/__init__.py,sha256=xudASjdVwTdfbHgXMXyAcoinkkCFfsqsAYrjmXe8zik,1105
|
|
2
|
+
medic/__main__.py,sha256=8GjXr4LG4P7eVWj40bj3C2jtS6Mm-rO62G3vkfwQP3o,142
|
|
3
|
+
medic/cli.py,sha256=kwb7aZ7RSeg60UF7HHukx7qIjizdFj7d4FGSpXnIP7o,19092
|
|
4
|
+
medic/completion.py,sha256=RA03ffz5lexrAcURYK23fWp4hX1QNsq1_gryacmqPR8,1721
|
|
5
|
+
medic/config.py,sha256=zpMIr-WAeDvouHu6mctWfDRXOt787C7YWPF8R8Kl6Fk,7271
|
|
6
|
+
medic/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
medic/checks/__init__.py,sha256=bxUjze1JC65pfYblW8YF9YyMo-KhdEHZ4P4APTkQcnM,546
|
|
8
|
+
medic/checks/dns.py,sha256=TIfVRdmvs8gIaN_OW5Fwq-38Z1t-WJMzr7m26F4C8a4,2274
|
|
9
|
+
medic/checks/exec.py,sha256=1wnRgt0s6ZzxwVijFX8r6ikquku3cG3IyUOsypnV2C0,3321
|
|
10
|
+
medic/checks/http.py,sha256=kqD7AlBabz6-KQSbT_8-VHY3Kd0S9px3i-8Exva-j4c,7400
|
|
11
|
+
medic/checks/ping.py,sha256=R4iJGviTCtHzLZj5H1EGSlI6mfqp2NJn5PmCtywHiPg,9725
|
|
12
|
+
medic/checks/ssh.py,sha256=z05nEKrvtcC_ayFeI3QRbEVxsMjL9kUha4WCEyZ0XSo,9436
|
|
13
|
+
medic/checks/system.py,sha256=wCWbq6YuB4ZHo-eRRP3xAgc-7GlQZ0W4W_MXuUE0AAw,15883
|
|
14
|
+
medic/checks/tcp.py,sha256=Rxl8DwlCAhqY3L9nbnZe0PpS9K987cpIslXBfugrsgE,7388
|
|
15
|
+
medic/checks/tls.py,sha256=Da8_EI2IENuQxSp56FcH8R5fBmAxyKfeIcdu2u1MBSg,10786
|
|
16
|
+
medic/core/__init__.py,sha256=rQqGBMuMrSPtH9_a0M4rcW0U6wN5-RONYHdnb4aPohc,434
|
|
17
|
+
medic/core/base.py,sha256=bQx0wQKeV01kxp-E5YHdHkrgyjO9cjy31arBkwyu6ww,1313
|
|
18
|
+
medic/core/enums.py,sha256=JHU_PotOUQfAWhr4XOkepaUZZ15NJrAREza7wdZyWE4,2195
|
|
19
|
+
medic/core/models.py,sha256=9OoSrMgQ8ArskjoPtagB2v0_BjIkK4faApEmTSQ9hTo,3962
|
|
20
|
+
medic/core/runner.py,sha256=D2v2U_ob0r0oxOaBwcREI2mVKq9T5K2PJc5ECL4GIX0,8514
|
|
21
|
+
medic/formatters/__init__.py,sha256=YLLpA4lG-BGoJxqTdOTQ6XBg21Aex1U1h7Bw-Fi9koE,1231
|
|
22
|
+
medic/formatters/base.py,sha256=DTraknBH3Y185of74Um0dayxPCUk5v5mxM3AUiIlckg,363
|
|
23
|
+
medic/formatters/json_formatter.py,sha256=lWYkTVkcXuRdbQDADNfjRxMv0T8uCPFB3xMcBzLVbbQ,741
|
|
24
|
+
medic/formatters/junit_formatter.py,sha256=6pkhFaEwt5D1EVAKx8pMigYqlWMt0balZYyg0hDZRxk,1974
|
|
25
|
+
medic/formatters/rich_formatter.py,sha256=tx_sq4q1ddFv4ZnpLBIyd7FUJI6-P7yYHM0U0m0nJ5k,8069
|
|
26
|
+
medic/formatters/text_formatter.py,sha256=9xo2kLi9af-vz3rW4H-4yhRORo_qWEeGn31J2wKHsbs,2761
|
|
27
|
+
medic_cli-0.1.1.dist-info/licenses/LICENSE,sha256=Bz5H3MtpNpTVPvu3BCs2Ecaafpc1NSQ-vekroqlZc9I,1060
|
|
28
|
+
medic_cli-0.1.1.dist-info/METADATA,sha256=sddsRNiGBwqXcAZfZdYj5pgWRDsxjE4jJxht6IyhLXg,5521
|
|
29
|
+
medic_cli-0.1.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
30
|
+
medic_cli-0.1.1.dist-info/entry_points.txt,sha256=7MBJv6OdV2h2MAC_sdEGrVNML6ChX0xFv1b5U0SfqRI,41
|
|
31
|
+
medic_cli-0.1.1.dist-info/top_level.txt,sha256=dhPC5NIKuiCD_UMxFeSv5ondC8XRYmhi44jtdZVtyBA,6
|
|
32
|
+
medic_cli-0.1.1.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ali
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
medic
|