]> git.proxmox.com Git - proxmox-backup.git/blobdiff - src/server/report.rs
update to proxmox-sys 0.2 crate
[proxmox-backup.git] / src / server / report.rs
index a1df1b680699e648106dba2a8d8ad4663575194d..1e7d60708243066697b39711302f8a5fc8faf948 100644 (file)
@@ -1,39 +1,45 @@
 use std::path::Path;
 use std::process::Command;
 
-use crate::config::datastore;
-use crate::tools::subscription::read_subscription;
-
 fn files() -> Vec<&'static str> {
     vec![
+        "/etc/hostname",
         "/etc/hosts",
         "/etc/network/interfaces",
+        "/etc/proxmox-backup/datastore.cfg",
+        "/etc/proxmox-backup/user.cfg",
+        "/etc/proxmox-backup/acl.cfg",
+        "/etc/proxmox-backup/remote.cfg",
+        "/etc/proxmox-backup/sync.cfg",
+        "/etc/proxmox-backup/verification.cfg",
     ]
 }
 
 fn commands() -> Vec<(&'static str, Vec<&'static str>)> {
     vec![
     //  ("<command>", vec![<arg [, arg]>])
+        ("proxmox-backup-manager", vec!["versions", "--verbose"]),
         ("df", vec!["-h"]),
         ("lsblk", vec!["--ascii"]),
+        ("zpool", vec!["status"]),
+        ("zfs", vec!["list"]),
+        ("proxmox-backup-manager", vec!["subscription", "get"]),
     ]
 }
 
-    // (<description>, <function to call>)
-fn function_calls() -> Vec<(&'static str, fn() -> String)> {
+// (description, function())
+type FunctionMapping = (&'static str, fn() -> String);
+
+fn function_calls() -> Vec<FunctionMapping> {
     vec![
-        ("Subscription status", || match read_subscription() {
-            Ok(Some(sub_info)) => sub_info.status.to_string(),
-            _ => String::from("No subscription found"),
-        }),
         ("Datastores", || {
-            let config = match datastore::config() {
+            let config = match pbs_config::datastore::config() {
                 Ok((config, _digest)) => config,
                 _ => return String::from("could not read datastore config"),
             };
 
             let mut list = Vec::new();
-            for (store, _) in &config.sections {
+            for store in config.sections.keys() {
                 list.push(store.as_str());
             }
             list.join(", ")
@@ -42,17 +48,17 @@ fn function_calls() -> Vec<(&'static str, fn() -> String)> {
 }
 
 pub fn generate_report() -> String {
-    use proxmox::tools::fs::file_read_optional_string;
+    use proxmox_sys::fs::file_read_optional_string;
 
     let file_contents = files()
         .iter()
         .map(|file_name| {
             let content = match file_read_optional_string(Path::new(file_name)) {
                 Ok(Some(content)) => content,
+                Ok(None) => String::from("# file does not exist"),
                 Err(err) => err.to_string(),
-                _ => String::from("Could not be read!"),
             };
-            format!("# {}\n{}", file_name, content)
+            format!("$ cat '{}'\n{}", file_name, content)
         })
         .collect::<Vec<String>>()
         .join("\n\n");
@@ -60,23 +66,27 @@ pub fn generate_report() -> String {
     let command_outputs = commands()
         .iter()
         .map(|(command, args)| {
-            let output = match Command::new(command).args(args).output() {
+            let output = Command::new(command)
+                .env("PROXMOX_OUTPUT_NO_BORDER", "1")
+                .args(args)
+                .output();
+            let output = match output {
                 Ok(output) => String::from_utf8_lossy(&output.stdout).to_string(),
                 Err(err) => err.to_string(),
             };
-            format!("# {} {}\n{}", command, args.join(" "), output)
+            format!("$ `{} {}`\n{}", command, args.join(" "), output)
         })
         .collect::<Vec<String>>()
         .join("\n\n");
 
     let function_outputs = function_calls()
         .iter()
-        .map(|(desc, function)| format!("# {}\n{}", desc, function()))
+        .map(|(desc, function)| format!("$ {}\n{}", desc, function()))
         .collect::<Vec<String>>()
         .join("\n\n");
 
     format!(
-        " FILES\n{}\n COMMANDS\n{}\n FUNCTIONS\n{}",
+        "= FILES =\n\n{}\n= COMMANDS =\n\n{}\n= FUNCTIONS =\n\n{}\n",
         file_contents, command_outputs, function_outputs
     )
 }