Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Translate collected information into JSON for API #30

Closed
wants to merge 3 commits into from

Conversation

ByteOtter
Copy link
Member

@ByteOtter ByteOtter commented Sep 11, 2023

What does this PR change?

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
            }
        }
    }
}

Tick the applicable box:

  • Add new feature
  • Security changes
  • Tests
  • Documentation changed

  • General Maintenance

Links

Fixes: #5

  • DONE

Documentation

  • Documentation provided with docstrings

  • DONE

@ByteOtter ByteOtter added help wanted Extra attention is needed translation This issue is linked to the information translation labels Sep 11, 2023
@ByteOtter ByteOtter closed this Sep 13, 2023
@ByteOtter ByteOtter deleted the dev/add-translation branch January 9, 2024 10:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies help wanted Extra attention is needed rust translation This issue is linked to the information translation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[TASK:] Translate collected information to NetBox readable format
1 participant