| 1 | use netdata_plugin_schema::NetdataSchema; |
| 2 | use schemars::JsonSchema; |
| 3 | use serde::{Deserialize, Serialize}; |
| 4 | |
| 5 | #[derive(Clone, Debug, JsonSchema, Serialize, Deserialize)] |
| 6 | #[schemars( |
| 7 | title = "Web Server Configuration", |
| 8 | description = "Configuration for a simple web server", |
| 9 | extend("x-ui-flavour" = "tabs"), |
| 10 | extend("x-ui-options" = { |
| 11 | "tabs": [ |
| 12 | { |
| 13 | "title": "Server Settings", |
| 14 | "fields": ["host", "port", "workers"] |
| 15 | }, |
| 16 | { |
| 17 | "title": "Security", |
| 18 | "fields": ["enable_tls", "tls_cert_path", "api_key"] |
| 19 | } |
| 20 | ] |
| 21 | }), |
| 22 | extend("x-config-id" = "demo_plugin:my_config"), |
| 23 | extend("x-config-path" = "/collectors"), |
| 24 | extend("x-config-type" = "single"), |
| 25 | extend("x-config-status" = "running"), |
| 26 | extend("x-config-source-type" = "stock"), |
| 27 | extend("x-config-source" = "Plugin-generated configuration"), |
| 28 | extend("x-config-cmds" = "schema|get|update"), |
| 29 | extend("x-config-view-access" = 0), |
| 30 | extend("x-config-edit-access" = 0), |
| 31 | )] |
| 32 | struct WebServerConfig { |
| 33 | #[schemars( |
| 34 | title = "Host Address", |
| 35 | description = "The IP address to bind the server to", |
| 36 | example = "0.0.0.0", |
| 37 | extend("x-ui-help" = "Use 0.0.0.0 to bind to all interfaces"), |
| 38 | extend("x-ui-placeholder" = "127.0.0.1") |
| 39 | )] |
| 40 | host: String, |
| 41 | |
| 42 | #[schemars( |
| 43 | title = "Port", |
| 44 | description = "TCP port number", |
| 45 | range(min = 1, max = 65535), |
| 46 | example = 8080, |
| 47 | extend("x-ui-help" = "Choose an available port number"), |
| 48 | extend("x-ui-placeholder" = "8080") |
| 49 | )] |
| 50 | port: u16, |
| 51 | } |
| 52 | |
| 53 | fn main() { |
| 54 | let schema = WebServerConfig::netdata_schema(); |
| 55 | println!("{}", serde_json::to_string_pretty(&schema).unwrap()); |
| 56 | } |