Add a translation module which takes the information collected by the collectors module and translates it into a JSON format (using the serde_json crate) to pass to the Netbox API.
Rough design:
Add impl blocks to the NetworkInformation and DmiInformation structs, which implement a serialize_to_json function. This function can serialize the struct to a JSON format. This is useful as it allows us for example for the network_collector as we have multiple instances of the NetworkInformation struct which need to be serialized individually to have a correct JSON in the end.
The translator module would then just get called to serialize these structs and build the findal JSON to be handed to Netbox.
Sketch of the impl block:
impl NetworkInformation {
fn serialize_to_json(&self) -> String {
match serde_json::to_string(&self) {
Ok(json) => json,
Err(err) => {
println!(
"Warning: Could not serialize interface '{}'. ({})",
&self.name, err
);
String::new() // Subject to change
}
}
}
}
What does this PR change?
Add a
translation
module which takes the information collected by thecollectors
module and translates it into a JSON format (using theserde_json
crate) to pass to the Netbox API.Rough design:
Add
impl
blocks to theNetworkInformation
andDmiInformation
structs, which implement aserialize_to_json
function. This function can serialize the struct to a JSON format. This is useful as it allows us for example for thenetwork_collector
as we have multiple instances of theNetworkInformation
struct which need to be serialized individually to have a correct JSON in the end.The
translator
module would then just get called to serialize these structs and build the findal JSON to be handed to Netbox.Sketch of the
impl block
:Tick the applicable box:
[x] Add new feature
[ ] Security changes
[ ] Tests
[ ] Documentation changed
[ ] General Maintenance
Links
Fixes: #5
Documentation
Documentation provided with docstrings
[x] DONE