补充API信息,增加自定义IP数据库文档 (#85)
This commit is contained in:
@@ -175,6 +175,72 @@ Example response:
|
||||
}
|
||||
```
|
||||
|
||||
### Get ICMP Ping / TCPing monitor value
|
||||
|
||||
This API does not require authentication, except for servers with `HideForGuest` option enabled.
|
||||
|
||||
Request:
|
||||
```
|
||||
GET /api/v1/monitor/{id}
|
||||
```
|
||||
|
||||
Parameters:
|
||||
- `id` (required): ServerID, must be an positive integer.
|
||||
|
||||
Example response:
|
||||
```json
|
||||
{
|
||||
"code": 0,
|
||||
"message": "success",
|
||||
"result": [
|
||||
{
|
||||
"monitor_id": 1,
|
||||
"server_id": 1,
|
||||
"monitor_name": "Monitor1",
|
||||
"server_name": "Server1",
|
||||
"created_at": [
|
||||
1722142860000,
|
||||
1722142920000
|
||||
],
|
||||
"avg_delay": [
|
||||
68.2275,
|
||||
70.1129
|
||||
]
|
||||
},
|
||||
{
|
||||
"monitor_id": 2,
|
||||
"server_id": 1,
|
||||
"monitor_name": "Monitor2",
|
||||
"server_name": "Server1",
|
||||
"created_at": [
|
||||
1722142860000,
|
||||
1722142920000
|
||||
],
|
||||
"avg_delay": [
|
||||
66.656,
|
||||
68.2153
|
||||
]
|
||||
},
|
||||
{
|
||||
"monitor_id": 3,
|
||||
"server_id": 1,
|
||||
"monitor_name": "Monitor3",
|
||||
"server_name": "Server1",
|
||||
"created_at": [
|
||||
1722142860000,
|
||||
1722142920000
|
||||
],
|
||||
"avg_delay": [
|
||||
61.4525,
|
||||
62.342
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
Note: `created_at` corresponds with `avg_delay`.
|
||||
|
||||
## Usage Examples
|
||||
|
||||
### Get All Server Information
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
---
|
||||
outline: deep
|
||||
---
|
||||
# Customize GeoIP database
|
||||
|
||||
Dashboard v0.18.3+ uses an embedded GeoIP database to query IP locations. An IPinfo format mmdb database is required to be placed at `pkg/geoip/geoip.db` to compile the Dashboard with working GeoIP queries.
|
||||
|
||||
An IPinfo format mmdb is constructed by those fields:
|
||||
|
||||
- An IP subnet as an entry
|
||||
- `continent`:Continent code
|
||||
- `continent_name`:Continent name
|
||||
- `country`:Country code
|
||||
- `country_name`:Country name
|
||||
|
||||
Dashboard only requires the `country` field, and other fields can be left empty.
|
||||
|
||||
## Editing database
|
||||
|
||||
It is recommended to use `mmdbwriter` and `maxminddb-golang` libraries for editing mmdb databases as of now.
|
||||
|
||||
If your goal is to correct geographic information, it is recommended to modify directly based on the original IPinfo database. For similar operations, you can refer to the [sing-geoip](https://github.com/SagerNet/sing-geoip) project.
|
||||
|
||||
Using the correction of IPinfo data as an example, you need to use the `ReplaceWith` inserter (which is the default value) and write the `mmdbtype.Map` information:
|
||||
|
||||
```go
|
||||
subnet := &net.IPNet{
|
||||
IP: net.ParseIP("114.5.1.4")
|
||||
Mask: net.CIDRMask(32, 32)
|
||||
}
|
||||
countryMap := make(map[mmdbtype.String]mmdbtype.String)
|
||||
|
||||
countryMap[mmdbtype.String("country")] = mmdbtype.String("JP")
|
||||
|
||||
if err := writer.Insert(subnet, mmdbtype.Map(countryMap)); err != nil {
|
||||
return err
|
||||
}
|
||||
```
|
||||
|
||||
A `writer` is an instance of `*mmdbwriter.Tree` and needs to be created using the `mmdbwriter.New` method. The specific operations and the process of inserting other fields are not mentioned here.
|
||||
|
||||
After writing the database information to a file, you can use the `mmdbinspect` CLI tool to test the database information. For example:
|
||||
|
||||
```shell
|
||||
$ mmdbinspect -db ./country.mmdb 114.5.1.4
|
||||
[
|
||||
{
|
||||
"Database": "./country.mmdb",
|
||||
"Records": [
|
||||
{
|
||||
"Network": "114.5.1.4/32",
|
||||
"Record": {
|
||||
"continent": "AS",
|
||||
"continent_name": "Asia",
|
||||
"country": "JP",
|
||||
"country_name": "Japan"
|
||||
}
|
||||
}
|
||||
],
|
||||
"Lookup": "114.5.1.4"
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
Once the format and information are confirmed to be correct, the database can be used for compiling the Dashboard. Afterwards, you can test if the query API is working correctly using `grpcurl` or similar tools:
|
||||
|
||||
```shell
|
||||
grpcurl -proto ./nezha/proto/nezha.proto -plaintext -H 'client_secret: test' -d '{"ip": "114.5.1.4"}' 127.0.0.1:5555 proto.NezhaService/LookupGeoIP
|
||||
```
|
||||
Reference in New Issue
Block a user