Skip to content

Commit bd3de50

Browse files
Ahmet OeztuerkAhmet Oeztuerk
authored andcommitted
trying to pass CI tests
- add files of this PR to manifest, - modify csv API test functions to beware of quotation marks - save template file in "UTF-8 BOM" encoding - read and print the data according to data type in csv renderer
1 parent 5360253 commit bd3de50

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

MANIFEST

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ lib/Thruk/Utils/SelfCheck.pm
166166
lib/Thruk/Utils/Status.pm
167167
lib/Thruk/Utils/Timezone.pm
168168
lib/Thruk/Utils/Trends.pm
169+
lib/Thruk/Views/CsvRenderer.pm
169170
lib/Thruk/Views/ExcelRenderer.pm
170171
lib/Thruk/Views/GDRenderer.pm
171172
lib/Thruk/Views/JSONRenderer.pm
@@ -3178,6 +3179,7 @@ templates/_backends_select_multi.tt
31783179
templates/_blocks.tt
31793180
templates/_cmd_form.tt
31803181
templates/_cmd_parts.tt
3182+
templates/_csv_export.tt
31813183
templates/_comments_table.tt
31823184
templates/_common_css.tt
31833185
templates/_common_css_fonts.tt
@@ -3380,6 +3382,8 @@ templates/config_timeperiods.tt
33803382
templates/custom_perf_bar_adjustments.tt
33813383
templates/docs.tt
33823384
templates/error.tt
3385+
templates/csv/_status_hostdetail.tt
3386+
templates/csv/status_hostdetail.tt
33833387
templates/excel/_status_detail_worksheet.tt
33843388
templates/excel/_status_hostdetail_worksheet.tt
33853389
templates/excel/availability.tt

lib/Thruk/Views/CsvRenderer.pm

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,25 @@ sub render_csv {
3636
my $t1 = [gettimeofday];
3737
require Thruk::Views::ToolkitRenderer;
3838
my $output = '';
39-
Thruk::Views::ToolkitRenderer::render($c, $c->stash->{'template'}, undef, \$output);
39+
40+
if (defined $data && ref($data) eq 'ARRAY') {
41+
foreach my $row (@{$data}) {
42+
if (ref($row) eq 'ARRAY') {
43+
$output .= join(',', map { "\"$_\"" } (@{$row}) ) . "\n";
44+
} else {
45+
$output .= "\"$row\"\n";
46+
}
47+
}
48+
} elsif (defined $data && ref($data) eq 'HASH') {
49+
# Handle hash data
50+
my @keys = sort keys (%{$data});
51+
$output .= join(',', map { "\"$_\"" } @keys) . "\n";
52+
$output .= join(',', map { "\"$data->{$_}\"" } @keys) . "\n";
53+
} else {
54+
# Fallback for scalar data
55+
$output = defined $data ? "$data\n" : "";
56+
}
57+
4058
$c->{'rendered'} = 1;
4159
$c->res->content_type('text/csv');
4260
$c->res->body($output);

t/scenarios/rest_api/t/local/rest_functions.t

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ TestUtils::test_command({
4949
{
5050
TestUtils::test_command({
5151
cmd => '/usr/bin/env thruk r "/csv/hosts?columns=concat(name, \"_\", state, \"::\") as test"',
52-
like => [qr/^#test$/smx, qr/^localhost_\d::$/smx],
52+
like => [qr/^#test$/smx, qr/^"localhost_\d::"$/smx],
5353
});
5454
};
5555

@@ -71,7 +71,7 @@ TestUtils::test_command({
7171
});
7272
TestUtils::test_command({
7373
cmd => '/usr/bin/env thruk r "/csv/hosts?columns=fmt(\"%s:%.3f\", name, state) as test"',
74-
like => [qr/^#test$/smx, qr/^localhost:\d\.000$/smx],
74+
like => [qr/^#test$/smx, qr/^"localhost:\d\.000"$/smx],
7575
});
7676
};
7777

@@ -137,7 +137,7 @@ TestUtils::test_command({
137137
{
138138
TestUtils::test_command({
139139
cmd => '/usr/bin/env thruk r "/csv/hosts?columns=utc(last_check) as test"',
140-
like => [qr/^#test$/smx, qr/^\d+\-\d+\-\d+\s+\d+:\d+:\d+\s+UTC$/smx],
140+
like => [qr/^#test$/smx, qr/^\"\d+\-\d+\-\d+\s+\d+:\d+:\d+\s+UTC\"$/smx],
141141
});
142142
};
143143

@@ -146,7 +146,7 @@ TestUtils::test_command({
146146
{
147147
TestUtils::test_command({
148148
cmd => '/usr/bin/env thruk r "/csv/hosts?columns=date(last_check) as test"',
149-
like => [qr/^#test$/smx, qr/^\d+\-\d+\-\d+\s+\d+:\d+:\d+/smx],
149+
like => [qr/^#test$/smx, qr/^\"\d+\-\d+\-\d+\s+\d+:\d+:\d+/smx],
150150
});
151151
};
152152

templates/csv/_status_hostdetail.tt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[% USE date %]
1+
[% USE date %]
22
[% FOREACH col = columns %]
33
[% IF col == "Site" %]Site,
44
[% ELSIF col == "Hostname" %]Hostname,

0 commit comments

Comments
 (0)