summaryrefslogtreecommitdiff
path: root/index.pl
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 /index.pl
wat
Diffstat (limited to 'index.pl')
-rw-r--r--index.pl60
1 files changed, 60 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;