detect/
diagnostics.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2020 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Fetches diagnostic data.

use anyhow::Error;
use fuchsia_triage::{DiagnosticData, Source};
use inspect_fetcher::InspectFetcher;

// The capability name for the Inspect reader
const INSPECT_SERVICE_PATH: &str = "/svc/fuchsia.diagnostics.ArchiveAccessor.feedback";

// Durable connection to Archivist
#[derive(Debug)]
pub struct DiagnosticFetcher {
    inspect: InspectFetcher,
}

#[derive(Debug)]
pub struct Selectors {
    pub(crate) inspect_selectors: Vec<String>,
}

impl DiagnosticFetcher {
    pub fn create(selectors: Selectors) -> Result<DiagnosticFetcher, Error> {
        Ok(DiagnosticFetcher {
            inspect: InspectFetcher::create(INSPECT_SERVICE_PATH, selectors.inspect_selectors)?,
        })
    }

    pub async fn get_diagnostics(&mut self) -> Result<Vec<DiagnosticData>, Error> {
        let inspect_data = DiagnosticData::new(
            "inspect.json".to_string(),
            Source::Inspect,
            self.inspect.fetch().await?,
        )?;
        Ok(vec![inspect_data])
    }
}

impl Selectors {
    pub fn new() -> Selectors {
        Selectors { inspect_selectors: Vec::new() }
    }

    pub fn with_inspect_selectors(mut self, selectors: Vec<String>) -> Self {
        self.inspect_selectors.extend(selectors);
        self
    }
}