uptime-kuma-cli 0.1.0__tar.gz

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.
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: uptime-kuma-cli
3
+ Version: 0.1.0
4
+ Summary: CLI tool for managing Uptime Kuma monitors
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/your-username/uptime-kuma-cli
7
+ Keywords: uptime-kuma,monitoring,cli
8
+ Classifier: Environment :: Console
9
+ Classifier: Topic :: System :: Monitoring
10
+ Requires-Python: >=3.13
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: rich>=14.3.3
13
+ Requires-Dist: typer>=0.24.1
14
+ Requires-Dist: uptime-kuma-api>=1.2.1
15
+
16
+ # uptime-kuma-cli
17
+
18
+ A command-line tool for managing [Uptime Kuma](https://github.com/louislam/uptime-kuma) monitors.
19
+
20
+ ## Installation
21
+
22
+ Requires Python >= 3.13.
23
+
24
+ ```bash
25
+ # Using uv
26
+ uv tool install .
27
+
28
+ # Or using pip
29
+ pip install .
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ Provide connection info via environment variables or CLI options:
35
+
36
+ ```bash
37
+ # Environment variables (recommended)
38
+ export KUMA_URL=http://localhost:3001
39
+ export KUMA_USERNAME=admin
40
+ export KUMA_PASSWORD=yourpassword
41
+
42
+ # Or CLI options
43
+ kuma --url http://localhost:3001 -u admin -p yourpassword <command>
44
+ ```
45
+
46
+ ## Commands
47
+
48
+ ### Server info
49
+
50
+ ```bash
51
+ kuma info
52
+ ```
53
+
54
+ ### List monitors
55
+
56
+ ```bash
57
+ kuma list
58
+ ```
59
+
60
+ Output example:
61
+
62
+ ```
63
+ ID Name Type Target Status Interval
64
+ 1 Google http https://google.com UP 60s
65
+ 2 Database port db.example.com:5432 DOWN 30s
66
+ 3 DNS Check dns example.com:53 PAUSED 60s
67
+ ```
68
+
69
+ ### Get monitor details
70
+
71
+ ```bash
72
+ kuma get 1
73
+ ```
74
+
75
+ ### Add a monitor
76
+
77
+ ```bash
78
+ # HTTP monitor
79
+ kuma add http "Google" "https://google.com"
80
+
81
+ # HTTP with custom interval (30s)
82
+ kuma add http "GitHub" "https://github.com" -i 30
83
+
84
+ # Ping monitor
85
+ kuma add ping "Server" "8.8.8.8"
86
+
87
+ # TCP port monitor
88
+ kuma add port "Database" "db.example.com" --port 5432
89
+
90
+ # DNS monitor
91
+ kuma add dns "DNS Check" "example.com" --dns-type A
92
+
93
+ # Keyword monitor (check if response contains a keyword)
94
+ kuma add keyword "Status Page" "https://example.com/health" -k "ok"
95
+ ```
96
+
97
+ Supported monitor types: `http`, `ping`, `port`, `dns`, `keyword`, `push`, `docker`, `mqtt`, `postgres`, `mysql`, `mongodb`, `redis`.
98
+
99
+ ### Edit a monitor
100
+
101
+ ```bash
102
+ kuma edit 1 --name "New Name"
103
+ kuma edit 1 --interval 30
104
+ kuma edit 1 --target "https://new-url.com"
105
+ ```
106
+
107
+ ### Pause / Resume
108
+
109
+ ```bash
110
+ kuma pause 1
111
+ kuma resume 1
112
+ ```
113
+
114
+ ### Delete a monitor
115
+
116
+ ```bash
117
+ kuma delete 1 # with confirmation prompt
118
+ kuma delete 1 -y # skip confirmation
119
+ ```
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,108 @@
1
+ # uptime-kuma-cli
2
+
3
+ A command-line tool for managing [Uptime Kuma](https://github.com/louislam/uptime-kuma) monitors.
4
+
5
+ ## Installation
6
+
7
+ Requires Python >= 3.13.
8
+
9
+ ```bash
10
+ # Using uv
11
+ uv tool install .
12
+
13
+ # Or using pip
14
+ pip install .
15
+ ```
16
+
17
+ ## Configuration
18
+
19
+ Provide connection info via environment variables or CLI options:
20
+
21
+ ```bash
22
+ # Environment variables (recommended)
23
+ export KUMA_URL=http://localhost:3001
24
+ export KUMA_USERNAME=admin
25
+ export KUMA_PASSWORD=yourpassword
26
+
27
+ # Or CLI options
28
+ kuma --url http://localhost:3001 -u admin -p yourpassword <command>
29
+ ```
30
+
31
+ ## Commands
32
+
33
+ ### Server info
34
+
35
+ ```bash
36
+ kuma info
37
+ ```
38
+
39
+ ### List monitors
40
+
41
+ ```bash
42
+ kuma list
43
+ ```
44
+
45
+ Output example:
46
+
47
+ ```
48
+ ID Name Type Target Status Interval
49
+ 1 Google http https://google.com UP 60s
50
+ 2 Database port db.example.com:5432 DOWN 30s
51
+ 3 DNS Check dns example.com:53 PAUSED 60s
52
+ ```
53
+
54
+ ### Get monitor details
55
+
56
+ ```bash
57
+ kuma get 1
58
+ ```
59
+
60
+ ### Add a monitor
61
+
62
+ ```bash
63
+ # HTTP monitor
64
+ kuma add http "Google" "https://google.com"
65
+
66
+ # HTTP with custom interval (30s)
67
+ kuma add http "GitHub" "https://github.com" -i 30
68
+
69
+ # Ping monitor
70
+ kuma add ping "Server" "8.8.8.8"
71
+
72
+ # TCP port monitor
73
+ kuma add port "Database" "db.example.com" --port 5432
74
+
75
+ # DNS monitor
76
+ kuma add dns "DNS Check" "example.com" --dns-type A
77
+
78
+ # Keyword monitor (check if response contains a keyword)
79
+ kuma add keyword "Status Page" "https://example.com/health" -k "ok"
80
+ ```
81
+
82
+ Supported monitor types: `http`, `ping`, `port`, `dns`, `keyword`, `push`, `docker`, `mqtt`, `postgres`, `mysql`, `mongodb`, `redis`.
83
+
84
+ ### Edit a monitor
85
+
86
+ ```bash
87
+ kuma edit 1 --name "New Name"
88
+ kuma edit 1 --interval 30
89
+ kuma edit 1 --target "https://new-url.com"
90
+ ```
91
+
92
+ ### Pause / Resume
93
+
94
+ ```bash
95
+ kuma pause 1
96
+ kuma resume 1
97
+ ```
98
+
99
+ ### Delete a monitor
100
+
101
+ ```bash
102
+ kuma delete 1 # with confirmation prompt
103
+ kuma delete 1 -y # skip confirmation
104
+ ```
105
+
106
+ ## License
107
+
108
+ MIT
@@ -0,0 +1,290 @@
1
+ import sys
2
+ from typing import Optional
3
+
4
+ import typer
5
+ from rich.console import Console
6
+ from rich.table import Table
7
+ from uptime_kuma_api import UptimeKumaApi, MonitorType
8
+
9
+ app = typer.Typer(help="Uptime Kuma CLI - manage monitors from the command line")
10
+ console = Console()
11
+
12
+ MONITOR_TYPES = {
13
+ "http": MonitorType.HTTP,
14
+ "port": MonitorType.PORT,
15
+ "ping": MonitorType.PING,
16
+ "dns": MonitorType.DNS,
17
+ "keyword": MonitorType.KEYWORD,
18
+ "push": MonitorType.PUSH,
19
+ "docker": MonitorType.DOCKER,
20
+ "mqtt": MonitorType.MQTT,
21
+ "postgres": MonitorType.POSTGRES,
22
+ "mysql": MonitorType.MYSQL,
23
+ "mongodb": MonitorType.MONGODB,
24
+ "redis": MonitorType.REDIS,
25
+ }
26
+
27
+ STATUS_TEXT = {
28
+ 0: "[red]DOWN[/red]",
29
+ 1: "[green]UP[/green]",
30
+ 2: "[yellow]PENDING[/yellow]",
31
+ 3: "[blue]MAINT[/blue]",
32
+ }
33
+
34
+
35
+ def connect(ctx: typer.Context) -> UptimeKumaApi:
36
+ cfg = ctx.ensure_object(dict)
37
+ url = cfg.get("url")
38
+ if not url:
39
+ console.print("[red]Error: URL is required. Set KUMA_URL or use --url.[/red]")
40
+ raise typer.Exit(1)
41
+ try:
42
+ api = UptimeKumaApi(url)
43
+ username = cfg.get("username")
44
+ password = cfg.get("password")
45
+ if username and password:
46
+ api.login(username, password)
47
+ else:
48
+ api.login()
49
+ return api
50
+ except Exception as e:
51
+ console.print(f"[red]Failed to connect: {e}[/red]")
52
+ raise typer.Exit(1)
53
+
54
+
55
+ def get_status_map(api: UptimeKumaApi) -> dict[int, int]:
56
+ """Build monitor_id -> latest status map from heartbeat data."""
57
+ try:
58
+ heartbeats = api.get_heartbeats()
59
+ status_map = {}
60
+ if isinstance(heartbeats, dict):
61
+ for mid_str, hb_data in heartbeats.items():
62
+ mid = int(mid_str)
63
+ hb_list = hb_data if isinstance(hb_data, list) else hb_data.get("data", [])
64
+ if hb_list:
65
+ status_map[mid] = hb_list[-1].get("status", -1)
66
+ elif isinstance(heartbeats, list):
67
+ for item in heartbeats:
68
+ mid = item.get("monitorID", item.get("id"))
69
+ data = item.get("data", [])
70
+ if mid and data:
71
+ status_map[int(mid)] = data[-1].get("status", -1)
72
+ return status_map
73
+ except Exception:
74
+ return {}
75
+
76
+
77
+ @app.callback()
78
+ def callback(
79
+ ctx: typer.Context,
80
+ url: Optional[str] = typer.Option(None, "--url", envvar="KUMA_URL", help="Uptime Kuma server URL"),
81
+ username: Optional[str] = typer.Option(None, "--username", "-u", envvar="KUMA_USERNAME", help="Username"),
82
+ password: Optional[str] = typer.Option(None, "--password", "-p", envvar="KUMA_PASSWORD", help="Password"),
83
+ ):
84
+ """Uptime Kuma CLI - manage monitors from the command line.
85
+
86
+ Set KUMA_URL, KUMA_USERNAME, KUMA_PASSWORD environment variables or use --url, --username, --password options.
87
+ """
88
+ ctx.ensure_object(dict)
89
+ ctx.obj["url"] = url
90
+ ctx.obj["username"] = username
91
+ ctx.obj["password"] = password
92
+
93
+
94
+ @app.command()
95
+ def info(ctx: typer.Context):
96
+ """Show server info."""
97
+ api = connect(ctx)
98
+ try:
99
+ data = api.info()
100
+ console.print(f"Version: {data.get('version', 'N/A')}")
101
+ console.print(f"Latency: {data.get('latency', 'N/A')}ms")
102
+ finally:
103
+ api.disconnect()
104
+
105
+
106
+ @app.command("list")
107
+ def list_monitors(ctx: typer.Context):
108
+ """List all monitors."""
109
+ api = connect(ctx)
110
+ try:
111
+ monitors = api.get_monitors()
112
+ if not monitors:
113
+ console.print("No monitors found.")
114
+ return
115
+
116
+ status_map = get_status_map(api)
117
+
118
+ table = Table()
119
+ table.add_column("ID", style="cyan", justify="right")
120
+ table.add_column("Name", style="bold")
121
+ table.add_column("Type")
122
+ table.add_column("Target")
123
+ table.add_column("Status")
124
+ table.add_column("Interval", justify="right")
125
+
126
+ for m in sorted(monitors, key=lambda x: x.get("id", 0)):
127
+ mid = m.get("id")
128
+ mtype = m.get("type", "")
129
+ target = m.get("url") or m.get("hostname") or ""
130
+ if m.get("port"):
131
+ target += f":{m['port']}"
132
+
133
+ if not m.get("active", True):
134
+ status = "[dim]PAUSED[/dim]"
135
+ else:
136
+ status = STATUS_TEXT.get(status_map.get(mid, -1), "[dim]--[/dim]")
137
+
138
+ interval = f"{m.get('interval', '?')}s"
139
+ table.add_row(str(mid), m.get("name", ""), str(mtype), target, status, interval)
140
+
141
+ console.print(table)
142
+ finally:
143
+ api.disconnect()
144
+
145
+
146
+ @app.command()
147
+ def get(ctx: typer.Context, monitor_id: int = typer.Argument(help="Monitor ID")):
148
+ """Get monitor details."""
149
+ api = connect(ctx)
150
+ try:
151
+ m = api.get_monitor(monitor_id)
152
+ table = Table(show_header=False, box=None, padding=(0, 2))
153
+ table.add_column("Field", style="bold cyan")
154
+ table.add_column("Value")
155
+
156
+ fields = [
157
+ ("ID", "id"), ("Name", "name"), ("Type", "type"),
158
+ ("URL", "url"), ("Hostname", "hostname"), ("Port", "port"),
159
+ ("Active", "active"), ("Interval", "interval"),
160
+ ("Retry Interval", "retryInterval"), ("Max Retries", "maxretries"),
161
+ ("Description", "description"), ("Keyword", "keyword"),
162
+ ("Accepted Codes", "accepted_statuscodes"),
163
+ ]
164
+ for label, key in fields:
165
+ val = m.get(key)
166
+ if val is not None and val != "":
167
+ table.add_row(label, str(val))
168
+
169
+ console.print(table)
170
+ finally:
171
+ api.disconnect()
172
+
173
+
174
+ @app.command()
175
+ def add(
176
+ ctx: typer.Context,
177
+ monitor_type: str = typer.Argument(help="Monitor type (http, ping, port, dns, keyword, push, ...)"),
178
+ name: str = typer.Argument(help="Monitor name"),
179
+ target: str = typer.Argument(help="URL (for http/keyword) or hostname (for ping/port/dns)"),
180
+ port: Optional[int] = typer.Option(None, "--port", help="Port number (for port/dns type)"),
181
+ interval: int = typer.Option(60, "--interval", "-i", help="Check interval in seconds"),
182
+ keyword: Optional[str] = typer.Option(None, "--keyword", "-k", help="Keyword to search (for keyword type)"),
183
+ dns_type: str = typer.Option("A", "--dns-type", help="DNS record type (for dns type)"),
184
+ ):
185
+ """Add a new monitor."""
186
+ if monitor_type not in MONITOR_TYPES:
187
+ console.print(f"[red]Unknown type '{monitor_type}'. Available: {', '.join(MONITOR_TYPES)}[/red]")
188
+ raise typer.Exit(1)
189
+
190
+ api = connect(ctx)
191
+ try:
192
+ kwargs: dict = {
193
+ "type": MONITOR_TYPES[monitor_type],
194
+ "name": name,
195
+ "interval": interval,
196
+ }
197
+
198
+ if monitor_type in ("http", "keyword", "mqtt"):
199
+ kwargs["url"] = target
200
+ elif monitor_type in ("ping", "port", "dns"):
201
+ kwargs["hostname"] = target
202
+ else:
203
+ kwargs["url"] = target
204
+
205
+ if port is not None:
206
+ kwargs["port"] = port
207
+ if monitor_type == "keyword" and keyword:
208
+ kwargs["keyword"] = keyword
209
+ if monitor_type == "dns":
210
+ kwargs["dns_resolve_type"] = dns_type
211
+ kwargs["port"] = port or 53
212
+ kwargs["dns_resolve_server"] = "1.1.1.1"
213
+
214
+ result = api.add_monitor(**kwargs)
215
+ console.print(f"[green]Monitor added (ID: {result['monitorID']})[/green]")
216
+ finally:
217
+ api.disconnect()
218
+
219
+
220
+ @app.command()
221
+ def edit(
222
+ ctx: typer.Context,
223
+ monitor_id: int = typer.Argument(help="Monitor ID"),
224
+ name: Optional[str] = typer.Option(None, "--name", help="New name"),
225
+ url: Optional[str] = typer.Option(None, "--target", help="New URL or hostname"),
226
+ interval: Optional[int] = typer.Option(None, "--interval", "-i", help="New interval in seconds"),
227
+ ):
228
+ """Edit a monitor."""
229
+ api = connect(ctx)
230
+ try:
231
+ kwargs = {}
232
+ if name is not None:
233
+ kwargs["name"] = name
234
+ if url is not None:
235
+ kwargs["url"] = url
236
+ if interval is not None:
237
+ kwargs["interval"] = interval
238
+
239
+ if not kwargs:
240
+ console.print("[yellow]No changes specified.[/yellow]")
241
+ return
242
+
243
+ api.edit_monitor(monitor_id, **kwargs)
244
+ console.print(f"[green]Monitor {monitor_id} updated.[/green]")
245
+ finally:
246
+ api.disconnect()
247
+
248
+
249
+ @app.command()
250
+ def delete(
251
+ ctx: typer.Context,
252
+ monitor_id: int = typer.Argument(help="Monitor ID"),
253
+ yes: bool = typer.Option(False, "--yes", "-y", help="Skip confirmation"),
254
+ ):
255
+ """Delete a monitor."""
256
+ if not yes:
257
+ typer.confirm(f"Delete monitor {monitor_id}?", abort=True)
258
+
259
+ api = connect(ctx)
260
+ try:
261
+ api.delete_monitor(monitor_id)
262
+ console.print(f"[green]Monitor {monitor_id} deleted.[/green]")
263
+ finally:
264
+ api.disconnect()
265
+
266
+
267
+ @app.command()
268
+ def pause(ctx: typer.Context, monitor_id: int = typer.Argument(help="Monitor ID")):
269
+ """Pause a monitor."""
270
+ api = connect(ctx)
271
+ try:
272
+ api.pause_monitor(monitor_id)
273
+ console.print(f"[green]Monitor {monitor_id} paused.[/green]")
274
+ finally:
275
+ api.disconnect()
276
+
277
+
278
+ @app.command()
279
+ def resume(ctx: typer.Context, monitor_id: int = typer.Argument(help="Monitor ID")):
280
+ """Resume a monitor."""
281
+ api = connect(ctx)
282
+ try:
283
+ api.resume_monitor(monitor_id)
284
+ console.print(f"[green]Monitor {monitor_id} resumed.[/green]")
285
+ finally:
286
+ api.disconnect()
287
+
288
+
289
+ if __name__ == "__main__":
290
+ app()
@@ -0,0 +1,23 @@
1
+ [project]
2
+ name = "uptime-kuma-cli"
3
+ version = "0.1.0"
4
+ description = "CLI tool for managing Uptime Kuma monitors"
5
+ readme = "README.md"
6
+ requires-python = ">=3.13"
7
+ license = "MIT"
8
+ keywords = ["uptime-kuma", "monitoring", "cli"]
9
+ classifiers = [
10
+ "Environment :: Console",
11
+ "Topic :: System :: Monitoring",
12
+ ]
13
+ dependencies = [
14
+ "rich>=14.3.3",
15
+ "typer>=0.24.1",
16
+ "uptime-kuma-api>=1.2.1",
17
+ ]
18
+
19
+ [project.urls]
20
+ Repository = "https://github.com/your-username/uptime-kuma-cli"
21
+
22
+ [project.scripts]
23
+ kuma = "main:app"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,123 @@
1
+ Metadata-Version: 2.4
2
+ Name: uptime-kuma-cli
3
+ Version: 0.1.0
4
+ Summary: CLI tool for managing Uptime Kuma monitors
5
+ License-Expression: MIT
6
+ Project-URL: Repository, https://github.com/your-username/uptime-kuma-cli
7
+ Keywords: uptime-kuma,monitoring,cli
8
+ Classifier: Environment :: Console
9
+ Classifier: Topic :: System :: Monitoring
10
+ Requires-Python: >=3.13
11
+ Description-Content-Type: text/markdown
12
+ Requires-Dist: rich>=14.3.3
13
+ Requires-Dist: typer>=0.24.1
14
+ Requires-Dist: uptime-kuma-api>=1.2.1
15
+
16
+ # uptime-kuma-cli
17
+
18
+ A command-line tool for managing [Uptime Kuma](https://github.com/louislam/uptime-kuma) monitors.
19
+
20
+ ## Installation
21
+
22
+ Requires Python >= 3.13.
23
+
24
+ ```bash
25
+ # Using uv
26
+ uv tool install .
27
+
28
+ # Or using pip
29
+ pip install .
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ Provide connection info via environment variables or CLI options:
35
+
36
+ ```bash
37
+ # Environment variables (recommended)
38
+ export KUMA_URL=http://localhost:3001
39
+ export KUMA_USERNAME=admin
40
+ export KUMA_PASSWORD=yourpassword
41
+
42
+ # Or CLI options
43
+ kuma --url http://localhost:3001 -u admin -p yourpassword <command>
44
+ ```
45
+
46
+ ## Commands
47
+
48
+ ### Server info
49
+
50
+ ```bash
51
+ kuma info
52
+ ```
53
+
54
+ ### List monitors
55
+
56
+ ```bash
57
+ kuma list
58
+ ```
59
+
60
+ Output example:
61
+
62
+ ```
63
+ ID Name Type Target Status Interval
64
+ 1 Google http https://google.com UP 60s
65
+ 2 Database port db.example.com:5432 DOWN 30s
66
+ 3 DNS Check dns example.com:53 PAUSED 60s
67
+ ```
68
+
69
+ ### Get monitor details
70
+
71
+ ```bash
72
+ kuma get 1
73
+ ```
74
+
75
+ ### Add a monitor
76
+
77
+ ```bash
78
+ # HTTP monitor
79
+ kuma add http "Google" "https://google.com"
80
+
81
+ # HTTP with custom interval (30s)
82
+ kuma add http "GitHub" "https://github.com" -i 30
83
+
84
+ # Ping monitor
85
+ kuma add ping "Server" "8.8.8.8"
86
+
87
+ # TCP port monitor
88
+ kuma add port "Database" "db.example.com" --port 5432
89
+
90
+ # DNS monitor
91
+ kuma add dns "DNS Check" "example.com" --dns-type A
92
+
93
+ # Keyword monitor (check if response contains a keyword)
94
+ kuma add keyword "Status Page" "https://example.com/health" -k "ok"
95
+ ```
96
+
97
+ Supported monitor types: `http`, `ping`, `port`, `dns`, `keyword`, `push`, `docker`, `mqtt`, `postgres`, `mysql`, `mongodb`, `redis`.
98
+
99
+ ### Edit a monitor
100
+
101
+ ```bash
102
+ kuma edit 1 --name "New Name"
103
+ kuma edit 1 --interval 30
104
+ kuma edit 1 --target "https://new-url.com"
105
+ ```
106
+
107
+ ### Pause / Resume
108
+
109
+ ```bash
110
+ kuma pause 1
111
+ kuma resume 1
112
+ ```
113
+
114
+ ### Delete a monitor
115
+
116
+ ```bash
117
+ kuma delete 1 # with confirmation prompt
118
+ kuma delete 1 -y # skip confirmation
119
+ ```
120
+
121
+ ## License
122
+
123
+ MIT
@@ -0,0 +1,9 @@
1
+ README.md
2
+ main.py
3
+ pyproject.toml
4
+ uptime_kuma_cli.egg-info/PKG-INFO
5
+ uptime_kuma_cli.egg-info/SOURCES.txt
6
+ uptime_kuma_cli.egg-info/dependency_links.txt
7
+ uptime_kuma_cli.egg-info/entry_points.txt
8
+ uptime_kuma_cli.egg-info/requires.txt
9
+ uptime_kuma_cli.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kuma = main:app
@@ -0,0 +1,3 @@
1
+ rich>=14.3.3
2
+ typer>=0.24.1
3
+ uptime-kuma-api>=1.2.1