peach-workspace/peach-jsonrpc-server/src/main.rs

74 lines
3.3 KiB
Rust

#![warn(missing_docs)]
//! # peach-jsonrpc-server
//!
//! A JSON-RPC server which exposes an over HTTP.
//!
//! Currently includes peach-stats capability (system statistics).
//!
//! ## API
//!
//! | Method | Description | Returns |
//! | --- | --- | --- |
//! | `ping` | Microservice status | `success` if running |
//!
//! ### Network
//!
//! Methods for **retrieving data**:
//!
//! | Method | Description | Returns |
//! | --- | --- | --- |
//! | `available_networks` | `iface` | List SSID, flags (security), frequency and signal level for all networks in range of given interface |
//! | `id` | `iface`, `ssid` | Return ID of given SSID |
//! | `ip` | `iface` | Return IP of given network interface |
//! | `rssi` | `iface` | Return average signal strength (dBm) for given interface |
//! | `rssi_percent` | `iface` | Return average signal strength (%) for given interface |
//! | `saved_networks` | | List all networks saved in wpasupplicant config |
//! | `ssid` | `iface` | Return SSID of currently-connected network for given interface |
//! | `state` | `iface` | Return state of given interface |
//! | `status` | `iface` | Return status parameters for given interface |
//! | `traffic` | `iface` | Return network traffic for given interface |
//!
//! Methods for **modifying state**:
//!
//! | Method | Parameters | Description |
//! | --- | --- | --- |
//! | `add` | `iface`, `ssid`, `pass` | Add WiFi credentials to `wpa_supplicant-<iface>.conf` |
//! | `check_iface` | `wlan_iface`, `ap_iface` | Activate WiFi access point on <ap_iface> if <wlan_iface> is active without a connection |
//! | `connect` | `id`, `iface` | Disable other networks and attempt connection with AP represented by given id |
//! | `delete` | `id`, `iface` | Remove WiFi credentials for given network id and interface |
//! | `disable` | `id`, `iface` | Disable connection with AP represented by given id |
//! | `disconnect` | `iface` | Disconnect given interface |
//! | `modify` | `id`, `iface`, `pass` | Set a new password for given network id and interface |
//! | `reassociate` | `iface` | Reassociate with current AP for given interface |
//! | `reconfigure` | | Force wpa_supplicant to re-read its configuration file |
//! | `reconnect` | `iface` | Disconnect and reconnect given interface |
//! | `save` | | Save configuration changes to `wpa_supplicant-wlan0.conf` |
//! | `start_iface_server` | `iface` | Start the `systemd` service for the given interface |
//!
//! ### System Statistics
//!
//! | Method | Description | Returns |
//! | --- | --- | --- |
//! | `cpu_stats` | CPU statistics | `user`, `system`, `nice`, `idle` |
//! | `cpu_stats_percent` | CPU statistics as percentages | `user`, `system`, `nice`, `idle` |
//! | `disk_usage` | Disk usage statistics (array of disks) | `filesystem`, `one_k_blocks`, `one_k_blocks_used`, `one_k_blocks_free`, `used_percentage`, `mountpoint` |
//! | `load_average` | Load average statistics | `one`, `five`, `fifteen` |
//! | `mem_stats` | Memory statistics | `total`, `free`, `used` |
//! | `uptime` | System uptime | `secs` |
use std::process;
use log::error;
fn main() {
// initalize the logger
env_logger::init();
// handle errors returned from `run`
if let Err(e) = peach_jsonrpc_server::run() {
error!("Application error: {}", e);
process::exit(1);
}
}