]> git.proxmox.com Git - proxmox-backup.git/commitdiff
api2/node/syslog.rs: add syslog api schema
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 25 Jan 2019 16:17:30 +0000 (17:17 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 25 Jan 2019 16:17:30 +0000 (17:17 +0100)
src/api2/node.rs
src/api2/node/syslog.rs [new file with mode: 0644]
src/tools/common_regex.rs

index cb51f0568a22f8b119efc8ee024b4b2f18dec5c4..4147a02e63890cba249adc3b3ece3423a3b20f9d 100644 (file)
@@ -5,6 +5,7 @@ use serde_json::{json};
 mod time;
 mod network;
 mod dns;
+mod syslog;
 
 pub fn router() -> Router {
 
@@ -12,11 +13,13 @@ pub fn router() -> Router {
         .get(ApiMethod::new(
             |_,_| Ok(json!([
                 {"subdir": "network"},
-               {"subdir": "time"},
+                {"subdir": "syslog"},
+                {"subdir": "time"},
            ])),
             ObjectSchema::new("Directory index.")))
         .subdir("dns", dns::router())
         .subdir("network", network::router())
+        .subdir("syslog", syslog::router())
         .subdir("time", time::router());
 
     route
diff --git a/src/api2/node/syslog.rs b/src/api2/node/syslog.rs
new file mode 100644 (file)
index 0000000..966c1dd
--- /dev/null
@@ -0,0 +1,64 @@
+use failure::*;
+
+use crate::tools;
+use crate::api::schema::*;
+use crate::api::router::*;
+use serde_json::{json, Value};
+
+use std::sync::Arc;
+use lazy_static::lazy_static;
+use crate::tools::common_regex;
+
+fn get_syslog(param: Value, _info: &ApiMethod) -> Result<Value, Error> {
+
+    let result = json!({});
+
+    Ok(result)
+}
+
+lazy_static! {
+    pub static ref SYSTEMD_DATETIME_FORMAT: Arc<ApiStringFormat> =
+        ApiStringFormat::Pattern(&common_regex::SYSTEMD_DATETIME_REGEX).into();
+}
+
+pub fn router() -> Router {
+
+    let route = Router::new()
+        .get(
+            ApiMethod::new(
+                get_syslog,
+                ObjectSchema::new("Read server time and time zone settings.")
+                    .optional(
+                        "start",
+                        IntegerSchema::new("Start line number.")
+                            .minimum(0)
+                    )
+                    .optional(
+                        "limit",
+                        IntegerSchema::new("Max. number of lines.")
+                            .minimum(0)
+                    )
+                    .optional(
+                        "since",
+                        StringSchema::new("Display all log since this date-time string.")
+                           .format(SYSTEMD_DATETIME_FORMAT.clone())
+                    )
+                    .optional(
+                        "until",
+                        StringSchema::new("Display all log until this date-time string.")
+                           .format(SYSTEMD_DATETIME_FORMAT.clone())
+                    )
+                    .optional(
+                        "service",
+                        StringSchema::new("Service ID.")
+                            .max_length(128)
+                    )
+            ).returns(
+                ObjectSchema::new("Returns a list of syslog entries.")
+                    .required("n", IntegerSchema::new("Line number."))
+                    .required("t", StringSchema::new("Line text."))
+            )
+        );
+
+    route
+}
index 322476be1608c1a3cf13e1c6530d7ca37fbd9c2c..a3fb655cdcb2673d876094b492fbe2b69a6cd265 100644 (file)
@@ -35,5 +35,11 @@ macro_rules! IPRE { () => (concat!(r"(?:", IPV4RE!(), "|", IPV6RE!(), ")")) }
 lazy_static! {
     pub static ref IP_REGEX: Regex = Regex::new(IPRE!()).unwrap();
 
-    pub static ref SHA256_HEX_REGEX: Regex = Regex::new("^[a-f0-9]{64}$").unwrap();
+    pub static ref SHA256_HEX_REGEX: Regex =
+        Regex::new(r"^[a-f0-9]{64}$")
+        .unwrap();
+
+    pub static ref SYSTEMD_DATETIME_REGEX: Regex =
+        Regex::new(r"^\d{4}-\d{2}-\d{2}( \d{2}:\d{2}(:\d{2})?)?$")
+        .unwrap();
 }