Skip to content

Commit a456a25

Browse files
authored
Merge pull request #9 from DemOnJR/feature
Feature
2 parents 9d78bf3 + 7c0fb55 commit a456a25

59 files changed

Lines changed: 3795 additions & 859 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Advanced: API payload reference
2+
3+
Endpoint: `POST /api/report.php`
4+
5+
## Headers
6+
- `Content-Type: application/json`
7+
- Optional: `X-Agent-Token: <64-hex>`
8+
9+
## Required fields
10+
- `hostname`
11+
- `metrics`
12+
13+
## Units
14+
- RAM: MB
15+
- Disk: KB
16+
- Network counters: bytes
17+
18+
## Token rules
19+
- Format: 64 hex chars.
20+
- Invalid tokens are ignored.
21+
- Token is accepted from header or `agent.token`.
22+
23+
## CPU value
24+
`metrics.cpu` is agent-defined:
25+
- Windows agent sends a 0..1 fraction.
26+
- Linux agent currently sends load average (string).
27+
28+
## JSON Schema (simplified)
29+
```json
30+
{
31+
"$schema": "https://json-schema.org/draft/2020-12/schema",
32+
"type": "object",
33+
"required": ["hostname", "metrics"],
34+
"properties": {
35+
"hostname": { "type": "string" },
36+
"agent": {
37+
"type": "object",
38+
"properties": {
39+
"token": { "type": "string", "pattern": "^[a-fA-F0-9]{64}$" }
40+
},
41+
"additionalProperties": true
42+
},
43+
"machine": {
44+
"type": "object",
45+
"properties": {
46+
"cpu_arch": { "type": "string" },
47+
"cpu_model": { "type": "string" },
48+
"cpu_vendor": { "type": "string" },
49+
"cpu_cores": { "type": "integer" },
50+
"cpu_max_mhz": { "type": ["number", "string"] },
51+
"cpu_min_mhz": { "type": ["number", "string"] },
52+
"virtualization": { "type": "string" },
53+
"fs_root": { "type": "string" },
54+
"machine_id": { "type": "string" },
55+
"boot_id": { "type": "string" },
56+
"dmi_uuid": { "type": "string" },
57+
"dmi_serial": { "type": "string" },
58+
"board_serial": { "type": "string" },
59+
"macs": { "type": "string" },
60+
"disks": { "type": "string" },
61+
"disks_json": { "type": ["array", "string"] }
62+
},
63+
"additionalProperties": true
64+
},
65+
"metrics": {
66+
"type": "object",
67+
"required": ["cpu", "ram_used", "ram_total", "disk_used", "disk_total"],
68+
"properties": {
69+
"os": { "type": "string" },
70+
"kernel": { "type": "string" },
71+
"cpu": { "type": ["number", "string"] },
72+
"cpu_load_5": { "type": ["number", "string"] },
73+
"cpu_load_15": { "type": ["number", "string"] },
74+
"public_ip": { "type": "string" },
75+
"ram_used": { "type": "integer" },
76+
"ram_total": { "type": "integer" },
77+
"swap_used": { "type": "integer" },
78+
"swap_total": { "type": "integer" },
79+
"disk_used": { "type": "integer" },
80+
"disk_total": { "type": "integer" },
81+
"rx_bytes": { "type": "integer" },
82+
"tx_bytes": { "type": "integer" },
83+
"processes": { "type": "integer" },
84+
"zombies": { "type": "integer" },
85+
"failed_services": { "type": "integer" },
86+
"open_ports": { "type": "integer" },
87+
"uptime": { "type": "string" },
88+
"filesystems_json": { "type": ["array", "string"] }
89+
},
90+
"additionalProperties": true
91+
},
92+
"service_issues": {
93+
"type": "array",
94+
"items": {
95+
"type": "object",
96+
"required": ["service", "new_unique_logs"],
97+
"properties": {
98+
"service": { "type": "string" },
99+
"new_unique_logs": { "type": "string" },
100+
"priority": { "type": "string" },
101+
"active_state": { "type": "string" },
102+
"sub_state": { "type": "string" },
103+
"exec_status": { "type": "string" },
104+
"restarts": { "type": ["string", "integer"] }
105+
},
106+
"additionalProperties": true
107+
}
108+
}
109+
},
110+
"additionalProperties": true
111+
}
112+
```
113+
114+
## Minimal payload example
115+
```json
116+
{
117+
"hostname": "srv-1",
118+
"metrics": {
119+
"cpu": 0.12,
120+
"ram_used": 512,
121+
"ram_total": 2048,
122+
"disk_used": 1048576,
123+
"disk_total": 8388608,
124+
"rx_bytes": 12000,
125+
"tx_bytes": 9000
126+
}
127+
}
128+
```
129+
130+
## Full payload example (Linux-style)
131+
```json
132+
{
133+
"hostname": "srv-1",
134+
"agent": { "token": "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" },
135+
"machine": {
136+
"cpu_model": "Intel(R) Xeon(R)",
137+
"cpu_vendor": "GenuineIntel",
138+
"cpu_cores": 4,
139+
"cpu_arch": "x86_64",
140+
"cpu_max_mhz": "3600.0000",
141+
"cpu_min_mhz": "800.0000",
142+
"virtualization": "kvm",
143+
"fs_root": "ext4",
144+
"machine_id": "abcdef",
145+
"boot_id": "123456",
146+
"dmi_uuid": "uuid-here",
147+
"dmi_serial": "serial-here",
148+
"board_serial": "board-serial",
149+
"macs": "00:11:22:33:44:55",
150+
"disks": "sda:disk:ssd:Samsung",
151+
"disks_json": [
152+
{ "name": "sda", "size": "100G", "media": "ssd", "model": "Samsung" }
153+
]
154+
},
155+
"metrics": {
156+
"os": "Ubuntu 22.04",
157+
"kernel": "5.15.0",
158+
"cpu": "0.35",
159+
"cpu_load_5": "0.20",
160+
"cpu_load_15": "0.10",
161+
"ram_used": 1024,
162+
"ram_total": 4096,
163+
"swap_used": 0,
164+
"swap_total": 0,
165+
"disk_used": 2097152,
166+
"disk_total": 8388608,
167+
"rx_bytes": 1234567,
168+
"tx_bytes": 7654321,
169+
"processes": 132,
170+
"zombies": 0,
171+
"failed_services": 0,
172+
"open_ports": 12,
173+
"uptime": "up 2 days, 3 hours",
174+
"public_ip": "203.0.113.10",
175+
"filesystems_json": [
176+
{ "filesystem": "/dev/sda1", "fstype": "ext4", "total_kb": 8388608, "used_kb": 2097152, "used_percent": 25, "mount": "/" }
177+
]
178+
},
179+
"service_issues": [
180+
{
181+
"service": "nginx",
182+
"new_unique_logs": "failed to start\\nport already in use",
183+
"priority": "high",
184+
"active_state": "failed",
185+
"sub_state": "dead",
186+
"exec_status": "1",
187+
"restarts": "3"
188+
}
189+
]
190+
}
191+
```
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Advanced: App file map
2+
3+
This page lists every file under `php/App` with a short role and key methods.
4+
5+
## Bootstrap
6+
### `php/App/Bootstrap.php`
7+
- Role: load config, autoload classes, open DB, start session, set headers.
8+
- Key: `appBaseUrl()` returns scheme/host (proxy-aware).
9+
10+
## Auth
11+
### `php/App/Auth/Auth.php`
12+
- Role: session auth, login, logout, brute-force block.
13+
- Key methods: `check()`, `login()`, `logout()`, `isBlocked()`.
14+
15+
### `php/App/Auth/Guard.php`
16+
- Role: protect routes, redirect to login when not authenticated.
17+
- Key method: `protect()`.
18+
19+
## Database
20+
### `php/App/Database/PDO.php`
21+
- Role: PDO wrapper with secure defaults (exceptions, assoc fetch, no emulation).
22+
23+
## Install
24+
### `php/App/Install/AgentInstall.php`
25+
- Role: build install URL + command for Linux/Windows.
26+
- Key methods: `fromServer()`, `isWindows()`, `makeInstallUrl()`, `makeCmd()`.
27+
28+
## Metrics
29+
### `php/App/Metrics/MetricsRepository.php`
30+
- Role: insert and read metric snapshots.
31+
- Key methods: `insert()`, `today()`, `latest()`, `todayStartTimestamp()`.
32+
33+
### `php/App/Metrics/MetricsService.php`
34+
- Role: chart series + uptime grid on top of repository.
35+
- Key methods: `cpuRamSeries()`, `networkSeries()`, `uptimeGrid()`.
36+
37+
## Preview
38+
### `php/App/Preview/PublicPreviewRepository.php`
39+
- Role: load public preview config by slug + server resources.
40+
- Key methods: `findPageBySlug()`, `getResourcesByServerId()`.
41+
42+
## Server
43+
### `php/App/Server/ServerRepository.php`
44+
- Role: server read models + identity upsert.
45+
- Key methods: `fetchAllWithLastMetric()`, `findById()`, `upsert()`,
46+
`getPublicPage()`, `getIpHistory()`, `listForSelect()`.
47+
48+
### `php/App/Server/ServerService.php`
49+
- Role: validate and update display name.
50+
- Key method: `rename()`.
51+
52+
### `php/App/Server/ServerActions.php`
53+
- Role: AJAX action router for server operations.
54+
55+
### `php/App/Server/PublicPageRepository.php`
56+
- Role: public page settings + slug helpers + bulk map.
57+
- Key methods: `getSettingsOrDefaults()`, `publicUrlFromSlug()`,
58+
`slugBaseForInput()`, `mapByServerIds()`.
59+
60+
### `php/App/Server/ServerViewHelpers.php`
61+
- Role: UI helpers for OS badges and percentage colors.
62+
- Key methods: `osBadge()`, `pctVal()`, `ringColor()`.
63+
64+
## Services
65+
### `php/App/Services/ServicesOverviewService.php`
66+
- Role: aggregated issue counts per server.
67+
- Key method: `listServersWithServiceIssueCounts()`.
68+
69+
### `php/App/Services/ServiceIssuesService.php`
70+
- Role: server info + issue list for a single server.
71+
- Key methods: `getServer()`, `listIssuesByServerId()`.
72+
73+
## Utils
74+
### `php/App/Utils/Mask.php`
75+
- Role: mask IP and hostname for public display.
76+
- Key methods: `ip()`, `hostname()`.
77+
78+
### `php/App/Utils/Formatter.php`
79+
- Role: format bytes, disk, duration, network throughput.
80+
- Key methods: `bytes()`, `bytesMB()`, `diskKB()`, `networkRxPerMinute()`,
81+
`networkTxPerMinute()`.
82+
83+
### `php/App/Utils/ChartSeries.php`
84+
- Role: normalize and downsample Chart.js series.
85+
- Key methods: `percent()`, `network()`, `downsample()`, `j()`.
86+
87+
## Alert
88+
### `php/App/Alert/AlertRepository.php`
89+
- Role: read helpers for alert headers.
90+
- Key methods: `listAlerts()`, `findById()`, `exists()`.
91+
92+
### `php/App/Alert/AlertRuleRepository.php`
93+
- Role: load rules with targets and channel config.
94+
- Key method: `listByAlertIdWithTargetsAndChannel()`.
95+
96+
### `php/App/Alert/AlertSettingsRepository.php`
97+
- Role: global alert enabled flag.
98+
- Key method: `isAlertsEnabled()`.
99+
100+
### `php/App/Alert/AlertEvaluator.php`
101+
- Role: evaluate rules against incoming metrics.
102+
- Key method: `evaluate()`.
103+
104+
### `php/App/Alert/AlertDispatcher.php`
105+
- Role: build Discord payload and send to channels.
106+
- Key method: `dispatch()`.
107+
108+
### `php/App/Alert/AlertChannelRepository.php`
109+
- Role: read enabled channels linked to a rule.
110+
- Key methods: `getChannelsForRule()`, `getById()`.
111+
112+
### `php/App/Alert/AlertStateRepository.php`
113+
- Role: cooldown state and last send time.
114+
- Key methods: `canSend()`, `markSent()`.
115+
116+
### `php/App/Alert/Channel/ChannelInterface.php`
117+
- Role: interface contract for channel delivery.
118+
119+
### `php/App/Alert/Channel/DiscordChannel.php`
120+
- Role: send Discord webhook payloads.
121+
- Key method: `send()`.
122+
123+
### `php/App/Alert/Channel/DiscordException.php`
124+
- Role: Discord webhook exception wrapper.

0 commit comments

Comments
 (0)