2 use std
::process
::Command
;
4 use crate::config
::datastore
;
5 use crate::tools
::subscription
::read_subscription
;
7 fn files() -> Vec
<&'
static str> {
10 "/etc/network/interfaces",
14 fn commands() -> Vec
<(&'
static str, Vec
<&'
static str>)> {
16 // ("<command>", vec![<arg [, arg]>])
18 ("lsblk", vec
!["--ascii"]),
22 // (<description>, <function to call>)
23 fn function_calls() -> Vec
<(&'
static str, fn() -> String
)> {
25 ("Subscription status", || match read_subscription() {
26 Ok(Some(sub_info
)) => sub_info
.status
.to_string(),
27 _
=> String
::from("No subscription found"),
30 let config
= match datastore
::config() {
31 Ok((config
, _digest
)) => config
,
32 _
=> return String
::from("could not read datastore config"),
35 let mut list
= Vec
::new();
36 for (store
, _
) in &config
.sections
{
37 list
.push(store
.as_str());
44 pub fn generate_report() -> String
{
45 use proxmox
::tools
::fs
::file_read_optional_string
;
47 let file_contents
= files()
50 let content
= match file_read_optional_string(Path
::new(file_name
)) {
51 Ok(Some(content
)) => content
,
52 Err(err
) => err
.to_string(),
53 _
=> String
::from("Could not be read!"),
55 format
!("# {}\n{}", file_name
, content
)
57 .collect
::<Vec
<String
>>()
60 let command_outputs
= commands()
62 .map(|(command
, args
)| {
63 let output
= match Command
::new(command
).args(args
).output() {
64 Ok(output
) => String
::from_utf8_lossy(&output
.stdout
).to_string(),
65 Err(err
) => err
.to_string(),
67 format
!("# {} {}\n{}", command
, args
.join(" "), output
)
69 .collect
::<Vec
<String
>>()
72 let function_outputs
= function_calls()
74 .map(|(desc
, function
)| format
!("# {}\n{}", desc
, function()))
75 .collect
::<Vec
<String
>>()
79 " FILES\n{}\n COMMANDS\n{}\n FUNCTIONS\n{}",
80 file_contents
, command_outputs
, function_outputs