-
Notifications
You must be signed in to change notification settings - Fork 0
/
HTMLRenderer.pm
64 lines (56 loc) · 1.46 KB
/
HTMLRenderer.pm
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
#!/usr/bin/perl
package HTMLRenderer;
use strict;
use warnings;
sub render_header {
return <<'END_HTML';
Content-Type: text/html
<!DOCTYPE html>
<html>
<head>
<title>Proxmox Resources Monitor</title>
<style>
body { font-family: Arial, sans-serif; margin: 20px; }
table { border-collapse: collapse; width: 100%; margin-bottom: 20px; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
.status-running { color: green; }
.status-stopped { color: red; }
h2 { color: #333; }
</style>
</head>
<body>
END_HTML
}
sub render_resource_table {
my ($title, $resources) = @_;
my $html = "<h2>$title</h2>\n";
$html .= <<'END_HTML';
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Status</th>
<th>Memory (MB)</th>
<th>CPU</th>
</tr>
END_HTML
foreach my $resource (@$resources) {
my $status_class = $resource->{status} eq 'running' ? 'status-running' : 'status-stopped';
$html .= sprintf(
"<tr><td>%s</td><td>%s</td><td class='%s'>%s</td><td>%s</td><td>%s</td></tr>\n",
$resource->{id},
$resource->{name},
$status_class,
$resource->{status},
int($resource->{memory} / (1024*1024)),
$resource->{cpu}
);
}
$html .= "</table>\n";
return $html;
}
sub render_footer {
return "</body></html>\n";
}
1;