From 6f43d838dc808288e3b71cf26e86ab70d0e3b1d5 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Tue, 17 Jan 2017 20:22:19 +0100 Subject: distinguish between fresh and old host data --- index.pl | 32 ++++++++++++++++++++++---------- templates/main.html.ep | 20 ++++++++++++++++++-- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/index.pl b/index.pl index e1c0463..b36f6a7 100644 --- a/index.pl +++ b/index.pl @@ -69,23 +69,35 @@ app->attr( dbh => sub { return $dbh } ); get '/' => sub { my ($self) = @_; + my $epoch = DateTime->now( time_zone => 'Europe/Berlin' )->epoch; my @hostdata; + my @olddata; + my @curdata; my $hostdata_raw = $dbh->selectall_arrayref( - qq{select * from hostdata order by last_contact desc} - ); - my @fields = (qw(hostname contact), @int_fields, @text_fields); - - for my $host (@{$hostdata_raw}) { - push(@hostdata, { - map { ($fields[$_], $host->[$_]) } (0 .. $#fields) - }); + qq{select * from hostdata order by last_contact desc}); + my @fields = ( qw(hostname last_contact), @int_fields, @text_fields ); + + for my $host ( @{$hostdata_raw} ) { + my $hostref + = { map { ( $fields[$_], $host->[$_] ) } ( 0 .. $#fields ) }; + push( @hostdata, $hostref ); + if ( $epoch - $hostref->{last_contact} < ( 31 * 60 ) ) { + push( @curdata, $hostref ); + } + else { + push( @olddata, $hostref ); + } } + @curdata = sort { $a->{hostname} cmp $b->{hostname} } @curdata; + $self->render( 'main', - hosts => \@hostdata, - version => $VERSION, + active_hosts => \@curdata, + hosts => \@hostdata, + old_hosts => \@olddata, + version => $VERSION, ); }; diff --git a/templates/main.html.ep b/templates/main.html.ep index f5cae1d..6f786dc 100644 --- a/templates/main.html.ep +++ b/templates/main.html.ep @@ -1,15 +1,31 @@
+

Active

- % for my $host (@{$hosts}) { + % for my $host (@{$active_hosts}) { - + + + % } +
Hostname Load OS
<%= $host->{hostname} %> <%= $host->{load15} %>Debian <%= $host->{debian} %>Debian <%= $host->{debian_version} %>
+

Old

+ + + + + + + % for my $host (@{$old_hosts}) { + + + + % }
HostnameLoadOS
<%= $host->{hostname} %><%= $host->{load15} %>Debian <%= $host->{debian_version} %>
-- cgit v1.2.3