-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimplemonitor
82 lines (77 loc) · 2.85 KB
/
simplemonitor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/perl
use lib 'lib';
use SimpleMonitor;
use File::Slurp;
SimpleMonitor->load_config();
if (!caller) {
SimpleMonitor->run_checks();
exit;
}
# From now on, we're a web server
require Plack::Request;
require Template;
my $template = $SimpleMonitor::config{templatefile} ?
read_file($SimpleMonitor::config{templatefile}) :
do { local $/; <DATA>; };
my $css = <<'EOF';
@import url("http://fonts.googleapis.com/css?family=Droid+Sans:regular,bold");
html { background: #ffffea; margin-left: 50px; font-family: "Droid Sans",sans-serif; }
h1,h2 { text-align: center; } .fail { background: #fbb; }
td.res { padding-left: 1em; }
tr.fail td.res { background: url(data:image/gif;base64,R0lGODlhEAAPAKIHAOrc3eggLfKcoPZPX7Sjo6JUVrIOF/n5+SH5BAEAAAcALAAAAAAQAA8AAANLeLrVvfCQIoAFokRlqvieQUAGBZ6FwRjG4L4uqx0sG9zDXau0ff8/FscALAaEBKKxyFPiXkBe4Qdz/Wa0J+wXoUJvm8O0iA1rHpEEADs=) no-repeat;
}
tr.pass td.res { background: url(data:image/gif;base64,R0lGODlhEAAPAKIHAJHXMeD21cXzQaPWhMjotjmrHfn5+fn5+SH5BAEAAAcALAAAAAAQAA8AAANMeLpTNSuuF4wJTapCgv9EIRVAQJwoAYhKAwxwDK/Q4QD4m+POtv85Fgn4E+YEyGRQcUw6cwuAcyoARHBUJE4izVo1B6y2Bj4QDuRIAgA7) no-repeat }
EOF
$css = read_file($SimpleMonitor::config{css})
if -f $SimpleMonitor::config{css};
sub {
my $env = shift;
my $req = Plack::Request->new($env);
my $res = $req->new_response(200);
$res->content_type("text/html");
my $out;
Template->new->process(\$template, { css => $css,
SimpleMonitor->status_for_template }, \$out);
$res->body($out);
$res->finalize;
}
__DATA__
<html>
<head>
<title> SimpleMonitor </title>
<style> [% css %] </style>
</head>
<body>
<h1> SimpleMonitor </h1>
[% IF warnings.size > 0 %]
<div name="warnings">
<h2> Current Warnings </h2>
<table>
[% FOR warn = warnings %]
<tr class="[%warn.result%]">
<td class="res">[%warn.result%]</td>
<td class="system">[% warn.system |html %]</td>
<td class="name">[% warn.name |html %]</td>
<td class="message">[% warn.message |html %]</td>
<td class="checked">[% USE date; date.format(warn.checked) %] </td>
</tr>
[%END%]
</table>
</div>
[%END%]
<div name="status">
<h2> Current Status </h2>
<table>
[% FOR check = latest %]
<tr class="[%check.result%]">
<td class="res">[%check.result%]</td>
<td class="system">[% check.system |html %]</td>
<td class="name">[% check.name |html %]</td>
<td class="message">[% check.message |html %]</td>
<td class="checked">[% USE date; date.format(check.checked) %] </td>
</tr>
[%END%]
</table>
</div>
</body>
</html>