From 39d74c49fa853efb521fb3b8de43a41a92b232c5 Mon Sep 17 00:00:00 2001 From: Joost Faassen Date: Sat, 22 Aug 2020 09:30:18 +0100 Subject: [PATCH] feat: host data export to csv --- src/Service/HtmlGeneratorService.php | 10 ++++++++++ templates/host.html.twig | 1 + templates/hosts.csv.twig | 6 ++++++ templates/hosts.html.twig | 3 +++ 4 files changed, 20 insertions(+) create mode 100644 templates/hosts.csv.twig diff --git a/src/Service/HtmlGeneratorService.php b/src/Service/HtmlGeneratorService.php index 97d57fd..9a5da4f 100644 --- a/src/Service/HtmlGeneratorService.php +++ b/src/Service/HtmlGeneratorService.php @@ -64,6 +64,16 @@ public function generateHosts($resources): void ) ); + file_put_contents( + $this->pathOutput . '/hosts.csv', + $this->twig->render( + 'hosts.csv.twig', + [ + 'resources' => $resources, + ] + ) + ); + foreach ($resources as $resource) { file_put_contents( $this->pathOutput . '/hosts:' . $resource['name'] . '.html', diff --git a/templates/host.html.twig b/templates/host.html.twig index 25d587b..9780be0 100644 --- a/templates/host.html.twig +++ b/templates/host.html.twig @@ -2,6 +2,7 @@ {% block body %}

Host: {{ resource.name }}

+
Name
{{ resource.name }}
diff --git a/templates/hosts.csv.twig b/templates/hosts.csv.twig new file mode 100644 index 0000000..6ec4e8d --- /dev/null +++ b/templates/hosts.csv.twig @@ -0,0 +1,6 @@ +name;os;publicIp;privateIp;status;services;labels; +{% for resource in resources %} +{{ resource.name }};{{ resource.osRelease.name }};{{ resource.publicIp }};{{ resource.privateIp }};{{ resource.status }};{% for service in resource.services %}{{ service.name}} {% endfor %};{% for label in resource.labels %} +{{ label.key}}:{{ label.value}} {% endfor %}; +{% endfor %} + diff --git a/templates/hosts.html.twig b/templates/hosts.html.twig index 998ccf8..a9a1d72 100644 --- a/templates/hosts.html.twig +++ b/templates/hosts.html.twig @@ -4,6 +4,9 @@

resources {{ resources|length }}

+ + Export to csv
+