From 9566a6fbade6910a95c279534985540f8267fe82 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Mon, 16 Jan 2017 21:10:07 +0100 Subject: add updatecmd --- updatecmd | 1 + 1 file changed, 1 insertion(+) create mode 100644 updatecmd diff --git a/updatecmd b/updatecmd new file mode 100644 index 0000000..66ea420 --- /dev/null +++ b/updatecmd @@ -0,0 +1 @@ +curl -F hostname="$(cat /etc/hostname)" -F fullname="$(hostname -f)" -F uptime="$(cat /proc/uptime)" -F load="$(cat /proc/loadavg)" -F uname="$(uname -sr)" -F df="$(df -l)" -F meminfo="$(cat /proc/meminfo)" -F cpus="$(lscpu)" -F debian="$(cat /etc/debian_version)" -- cgit v1.2.3 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 From e96588019160b9ab12712980c95b3bceb599de64 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sat, 28 Jan 2017 08:42:41 +0100 Subject: hurr --- updatecmd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/updatecmd b/updatecmd index 66ea420..900dcda 100644 --- a/updatecmd +++ b/updatecmd @@ -1 +1 @@ -curl -F hostname="$(cat /etc/hostname)" -F fullname="$(hostname -f)" -F uptime="$(cat /proc/uptime)" -F load="$(cat /proc/loadavg)" -F uname="$(uname -sr)" -F df="$(df -l)" -F meminfo="$(cat /proc/meminfo)" -F cpus="$(lscpu)" -F debian="$(cat /etc/debian_version)" +curl -F hostname="$(cat /etc/hostname)" -F fullname="$(hostname -f)" -F uptime="$(cat /proc/uptime)" -F load="$(cat /proc/loadavg)" -F uname="$(uname -sr)" -F df="$(df -l)" -F meminfo="$(cat /proc/meminfo)" -F cpus="$(lscpu)" -F debian="$(cat /etc/debian_version)" -F temps1="$(cat /sys/class/hwmon/hwmon*/temp*_input)" -F temps2="$(cat /sys/class/thermal/thermal_zone*/temp)" -- cgit v1.2.3