fuchsia_triage/
plugins.rs1use crate::act::{Action, ActionResults, Gauge, Severity};
6use crate::metrics::fetch::FileDataFetcher;
7use crate::metrics::metric_value::MetricValue;
8
9mod crashes;
10mod helpers;
11mod memory;
12mod routing;
13mod sandbox_errors;
14
15pub trait Plugin {
16 fn name(&self) -> &'static str;
20
21 fn display_name(&self) -> &'static str;
25
26 fn run(&self, inputs: &FileDataFetcher<'_>) -> ActionResults {
28 let mut results = ActionResults::new();
29 results.sort_gauges = false;
30 let structured_results = self.run_structured(inputs);
31 for action in structured_results {
32 match action {
33 Action::Alert(alert) => match alert.severity {
34 Severity::Info => results.infos.push(alert.print),
35 Severity::Warning => results.warnings.push(alert.print),
36 Severity::Error => results.errors.push(alert.print),
37 },
38 Action::Gauge(Gauge { tag: Some(tag), value, .. }) => {
39 if let Some(MetricValue::String(raw_value)) = value.cached_value.into_inner() {
40 results.gauges.push(format!("{}: {}", tag, raw_value));
41 }
42 }
43 _ => (),
44 }
45 }
46 results
47 }
48
49 fn run_structured(&self, inputs: &FileDataFetcher<'_>) -> Vec<Action>;
51}
52
53pub fn register_plugins() -> Vec<Box<dyn Plugin>> {
55 vec![
56 Box::new(crashes::CrashesPlugin {}),
57 Box::new(sandbox_errors::SandboxErrorsPlugin {}),
58 Box::new(routing::RoutingErrorsPlugin {}),
59 Box::new(memory::MemoryPlugin {}),
60 ]
61}