feat: implementation for opnsense os-node_exporter
Some checks failed
Run Check Script / check (pull_request) Failing after 41s
Some checks failed
Run Check Script / check (pull_request) Failing after 41s
This commit is contained in:
@@ -5,7 +5,8 @@ use crate::{
|
||||
error::Error,
|
||||
modules::{
|
||||
caddy::CaddyConfig, dhcp_legacy::DhcpConfigLegacyISC, dns::UnboundDnsConfig,
|
||||
dnsmasq::DhcpConfigDnsMasq, load_balancer::LoadBalancerConfig, tftp::TftpConfig,
|
||||
dnsmasq::DhcpConfigDnsMasq, load_balancer::LoadBalancerConfig,
|
||||
node_exporter::NodeExporterConfig, tftp::TftpConfig,
|
||||
},
|
||||
};
|
||||
use log::{debug, info, trace, warn};
|
||||
@@ -71,6 +72,10 @@ impl Config {
|
||||
LoadBalancerConfig::new(&mut self.opnsense, self.shell.clone())
|
||||
}
|
||||
|
||||
pub fn node_exporter(&mut self) -> NodeExporterConfig<'_> {
|
||||
NodeExporterConfig::new(&mut self.opnsense, self.shell.clone())
|
||||
}
|
||||
|
||||
pub async fn upload_files(&self, source: &str, destination: &str) -> Result<String, Error> {
|
||||
self.shell.upload_folder(source, destination).await
|
||||
}
|
||||
|
||||
@@ -4,4 +4,5 @@ pub mod dhcp_legacy;
|
||||
pub mod dns;
|
||||
pub mod dnsmasq;
|
||||
pub mod load_balancer;
|
||||
pub mod node_exporter;
|
||||
pub mod tftp;
|
||||
|
||||
55
opnsense-config/src/modules/node_exporter.rs
Normal file
55
opnsense-config/src/modules/node_exporter.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use opnsense_config_xml::{NodeExporter, OPNsense};
|
||||
|
||||
use crate::{config::OPNsenseShell, Error};
|
||||
|
||||
pub struct NodeExporterConfig<'a> {
|
||||
opnsense: &'a mut OPNsense,
|
||||
opnsense_shell: Arc<dyn OPNsenseShell>,
|
||||
}
|
||||
|
||||
impl<'a> NodeExporterConfig<'a> {
|
||||
pub fn new(opnsense: &'a mut OPNsense, opnsense_shell: Arc<dyn OPNsenseShell>) -> Self {
|
||||
Self {
|
||||
opnsense,
|
||||
opnsense_shell,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_full_config(&self) -> &Option<NodeExporter> {
|
||||
&self.opnsense.opnsense.node_exporter
|
||||
}
|
||||
fn with_node_exporter<F, R>(&mut self, f: F) -> R
|
||||
where
|
||||
F: FnOnce(&mut NodeExporter) -> R,
|
||||
{
|
||||
match &mut self.opnsense.opnsense.node_exporter.as_mut() {
|
||||
Some(node_exporter) => f(node_exporter),
|
||||
None => unimplemented!(
|
||||
"
|
||||
node exporter is not yet installed"
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn enable(&mut self, enabled: bool) {
|
||||
self.with_node_exporter(|node_exporter| node_exporter.enabled = enabled as u8)
|
||||
}
|
||||
|
||||
pub async fn reload_restart(&self) -> Result<(), Error> {
|
||||
self.opnsense_shell
|
||||
.exec("configctl node_exporter stop")
|
||||
.await?;
|
||||
self.opnsense_shell
|
||||
.exec("configctl template reload OPNsense/NodeExporter")
|
||||
.await?;
|
||||
self.opnsense_shell
|
||||
.exec("configctl node_exporter configtest")
|
||||
.await?;
|
||||
self.opnsense_shell
|
||||
.exec("configctl node_exporter start")
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user