summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2017-01-12 21:13:44 +0100
committerDaniel Friesel <derf@finalrewind.org>2017-01-12 21:13:44 +0100
commitcf9159cdd0173282b466d702c615fa92f2ecfe15 (patch)
treefd0f593bf71e0cc48733e8f7b0dcf6dc84ae9737
wat
-rw-r--r--index.pl60
-rw-r--r--templates/layouts/default.html.ep19
-rw-r--r--templates/main.html.ep1
3 files changed, 80 insertions, 0 deletions
diff --git a/index.pl b/index.pl
new file mode 100644
index 0000000..072ecf0
--- /dev/null
+++ b/index.pl
@@ -0,0 +1,60 @@
+#!/usr/bin/env perl
+
+use Mojolicious::Lite;
+use Data::Dumper;
+use DBI;
+use 5.020;
+use utf8;
+
+our $VERSION = qx{git describe --dirty} || '0.00';
+
+my $dbh = DBI->connect( "dbi:SQLite:dbname=picomon.sqlite", q{}, q{} );
+
+$dbh->do(qq{
+ create table if not exists hostdata (
+ hostname text not null unique,
+ integer last_contact not null,
+ load1 integer,
+ load5 integer,
+ load15 integer,
+ uptime integer
+ )
+});
+
+app->defaults( layout => 'default' );
+app->attr( dbh => sub { return $dbh } );
+
+get '/' => sub {
+ my ($self) = @_;
+
+ $self->render(
+ 'main',
+ version => $VERSION,
+ );
+};
+
+post '/update' => sub {
+ my ($self) = @_;
+ my $params = $self->req->params->to_hash;
+
+ say Dumper($params);
+
+ say Dumper($self->req->uploads);
+
+ $self->render(
+ data => q{},
+ status => 204,
+ );
+};
+
+app->config(
+ hypnotoad => {
+ listen => [ $ENV{PICOMON_LISTEN} // 'http://*:8099' ],
+ pid_file => '/tmp/picomon.pid',
+ workers => 1,
+ },
+);
+
+$ENV{MOJO_MAX_MESSAGE_SIZE} = 1048576;
+
+app->start;
diff --git a/templates/layouts/default.html.ep b/templates/layouts/default.html.ep
new file mode 100644
index 0000000..8105c9b
--- /dev/null
+++ b/templates/layouts/default.html.ep
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+ <title><%= stash('title') // 'picomon' %></title>
+ <meta charset="utf-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+% if ($self->stash('refresh_interval')) {
+ <meta http-equiv="refresh" content="<%= $self->stash('refresh_interval') %>"/>
+% }
+
+
+ %= stylesheet '/static/default.css'
+</head>
+<body>
+
+%= content
+
+</body>
+</html>
diff --git a/templates/main.html.ep b/templates/main.html.ep
new file mode 100644
index 0000000..025bb31
--- /dev/null
+++ b/templates/main.html.ep
@@ -0,0 +1 @@
+<p>ohai!</p>