diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-01-17 20:22:19 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-01-17 20:22:44 +0100 |
commit | 6f43d838dc808288e3b71cf26e86ab70d0e3b1d5 (patch) | |
tree | 5c9f68b6969c5eee920f9bd11b72288408c5393c | |
parent | 9566a6fbade6910a95c279534985540f8267fe82 (diff) |
distinguish between fresh and old host data
-rw-r--r-- | index.pl | 32 | ||||
-rw-r--r-- | templates/main.html.ep | 20 |
2 files changed, 40 insertions, 12 deletions
@@ -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 @@ <div> + <h1> Active </h1> <table> <tr> <th>Hostname</th> <th>Load</th> <th>OS</th> </tr> - % for my $host (@{$hosts}) { + % for my $host (@{$active_hosts}) { <tr> <td><%= $host->{hostname} %></td> <td><%= $host->{load15} %></td> - <td>Debian <%= $host->{debian} %></td> + <td>Debian <%= $host->{debian_version} %></td> + </tr> + % } + </table> + <h1> Old </h1> + <table> + <tr> + <th>Hostname</th> + <th>Load</th> + <th>OS</th> + </tr> + % for my $host (@{$old_hosts}) { + <tr> + <td><%= $host->{hostname} %></td> + <td><%= $host->{load15} %></td> + <td>Debian <%= $host->{debian_version} %></td> </tr> % } </table> |