
REST API reference
Endpoints, protected by tokens, for reading how your server is doing and managing its cron jobs. Every request, response and parameter.
Overview
The ZabMonitor REST API lets your own programs read how a server is doing and, if you allow it, manage its cron jobs. It is optional: it exists only if you answered yes to "Enable the public REST API?" when running install.sh, or turned it on later with sudo ./install.sh rest-enable. It is separate from the dashboard's own API (/api/v1, protected by the API key): a token never works there and the API key never works here.
| Item | Value |
|---|---|
| Base URL | https://<your-domain>/rest/v1 (HTTPS is required unless the agent is local-only, reached through an SSH tunnel). |
| Format | JSON, UTF-8. Requests with a body send Content-Type: application/json. |
| Authentication | Authorization: Bearer <token> on every call. See Authentication. |
| Units | Times are Unix seconds (UTC) unless a field says otherwise (ts in the request log is milliseconds; day/today are YYYY-MM-DD in the job's own zone). Sizes are bytes. Percentages are 0-100 with one decimal. |
| Freshness | Metrics are sampled every 3 seconds; responses are never cached (Cache-Control: no-store). |
| Rate limit | 240 requests per minute per client address by default (429 + Retry-After). |
| Lockout | 5 wrong tokens within 5 minutes lock that address out for 15 minutes (everything it sends gets 429, even correct tokens). |
| Body size | At most 256 KB, only on the cron write endpoints. |
| Methods | GET (and HEAD) everywhere; POST, PUT and DELETE only below /cron/. |
| Browsers | Not meant for browser pages: no CORS headers are sent. Call it from servers, scripts and tools. |
Quick start
export TOKEN='zmt_9e085d6a_...your token...'
curl -s -H "Authorization: Bearer $TOKEN" https://mon.example.com/rest/v1/statusResponse: see Status summary. A 401 means the token is wrong, revoked or expired; 404 "the REST API is not enabled" means it is switched off on the server.
Getting and managing tokens
Tokens are created only on the server, as root, with install.sh. Nothing reachable over HTTP can create or change a token, so a stolen token cannot mint new ones.
| Task | Command |
|---|---|
| Turn the API on (asks what the first token may do, shows it once) | sudo ./install.sh rest-enable |
| Same during installation | answer yes to Enable the public REST API?, or --rest [--rest-scopes ...] [--rest-name N] [--rest-days D] [--rest-allow IPS] with -y |
| Create another token | sudo ./install.sh rest-token create NAME --rest-scopes metrics:read,cron:read --rest-days 90 --rest-allow 203.0.113.0/24 |
| List tokens (id, state, scopes, expiry, allowed addresses; never secrets) | sudo ./install.sh rest-token list |
| Revoke a token (works immediately, no restart) | sudo ./install.sh rest-token revoke ID |
| Turn the API off (tokens are kept but refused) | sudo ./install.sh rest-disable |
- Format:
zmt_<8 hex id>_<40 letters and digits>. It is shown once; the server keeps only a salted hash in/etc/zabmonitor/tokens.json(root-owned) and cannot show it again. Lost it? Revoke it and make a new one. - Expiry: 365 days by default (
--rest-days 0= never). Check with GET /token. - Address limit:
--rest-allowrestricts a token to listed IP addresses or ranges (IPv4 or IPv6). A valid token used from elsewhere gets 403 and counts towards the lockout. - Several tokens: make one per program, with only the scopes it needs, so you can revoke one without touching the others.
Authentication and scopes
Send the token in the Authorization header. It is never accepted in the URL, in a query string or in another header.
Authorization: Bearer zmt_9e085d6a_Xk3Pq9...| Scope | Allows | Notes |
|---|---|---|
metrics:read | All endpoints under Metrics. | Safe for dashboards and alerting. Exposes process names and PIDs, never command lines. |
logs:read | The request log. | Shows client addresses, paths and user agents of everyone who called the server. |
cron:read | Read jobs, runs, output, audit trail; preview schedules. | Sensitive: job scripts and their output may contain secrets. |
cron:write | Create, change, delete, enable, disable and run jobs (implies cron:read). | Equals running commands on the server as the allowed cron users. Give it only to programs you trust, restrict it by IP address, and prefer a low-privilege cron user. |
The cron scopes only work while the Cron Jobs manager is on, and the user a job runs as must be on the administrator's allow-list, whatever the token says. The administrator can also forbid typed scripts (cron-inline off): then only script_path jobs can be created.
Errors
Errors are JSON with an error message: {"error": "invalid or missing token"}. A 403 for a missing scope adds required_scope.
| Status | Meaning |
|---|---|
400 | Bad input. The error text says what is wrong (bad number, invalid schedule, run_as not allowed, ...). |
401 | Missing, malformed, wrong, revoked or expired token. The text tells which. Wrong tokens count towards the lockout. |
403 | The token is valid but lacks the scope (required_scope is included), or it is used from an address it is not allowed from. |
404 | Unknown endpoint or id, or the feature is not enabled (REST API off, cron manager off). |
405 | Wrong method for that endpoint. Writing exists only under /rest/v1/cron/; PATCH is not supported (use PUT). |
408 / 411 | Body not received in time / chunked uploads are not accepted: send Content-Length. |
413 | Body larger than 256 KB. |
415 | A body needs Content-Type: application/json. |
429 | Too many requests (default 240 per minute per client address) or the address is locked out after repeated wrong tokens. Retry-After says how many seconds to wait. |
503 | Metrics are still warming up (first seconds after a start), or the cron runner service is not running. |
Examples
{
"error": "invalid or missing token"
} <- 401{
"error": "this token lacks the required scope",
"required_scope": "logs:read"
} <- 403 (token without logs:read){
"error": "job not found"
} <- 404{
"error": "invalid schedule: a schedule needs 5 fields: minute hour day-of-month month day-of-week"
} <- 400Service
Two housekeeping endpoints that any valid token may call.
API index
GET /rest/v1
Needs: any valid token
Lists the endpoints this token may call, so a client can discover what it is allowed to do.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1Response 200 OK
{
"name": "ZabMonitor REST API",
"version": "1",
"time": 1794044462,
"endpoints": [
{
"method": "GET",
"path": "/rest/v1",
"scope": null
},
{
"method": "GET",
"path": "/rest/v1/token",
"scope": null
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
name | string | Always ZabMonitor REST API. |
version | string | API version, currently 1. |
time | integer | Server time, Unix seconds. |
endpoints | array | Objects with method, path and scope (null = any valid token). Only endpoints the token's scopes allow are listed. |
Inspect your token
GET /rest/v1/token
Needs: any valid token
Shows the calling token's own details (never its secret). Use it to check scopes and the expiry date.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/tokenResponse 200 OK
{
"id": "d310ffff",
"name": "demo-full",
"scopes": [
"metrics:read",
"logs:read"
],
"created": 1794044461,
"expires": null,
"allowed_ips": []
}Response fields
| Field | Type | Meaning |
|---|---|---|
id | string | 8-character token id (also appears in the request log and the cron audit trail). |
name | string | Name given when the token was created. |
scopes | array | Scopes the token holds. |
created | integer | Creation time, Unix seconds. |
expires | integer|null | Expiry time, Unix seconds; null = never. |
allowed_ips | array | IP addresses/ranges the token is limited to; empty = anywhere. |
Metrics
Read-only monitoring data. Values come from a sampler that refreshes every 3 seconds, so calling more often than that returns the same numbers. All endpoints need metrics:read. They answer 503 for the first few seconds after the service starts.
Status summary
GET /rest/v1/status
Needs: metrics:read
The one-call health check: overall status plus the headline numbers. Cheap enough to poll every few seconds.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/statusResponse 200 OK
{
"status": "ok",
"time": 1794044462,
"name": "Production Web 01",
"hostname": "demo-server",
"uptime": 90000,
"cpu_percent": 23.9,
"memory_percent": 48.1,
"disk_max_percent": 82.0,
"alerts": []
}Response fields
| Field | Type | Meaning |
|---|---|---|
status | string | ok, warning (CPU, memory or a disk at 85% or more) or critical (95% or more, or a watched service is not active). |
time | integer | When the numbers were sampled, Unix seconds (sampled every 3 s). |
name | string | Display name chosen at install time (hostname if none). |
hostname | string | The machine's hostname. |
uptime | integer | Seconds since boot. |
cpu_percent | number | Total CPU use, 0-100. |
memory_percent | number | Memory in use (excluding reclaimable cache), 0-100. |
disk_max_percent | number | Fullest disk, 0-100. |
alerts | array | Human-readable reasons for any warning/critical status; empty when ok. |
Server information
GET /rest/v1/server
Needs: metrics:read
Identity and state of the machine.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/serverResponse 200 OK
{
"time": 1794044462,
"status": "ok",
"alerts": [],
"host": {
"name": "Production Web 01",
"hostname": "demo-server",
"os": "Ubuntu 24.04 LTS (simulated)",
"kernel": "6.8.0",
"arch": "x86_64",
"uptime": 90000
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time, Unix seconds. |
status | string | Same as in status. |
alerts | array | Same as in status. |
host | object | name (display name), hostname, os (pretty OS name), kernel, arch, uptime (seconds). |
CPU
GET /rest/v1/cpu
Needs: metrics:read
CPU use and load averages.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cpuResponse 200 OK
{
"time": 1794044462,
"percent": 23.9,
"cores": 4,
"load": [
0.42,
0.37
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
percent | number | Total CPU use across all cores since the previous sample, 0-100. |
cores | integer | Number of logical CPUs. |
load | array | Load average over 1, 5 and 15 minutes. |
Memory and swap
GET /rest/v1/memory
Needs: metrics:read
All sizes are in bytes.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/memoryResponse 200 OK
{
"time": 1794044462,
"total": 8589934592,
"used": 4131758538,
"available": 4458176053,
"percent": 48.1,
"swap_total": 2147483648,
"swap_used": 107374182,
"swap_percent": 5.0
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
total | integer | Installed memory. |
used | integer | Memory in use (total minus available). |
available | integer | Memory that can be given to programs without swapping. |
percent | number | used as a percentage of total. |
swap_total | integer | Swap size (0 if none). |
swap_used | integer | Swap in use. |
swap_percent | number | Swap in use, 0-100. |
Disks
GET /rest/v1/disks
Needs: metrics:read
Mounted real file systems (ext4, xfs, btrfs, ...). Virtual and container mounts are left out.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/disksResponse 200 OK
{
"time": 1794044462,
"disks": [
{
"mount": "/",
"fs": "ext4",
"total": 107374182400,
"used": 67645734912,
"percent": 63.0
},
{
"mount": "/data",
"fs": "xfs",
"total": 536870912000,
"used": 440234147840,
"percent": 82.0
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
disks | array | Objects: mount (mount point), fs (type), total, used (bytes), percent (0-100). |
Network
GET /rest/v1/network
Needs: metrics:read
Totals and current speed across all physical interfaces (loopback, Docker and virtual interfaces are excluded).
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/networkResponse 200 OK
{
"time": 1794044462,
"rx_bytes": 55834574848,
"tx_bytes": 9663676416,
"rx_rate": 161966,
"tx_rate": 42377
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
rx_bytes | integer | Bytes received since boot. |
tx_bytes | integer | Bytes sent since boot. |
rx_rate | integer | Current receive speed, bytes per second. |
tx_rate | integer | Current send speed, bytes per second. |
Temperature
GET /rest/v1/temperature
Needs: metrics:read
Highest thermal-zone temperature.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/temperatureResponse 200 OK
{
"time": 1794044462,
"celsius": 54.0
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
celsius | number|null | Degrees Celsius; null when the machine exposes no sensor (many virtual servers). |
Watched services
GET /rest/v1/services
Needs: metrics:read
The systemd services chosen at install time (--services), checked every 10 seconds. An empty list means none are watched.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/servicesResponse 200 OK
{
"time": 1794044462,
"services": [
{
"name": "nginx",
"state": "active",
"active": true
},
{
"name": "sshd",
"state": "active",
"active": true
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
services | array | Objects: name, state (the systemctl is-active answer, e.g. active, inactive, failed), active (boolean). |
Top processes
GET /rest/v1/processes
Needs: metrics:read
The five biggest CPU and memory users. Only the process name and PID are exposed, never command lines or arguments.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/processesResponse 200 OK
{
"time": 1794044462,
"count": 143,
"top_cpu": [
{
"pid": 811,
"name": "mysqld",
"cpu": 12.4,
"mem": 671088640
},
{
"pid": 1203,
"name": "nginx",
"cpu": 3.1,
"mem": 41943040
}
],
"top_mem": [
{
"pid": 811,
"name": "mysqld",
"cpu": 12.4,
"mem": 671088640
},
{
"pid": 2210,
"name": "python3",
"cpu": 1.0,
"mem": 220200960
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
time | integer | Sample time. |
count | integer | Total number of processes. |
top_cpu | array | Objects: pid, name (max 32 characters), cpu (percent of one core), mem (resident bytes). |
top_mem | array | Same objects, ordered by memory. |
Everything at once
GET /rest/v1/metrics
Needs: metrics:read
All of the above in one document.
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
history | integer | 0 | 1 adds a history array (the last ~6 minutes, see history). |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/metricsResponse 200 OK
{
"time": 1794044462,
"status": "ok",
"alerts": [],
"host": {
"name": "Production Web 01",
"hostname": "demo-server",
"os": "Ubuntu 24.04 LTS (simulated)",
"kernel": "6.8.0",
"arch": "x86_64",
"uptime": 90000
},
"cpu": {
"percent": 24.0,
"cores": 4,
"load": [
0.42,
0.37
]
},
"memory": {
"total": 8589934592,
"used": 4131758538,
"available": 4458176053,
"percent": 48.1,
"swap_total": 2147483648,
"swap_used": 107374182,
"swap_percent": 5.0
},
"disks": [
{
"mount": "/",
"fs": "ext4",
"total": 107374182400,
"used": 67645734912,
"percent": 63.0
},
{
"mount": "/data",
"fs": "xfs",
"total": 536870912000,
"used": 440234147840,
"percent": 82.0
}
],
"network": {
"rx_bytes": 55834574848,
"tx_bytes": 9663676416,
"rx_rate": 162038,
"tx_rate": 42392
},
"temperature": 54.0,
"services": [
{
"name": "nginx",
"state": "active",
"active": true
},
{
"name": "sshd",
"state": "active",
"active": true
}
],
"processes": {
"count": 143,
"top_cpu": [
{
"pid": 811,
"name": "mysqld",
"cpu": 12.4,
"mem": 671088640
},
{
"pid": 1203,
"name": "nginx",
"cpu": 3.1,
"mem": 41943040
}
],
"top_mem": [
{
"pid": 811,
"name": "mysqld",
"cpu": 12.4,
"mem": 671088640
},
{
"pid": 2210,
"name": "python3",
"cpu": 1.0,
"mem": 220200960
}
]
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
time, status, alerts, host, cpu, memory, disks, network, temperature, services, processes | Exactly the objects described for the individual endpoints, in one response. |
Recent history
GET /rest/v1/history
Needs: metrics:read
The in-memory history of the last ~6 minutes (one point every 3 seconds, up to 120 points). It is lost when the service restarts. For long-term graphs, collect the numbers yourself by polling.
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
limit | integer | 120 | How many of the newest points to return (1-120). |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://mon.example.com/rest/v1/history?limit=3"Response 200 OK
{
"interval_seconds": 3,
"points": [
{
"t": 1794044462,
"cpu": 24.0,
"mem": 48.1,
"rx": 162020,
"tx": 42388
},
{
"t": 1794044462,
"cpu": 24.0,
"mem": 48.1,
"rx": 162038,
"tx": 42392
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
interval_seconds | integer | Seconds between points. |
points | array | Oldest first. Objects: t (time), cpu (%), mem (%), rx, tx (bytes per second). |
Errors for this endpoint
| Status | When |
|---|---|
400 | limit is not a number. |
Request log
The server's own record of recent requests. Needs logs:read.
Recent requests
GET /rest/v1/logs
Needs: logs:read
The server's in-memory log of the last 1000 requests (any endpoint, including failed logins). Secrets are redacted before they are stored and the log is never written to disk. Fetching the log does not add entries to it.
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
since | integer | 0 | Return only entries with an id greater than this (poll with the latest value you got last time). |
limit | integer | 200 | Maximum entries, 1-500 (the newest ones). |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://mon.example.com/rest/v1/logs?limit=3"Response 200 OK
{
"latest": 13,
"entries": [
{
"id": 11,
"ts": 1794044462431,
"ip": "127.0.0.1",
"method": "GET",
"path": "/rest/v1/processes",
"auth": "token:d310ffff",
"status": 200,
"ms": 0.4,
"bytes": 274,
"ua": "Python-urllib/3.14"
},
{
"id": 12,
"ts": 1794044462432,
"ip": "127.0.0.1",
"method": "GET",
"path": "/rest/v1/metrics",
"auth": "token:d310ffff",
"status": 200,
"ms": 0.4,
"bytes": 1107,
"ua": "Python-urllib/3.14"
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
latest | integer | Id of the newest entry in the log. |
entries | array | Objects: id, ts (milliseconds), ip, method, path, auth (ok, fail, token:<id>, locked, limited, none), status, ms, bytes, ua. |
Errors for this endpoint
| Status | When |
|---|---|
400 | since or limit is not a number. |
One request in detail
GET /rest/v1/logs/{id}
Needs: logs:read
The full record: request and response headers (credentials shown only as [redacted, N chars]) and a short response preview (never for cron endpoints).
Path parameters
| Name | Description |
|---|---|
id | Entry id from the list. |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/logs/11Response 200 OK
{
"ts": 1794044462431,
"ip": "127.0.0.1",
"peer": "127.0.0.1",
"method": "GET",
"path": "/rest/v1/processes",
"query": "",
"proto": "HTTP/1.1",
"auth": "token:d310ffff",
"status": 200,
"ms": 0.4,
"bytes": 274,
"ua": "Python-urllib/3.14",
"req_headers": [
[
"Accept-Encoding",
"identity"
],
[
"Host",
"127.0.0.1:18899"
]
],
"resp_headers": [
[
"Server",
"ZabMonitor"
],
[
"Date",
"Sat, 07 Nov 2026 09:41:02 GMT"
]
],
"type": "application/json",
"preview": "{\"time\":1794044462,\"count\":143,\"top_cpu\":[{\"pid\":811,\"name\":\"mysqld\",\"cpu\":12.4,\"mem\":671088640},{\"pid\":1203,\"name\":\"nginx\",\"cpu\":3.1,\"mem\":41943040}],\"top_mem\":[{\"pid\":811,\"name\":\"mysqld\",\"cpu\":12.4,\"mem\":671088640},{\"pid\":2210,\"name\":\"python3\",\"cpu\":1.0,\"mem\":220200960}]}",
"id": 11
}Response fields
| Field | Type | Meaning |
|---|---|---|
id, ts, ip, peer, method, path, query, proto, auth, status, ms, bytes, ua | As in the list, plus peer (the connection's address) and query (secret-looking values redacted). | |
req_headers, resp_headers | array | Lists of [name, value] pairs. |
type | string | Response content type. |
preview | string | First part of the response body (empty for cron paths). |
Errors for this endpoint
| Status | When |
|---|---|
404 | The entry is unknown or already rolled out of the 1000-entry buffer. |
Cron jobs
Create, change, run and inspect scheduled scripts. Needs the Cron Jobs manager to be enabled on the server (otherwise every endpoint here answers 404). Reading needs cron:read; anything that changes or runs something needs cron:write, which means running commands on the server as the users the administrator allowed.
The job object
Returned by the job endpoints. Fields you can send are described under "JSON body" of Create a job.
| Field | Type | Meaning |
|---|---|---|
id | integer | Job id. |
name, schedule, tz, script, script_path, run_as, timeout_s | As sent. schedule has macros expanded. Exactly one of script / script_path is non-empty. | |
enabled | integer | 1 scheduled, 0 paused. |
next_run | integer|null | Next planned run, Unix seconds; null when paused. |
created_at, updated_at | integer | Unix seconds. |
last_run | object|null | Newest run: id, status, started_at, finished_at, exit_code, trig. |
running | boolean | A run is in progress right now. |
today | string | Today's date (YYYY-MM-DD) in the job's own time zone. |
days | array | The last 14 days in the job's zone: day, success, failed, missed, skipped (only in single-job and list responses). |
The run object
| Field | Type | Meaning |
|---|---|---|
id, job_id | integer | Run id and its job. |
job_name | string | Only in the single-run response. |
trig | string | schedule (started by the schedule) or manual (the run endpoint or the dashboard). |
scheduled_for, started_at, finished_at | integer|null | Unix seconds. |
exit_code | integer|null | The script's exit status; null when it never ran or was killed. |
run_as | string | The user it ran as. |
output | string | Combined stdout and stderr, only the last 64 KB. Only in the single-run response. |
truncated | integer | 1 when the output was cut to 64 KB. |
status | string | success (exit 0); failed (non-zero exit); timeout (stopped after timeout_s); killed (the service stopped while it ran); missed (the server was down at the scheduled time; it is never run late); skipped (the previous run of the job was still going); running. |
Cron manager information
GET /rest/v1/cron/info
Needs: cron:read (cron:write also works)
What the server allows. Read this before creating jobs. All cron endpoints answer 404 with the cron manager is not enabled on this server when the administrator did not enable it.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/infoResponse 200 OK
{
"users": [
"zabcron",
"demo"
],
"default_timeout": 600,
"max_timeout": 86400,
"now": 1794044462,
"timezone": "UTC",
"tz_name": "UTC",
"utc_offset": 0,
"retention_days": 90,
"named_zones": true,
"allow_inline": true,
"script_dirs": [],
"jobs_dir": "/run/zabmonitor-cron/jobs",
"data_dir": "/var/lib/zabmonitor"
}Response fields
| Field | Type | Meaning |
|---|---|---|
users | array | System users jobs may run as (the allow-list). A job with any other run_as is refused. |
default_timeout, max_timeout | integer | Job timeout default and ceiling, seconds. |
now | integer | Server time, Unix seconds. |
timezone, tz_name, utc_offset | The server's local time zone (abbreviation, IANA name when known, offset in seconds). | |
named_zones | boolean | Whether IANA zone names such as Asia/Tokyo work in tz (otherwise use fixed offsets). |
allow_inline | boolean | Whether script (typed script text) is accepted. When false only script_path works. |
script_dirs | array | If not empty, script_path must be inside one of these folders. |
retention_days | integer | How long run history is kept (also at most 500 runs per job). |
jobs_dir, data_dir | string | Server folders used by the runner (informational). |
Preview a schedule
POST /rest/v1/cron/preview
Needs: cron:read (cron:write also works)
Calculates the next run times of a schedule without saving anything. Useful for checking a cron expression and a time zone.
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
schedule | string | yes | Cron expression or macro, as for jobs. |
tz | string | no | Time zone, as for jobs. |
count | integer | no | How many times to return, 1-10 (default 5). |
Example request
curl -s \
-X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
https://mon.example.com/rest/v1/cron/preview \
-d '{"schedule": "0 2 * * *", "tz": "UTC+09:00", "count": 3}'Response 200 OK
{
"schedule": "0 2 * * *",
"tz": "UTC+09:00",
"next": [
1794081600,
1794168000
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
schedule | string | The normalised schedule (macros expanded). |
tz | string | The zone you sent. |
next | array | The next run times, Unix seconds. |
Errors for this endpoint
| Status | When |
|---|---|
400 | Invalid schedule or time zone (the message says what is wrong). |
List jobs
GET /rest/v1/cron/jobs
Needs: cron:read (cron:write also works)
All jobs, sorted by name, each with its last run and a 14-day summary. Treat the response as sensitive: it contains the script text of typed jobs.
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/jobsResponse 200 OK
[
{
"id": 2,
"name": "Clean old logs",
"schedule": "*/15 * * * *",
"script": "find /var/log -name '*.gz' -mtime +30 -delete\necho cleaned",
"run_as": "zabcron",
"timeout_s": 600,
"enabled": 1,
"next_run": 1794044700,
"tz": "",
"script_path": "",
"created_at": 1794044461,
"updated_at": 1794044461,
"last_run": {
"id": 28,
"status": "success",
"started_at": 1793958061,
"finished_at": 1793958138,
"exit_code": 0,
"trig": "schedule"
},
"running": false,
"today": "2026-11-07",
"days": [
{
"day": "2026-10-24",
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
},
{
"day": "2026-10-25",
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
}
]
},
{
"id": 1,
"name": "Daily database backup",
"schedule": "0 0 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 600,
"enabled": 1,
"next_run": 1794074400,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044461,
"updated_at": 1794044461,
"last_run": {
"id": 14,
"status": "success",
"started_at": 1793958061,
"finished_at": 1793958069,
"exit_code": 0,
"trig": "schedule"
},
"running": false,
"today": "2026-11-07",
"days": [
{
"day": "2026-10-24",
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
},
{
"day": "2026-10-25",
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
}
]
}
]Response fields
| Field | Type | Meaning |
|---|---|---|
(array) | array | Job objects, described under The job object. |
Create a job
POST /rest/v1/cron/jobs
Needs: cron:write
Creates a job. It starts running on its schedule right away (unless enabled is false). This lets the caller run commands on the server as the allowed users.
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes (create) | 1-80 characters, no control characters. |
schedule | string | yes (create) | Five cron fields minute hour day-of-month month day-of-week (lists 1,15, ranges 1-5, steps */10, month/day names) or one of @hourly @daily @midnight @weekly @monthly @yearly @annually. When both day fields are restricted, either may match (classic cron rule). |
tz | string | no | Zone the schedule is read in: empty = server local time, UTC, a fixed offset UTC+09:00, or an IANA name such as Asia/Tokyo (needs Python 3.9+ and tzdata on the server; see named_zones in cron/info). |
script | string | one of script / script_path | The bash script text (max 100 KB). Refused with 400 when the administrator switched typed scripts off at install time (allow_inline is false in cron/info). |
script_path | string | one of script / script_path | Absolute path of a script file that already exists on the server. It must be a regular file owned by root or the run-as user (root jobs: root only), with no symbolic links, and neither the file nor any parent folder writable by group or others. Checked at save time and before every run. If given, script is ignored. |
run_as | string | no | System user the job runs as. Must be on the server's allow-list (users in cron/info); default: the first allowed user. Anything else is refused with 400, always. |
timeout_s | integer | no | Seconds before the job is stopped, 1 to max_timeout (cron/info). Default: default_timeout. |
enabled | boolean | no | Create: false creates the job paused. Update: switches it. Prefer the enable/disable endpoints to change it later. |
Example request
curl -s \
-X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
https://mon.example.com/rest/v1/cron/jobs \
-d '{"name": "Nightly database backup", "schedule": "0 2 * * *", "tz": "UTC+09:00", "run_as": "zabcron", "timeout_s": 1800, "script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n"}'Response 201 Created
{
"id": 4,
"name": "Nightly database backup",
"schedule": "0 2 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 1800,
"enabled": 1,
"next_run": 1794081600,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044462,
"updated_at": 1794044462,
"last_run": null,
"running": false,
"today": "2026-11-07"
}Response fields
| Field | Type | Meaning |
|---|---|---|
(job) | object | The new job, described under The job object. |
Errors for this endpoint
| Status | When |
|---|---|
400 | Invalid input: bad schedule/zone, run_as not allowed, empty script, typed scripts switched off, unsafe script_path, bad timeout. |
413 | Body over 256 KB. |
415 | Content-Type is not application/json. |
Get one job
GET /rest/v1/cron/jobs/{id}
Needs: cron:read (cron:write also works)
One job object.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/jobs/4Response 200 OK
{
"id": 4,
"name": "Nightly database backup",
"schedule": "0 2 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 1800,
"enabled": 1,
"next_run": 1794081600,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044462,
"updated_at": 1794044462,
"last_run": null,
"running": false,
"today": "2026-11-07",
"days": []
}Response fields
| Field | Type | Meaning |
|---|---|---|
(job) | object | See The job object. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such job. |
Update a job
PUT /rest/v1/cron/jobs/{id}
Needs: cron:write
Changes only the fields you send (a partial update); everything else stays. The next run time is recalculated.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
JSON body
| Field | Type | Required | Description |
|---|---|---|---|
name | string | yes (create) | 1-80 characters, no control characters. |
schedule | string | yes (create) | Five cron fields minute hour day-of-month month day-of-week (lists 1,15, ranges 1-5, steps */10, month/day names) or one of @hourly @daily @midnight @weekly @monthly @yearly @annually. When both day fields are restricted, either may match (classic cron rule). |
tz | string | no | Zone the schedule is read in: empty = server local time, UTC, a fixed offset UTC+09:00, or an IANA name such as Asia/Tokyo (needs Python 3.9+ and tzdata on the server; see named_zones in cron/info). |
script | string | one of script / script_path | The bash script text (max 100 KB). Refused with 400 when the administrator switched typed scripts off at install time (allow_inline is false in cron/info). |
script_path | string | one of script / script_path | Absolute path of a script file that already exists on the server. It must be a regular file owned by root or the run-as user (root jobs: root only), with no symbolic links, and neither the file nor any parent folder writable by group or others. Checked at save time and before every run. If given, script is ignored. |
run_as | string | no | System user the job runs as. Must be on the server's allow-list (users in cron/info); default: the first allowed user. Anything else is refused with 400, always. |
timeout_s | integer | no | Seconds before the job is stopped, 1 to max_timeout (cron/info). Default: default_timeout. |
enabled | boolean | no | Create: false creates the job paused. Update: switches it. Prefer the enable/disable endpoints to change it later. |
Example request
curl -s \
-X PUT \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
https://mon.example.com/rest/v1/cron/jobs/4 \
-d '{"schedule": "30 1 * * *", "timeout_s": 3600}'Response 200 OK
{
"id": 4,
"name": "Nightly database backup",
"schedule": "30 1 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 3600,
"enabled": 1,
"next_run": 1794079800,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044462,
"updated_at": 1794044462,
"last_run": null,
"running": false,
"today": "2026-11-07"
}Response fields
| Field | Type | Meaning |
|---|---|---|
(job) | object | The updated job. |
Errors for this endpoint
| Status | When |
|---|---|
400 | Invalid input, or nothing to update. |
404 | No such job. |
Delete a job
DELETE /rest/v1/cron/jobs/{id}
Needs: cron:write
Deletes the job and its whole run history. A job that is running right now cannot be deleted.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Example request
curl -s \
-X DELETE \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/jobs/4Response 200 OK
{
"deleted": 4
}Response fields
| Field | Type | Meaning |
|---|---|---|
deleted | integer | Id of the deleted job. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such job. |
409 | The job is running; wait for it to finish. |
Run a job now
POST /rest/v1/cron/jobs/{id}/run
Needs: cron:write
Starts the job immediately, in addition to its schedule. The call returns at once; the job runs in the background. Poll cron/runs/{id} with the returned run id until status is no longer running.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Example request
curl -s \
-X POST \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/jobs/4/runResponse 202 Accepted
{
"run_id": 43
}Response fields
| Field | Type | Meaning |
|---|---|---|
run_id | integer | Id of the run that was started. |
Errors for this endpoint
| Status | When |
|---|---|
400 | The job's user is no longer on the allow-list, or its script file is no longer acceptable. |
404 | No such job. |
409 | The job is already running. |
Enable a job
POST /rest/v1/cron/jobs/{id}/enable
Needs: cron:write
Turns the schedule on and recalculates the next run. Send an empty JSON object {} (or no body).
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Example request
curl -s \
-X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
https://mon.example.com/rest/v1/cron/jobs/4/enable \
-d '{}'Response 200 OK
{
"id": 4,
"name": "Nightly database backup",
"schedule": "30 1 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 3600,
"enabled": 1,
"next_run": 1794079800,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044462,
"updated_at": 1794044462,
"last_run": null,
"running": false,
"today": "2026-11-07"
}Response fields
| Field | Type | Meaning |
|---|---|---|
(job) | object | The job with enabled: 1 and a next_run. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such job. |
Disable a job
POST /rest/v1/cron/jobs/{id}/disable
Needs: cron:write
Pauses the schedule (the job and its history are kept; no run starts by itself).
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Example request
curl -s \
-X POST \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/jobs/4/disableResponse 200 OK
{
"id": 4,
"name": "Nightly database backup",
"schedule": "30 1 * * *",
"script": "#!/bin/bash\nset -euo pipefail\necho \"dumping database...\"\nsleep 1\necho \"backup OK: 1.2 GB\"\n",
"run_as": "zabcron",
"timeout_s": 3600,
"enabled": 0,
"next_run": null,
"tz": "UTC+09:00",
"script_path": "",
"created_at": 1794044462,
"updated_at": 1794044462,
"last_run": null,
"running": false,
"today": "2026-11-07"
}Response fields
| Field | Type | Meaning |
|---|---|---|
(job) | object | The job with enabled: 0 and next_run: null. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such job. |
Run history of a job
GET /rest/v1/cron/jobs/{id}/runs
Needs: cron:read (cron:write also works)
Executions of the job, newest first. The list leaves out the output text; get it from cron/runs/{id}.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
status | string | all | all, success, failed (failed, timeout and killed), missed, skipped or running. |
from, to | integer | none | Only runs that started at or after from / at or before to (Unix seconds). |
limit | integer | 30 | Page size (maximum 500). |
offset | integer | 0 | Skip this many runs. |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://mon.example.com/rest/v1/cron/jobs/4/runs?status=success&limit=5"Response 200 OK
{
"total": 1,
"runs": [
{
"id": 43,
"job_id": 4,
"trig": "manual",
"scheduled_for": null,
"started_at": 1794044462,
"finished_at": 1794044463,
"status": "success",
"exit_code": 0,
"run_as": "zabcron",
"truncated": 0
}
]
}Response fields
| Field | Type | Meaning |
|---|---|---|
total | integer | Number of runs matching the filter (before limit/offset). |
runs | array | Run objects without output, described under The run object. |
Errors for this endpoint
| Status | When |
|---|---|
400 | from/to are not Unix timestamps. |
404 | No such job. |
Daily summary of a job
GET /rest/v1/cron/jobs/{id}/summary
Needs: cron:read (cron:write also works)
Counts of runs per day, computed in the job's own time zone.
Path parameters
| Name | Description |
|---|---|
id | Job id. |
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
days | integer | 30 | How many days back. |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://mon.example.com/rest/v1/cron/jobs/4/summary?days=7"Response 200 OK
{
"days": [
{
"day": "2026-11-07",
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
}
],
"totals": {
"runs": 1,
"success": 1,
"failed": 0,
"missed": 0,
"skipped": 0
}
}Response fields
| Field | Type | Meaning |
|---|---|---|
days | array | Objects: day (YYYY-MM-DD in the job's zone), success, failed, missed, skipped. |
totals | object | runs, success, failed, missed, skipped over all kept history. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such job. |
One run, with its output
GET /rest/v1/cron/runs/{id}
Needs: cron:read (cron:write also works)
A single execution including the program output. The output can contain secrets printed by your script: treat it as sensitive.
Path parameters
| Name | Description |
|---|---|
id | Run id (from a list or from run). |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
https://mon.example.com/rest/v1/cron/runs/43Response 200 OK
{
"id": 43,
"job_id": 4,
"job_name": "Nightly database backup",
"trig": "manual",
"scheduled_for": null,
"started_at": 1794044462,
"finished_at": 1794044463,
"status": "success",
"exit_code": 0,
"run_as": "zabcron",
"output": "dumping database...\nbackup OK: 1.2 GB\n",
"truncated": 0
}Response fields
| Field | Type | Meaning |
|---|---|---|
(run) | object | Run object plus output and job_name; see The run object. |
Errors for this endpoint
| Status | When |
|---|---|
404 | No such run (history is pruned after 90 days / 500 runs per job). |
Audit trail
GET /rest/v1/cron/audit
Needs: cron:read (cron:write also works)
Who changed what: every create, update, delete, enable, disable and manual run, newest first. Calls made through this API are recorded with the client address and the token id, e.g. 203.0.113.7 token:9e085d6a.
Query parameters
| Name | Type | Default | Description |
|---|---|---|---|
limit | integer | 100 | Maximum entries. |
Example request
curl -s \
-H "Authorization: Bearer $TOKEN" \
"https://mon.example.com/rest/v1/cron/audit?limit=3"Response 200 OK
[
{
"ts": 1794044462,
"ip": "127.0.0.1 token:d310ffff",
"action": "run_now",
"job_id": 4,
"detail": "Nightly database backup"
},
{
"ts": 1794044462,
"ip": "127.0.0.1 token:d310ffff",
"action": "enable",
"job_id": 4,
"detail": "Nightly database backup"
}
]Response fields
| Field | Type | Meaning |
|---|---|---|
(array) | array | Objects: ts (Unix seconds), ip (who), action, job_id, detail. |
Examples
Python (standard library)
import json, urllib.request
BASE, TOKEN = "https://mon.example.com/rest/v1", "zmt_9e085d6a_..."
def api(method, path, body=None):
req = urllib.request.Request(BASE + path, method=method, headers={"Authorization": "Bearer " + TOKEN})
if body is not None:
req.add_header("Content-Type", "application/json")
req.data = json.dumps(body).encode()
with urllib.request.urlopen(req, timeout=20) as r: # raises HTTPError on 4xx/5xx; the body has {"error": ...}
return json.loads(r.read())
s = api("GET", "/status")
if s["status"] != "ok":
print("ALERT:", s["alerts"])
print("CPU %s%% memory %s%% fullest disk %s%%" % (s["cpu_percent"], s["memory_percent"], s["disk_max_percent"]))Node.js (18+)
const BASE = "https://mon.example.com/rest/v1", TOKEN = "zmt_9e085d6a_...";
async function api(method, path, body) {
const r = await fetch(BASE + path, { method, headers: { Authorization: "Bearer " + TOKEN, ...(body && { "Content-Type": "application/json" }) }, body: body && JSON.stringify(body) });
const data = await r.json();
if (!r.ok) throw new Error(r.status + " " + data.error);
return data;
}
console.log(await api("GET", "/memory"));Shell: create a nightly job, run it now, read the result
AUTH="Authorization: Bearer $TOKEN"; API=https://mon.example.com/rest/v1
# 1. which users may jobs run as?
curl -s -H "$AUTH" $API/cron/info | python3 -c 'import sys,json; print(json.load(sys.stdin)["users"])'
# 2. create the job (daily at 02:00 Tokyo time) and keep its id
ID=$(curl -s -H "$AUTH" -H "Content-Type: application/json" $API/cron/jobs -d '{
"name": "Nightly backup", "schedule": "0 2 * * *", "tz": "Asia/Tokyo", "run_as": "zabcron",
"script": "#!/bin/bash\nset -e\n/usr/local/bin/backup.sh\n"}' | python3 -c 'import sys,json; print(json.load(sys.stdin)["id"])')
# 3. run it now and wait for the result
RUN=$(curl -s -X POST -H "$AUTH" $API/cron/jobs/$ID/run | python3 -c 'import sys,json; print(json.load(sys.stdin)["run_id"])')
until [ "$(curl -s -H "$AUTH" $API/cron/runs/$RUN | python3 -c 'import sys,json; print(json.load(sys.stdin)["status"])')" != running ]; do sleep 2; done
curl -s -H "$AUTH" $API/cron/runs/$RUNUptime-style check with curl
# exit code 0 only when the server reports "ok"
curl -sf -H "Authorization: Bearer $TOKEN" https://mon.example.com/rest/v1/status | grep -q '"status":"ok"' Security notes
- HTTPS only. The installer refuses to enable the API over plain HTTP (unless the agent is local-only) and switches it off again if the certificate could not be issued.
- Treat a token like a password. Keep it in a secret store or environment variable, never in a URL, a repository or a chat message.
- Least privilege. One token per program; only the scopes it needs; an expiry; an address limit when the caller has a fixed IP.
- Revoke at once when in doubt:
sudo ./install.sh rest-token revoke ID. The next request is refused. - cron:write is remote command execution. The server still enforces its own limits: only allowed users, only HTTPS, scripts typed in a request can be forbidden, script files are re-checked before every run, and each change is written to the audit trail with the token id.
- Nothing secret is logged. The request log stores the
Authorizationheader only as[redacted, N chars], and keeps no response text for cron endpoints. - Wrong tokens are throttled and lock the address out; the server compares tokens in constant time.
- The address limit and the lockout rely on the proxy. nginx/apache pass each caller's address to the agent together with a secret only they know, so a program on the same machine cannot fake an address. This protection is installed by
install.shfrom the version that added it;sudo ./install.sh statusshows whether it is active (older installs: re-run the installer). With--webserver nonethere is no proxy, so callers connect directly. - The REST API cannot start or stop services, edit server configuration or create tokens. Monitoring is read-only; the only way to run something is a cron job.
Versioning
The path carries the version (/rest/v1). New fields may be added to responses without a version change, so ignore fields you do not know. A change that removes or renames something would appear under a new version path.
Every example response on this page was captured from the running API (demo data: a simulated server and a real cron scheduler) when this document was generated by dev/make_api_doc.py. Long lists are cut to two items (marked by the generator). Host name mon.example.com and the token are placeholders.
