report: add more commands/files to check
add all of our configuration files in /etc/proxmox-backup/ further, call some ZFS tool to get that status. Also, use the subscription command form manager, as we often require more info than the status. Also, adapt formatting a bit. Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
		| @ -2,12 +2,18 @@ use std::path::Path; | |||||||
| use std::process::Command; | use std::process::Command; | ||||||
|  |  | ||||||
| use crate::config::datastore; | use crate::config::datastore; | ||||||
| use crate::tools::subscription::read_subscription; |  | ||||||
|  |  | ||||||
| fn files() -> Vec<&'static str> { | fn files() -> Vec<&'static str> { | ||||||
|     vec![ |     vec![ | ||||||
|  |         "/etc/hostname", | ||||||
|         "/etc/hosts", |         "/etc/hosts", | ||||||
|         "/etc/network/interfaces", |         "/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", | ||||||
|     ] |     ] | ||||||
| } | } | ||||||
|  |  | ||||||
| @ -16,16 +22,15 @@ fn commands() -> Vec<(&'static str, Vec<&'static str>)> { | |||||||
|     //  ("<command>", vec![<arg [, arg]>]) |     //  ("<command>", vec![<arg [, arg]>]) | ||||||
|         ("df", vec!["-h"]), |         ("df", vec!["-h"]), | ||||||
|         ("lsblk", vec!["--ascii"]), |         ("lsblk", vec!["--ascii"]), | ||||||
|  |         ("zpool", vec!["status"]), | ||||||
|  |         ("zfs", vec!["list"]), | ||||||
|  |         ("proxmox-backup-manager", vec!["subscription", "get"]), | ||||||
|     ] |     ] | ||||||
| } | } | ||||||
|  |  | ||||||
|     // (<description>, <function to call>) |     // (<description>, <function to call>) | ||||||
| fn function_calls() -> Vec<(&'static str, fn() -> String)> { | fn function_calls() -> Vec<(&'static str, fn() -> String)> { | ||||||
|     vec![ |     vec![ | ||||||
|         ("Subscription status", || match read_subscription() { |  | ||||||
|             Ok(Some(sub_info)) => sub_info.status.to_string(), |  | ||||||
|             _ => String::from("No subscription found"), |  | ||||||
|         }), |  | ||||||
|         ("Datastores", || { |         ("Datastores", || { | ||||||
|             let config = match datastore::config() { |             let config = match datastore::config() { | ||||||
|                 Ok((config, _digest)) => config, |                 Ok((config, _digest)) => config, | ||||||
| @ -49,10 +54,10 @@ pub fn generate_report() -> String { | |||||||
|         .map(|file_name| { |         .map(|file_name| { | ||||||
|             let content = match file_read_optional_string(Path::new(file_name)) { |             let content = match file_read_optional_string(Path::new(file_name)) { | ||||||
|                 Ok(Some(content)) => content, |                 Ok(Some(content)) => content, | ||||||
|  |                 Ok(None) => String::from("# file does not exists"), | ||||||
|                 Err(err) => err.to_string(), |                 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>>() |         .collect::<Vec<String>>() | ||||||
|         .join("\n\n"); |         .join("\n\n"); | ||||||
| @ -60,11 +65,15 @@ pub fn generate_report() -> String { | |||||||
|     let command_outputs = commands() |     let command_outputs = commands() | ||||||
|         .iter() |         .iter() | ||||||
|         .map(|(command, args)| { |         .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(), |                 Ok(output) => String::from_utf8_lossy(&output.stdout).to_string(), | ||||||
|                 Err(err) => err.to_string(), |                 Err(err) => err.to_string(), | ||||||
|             }; |             }; | ||||||
|             format!("# {} {}\n{}", command, args.join(" "), output) |             format!("# `{} {}`\n{}", command, args.join(" "), output) | ||||||
|         }) |         }) | ||||||
|         .collect::<Vec<String>>() |         .collect::<Vec<String>>() | ||||||
|         .join("\n\n"); |         .join("\n\n"); | ||||||
| @ -76,7 +85,7 @@ pub fn generate_report() -> String { | |||||||
|         .join("\n\n"); |         .join("\n\n"); | ||||||
|  |  | ||||||
|     format!( |     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 |         file_contents, command_outputs, function_outputs | ||||||
|     ) |     ) | ||||||
| } | } | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user