Skip to content

Commit

Permalink
feat: host data export to csv
Browse files Browse the repository at this point in the history
  • Loading branch information
joostfaassen committed Aug 22, 2020
1 parent 2375945 commit 39d74c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Service/HtmlGeneratorService.php
Expand Up @@ -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',
Expand Down
1 change: 1 addition & 0 deletions templates/host.html.twig
Expand Up @@ -2,6 +2,7 @@

{% block body %}
<h1>Host: {{ resource.name }}</h1>

<dl class="dl-horizontal">
<dt>Name</dt>
<dd>{{ resource.name }}</dd>
Expand Down
6 changes: 6 additions & 0 deletions 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 %}

3 changes: 3 additions & 0 deletions templates/hosts.html.twig
Expand Up @@ -4,6 +4,9 @@
<h1>resources
<small>{{ resources|length }}</small>
</h1>

<a href="./hosts.csv" class="btn btn-secondary"><i class="fa fa-cloud-download"></i> Export to csv</a><br />

<table class="data-table">
<thead>
<tr>
Expand Down

0 comments on commit 39d74c4

Please sign in to comment.