Danke! Ich habe das aufgegriffen:
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
#!/usr/bin/perl
use strict;
use warnings;
use CGI;
use CGI::Carp qw/warningsToBrowser fatalsToBrowser/;
use Proc::ProcessTable;
use Data::Dumper;
use HTML::Template;
my $q = new CGI;
my $template = HTML::Template->new(filename => "status_ps.html");
my $t = new Proc::ProcessTable;
my @needed = qw/Textmate Terminal mysqld launchd securityd/; # add here needed processes
my $report;
my @missing;
my %seen;
foreach my $p ( @{$t->table} ){
my $cmd = $p->cmndline;
$cmd =~ s/(.*)/<span class="success">$1<\/span>/i if grep /$cmd/i, @needed;
push @$report , {
cmdline => $cmd,
pid => $p->pid,
state => $p->state,
};
$seen{$p->cmndline}++;
}
for my $n (@needed) {
push @missing, {
proc => '<span class="error">'.$n.'</span>',
} unless grep /$n/i, keys %seen;
}
$template->param( report => $report , missing => \@missing, );
print $q->header(), $template->output();
und das Template:
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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="de">
<head>
<title>Simple Report</title>
<meta name="author" content="Ronnie Neumann" />
<meta name="keywords" content="status report" />
<style type="text/css" media="screen">
/* <![CDATA[ */
h1 { color: #ff9; }
.default {
font-size: 100%;
color: #fff;
background-color: Ƽ font-family: Arial, Helvectia;
}
.error {
color: #f00;
}
.success {
color: #0f0;
}
/* ]]> */
</style>
</head>
<body class="default">
<h1>Fehlende Prozesse:</h1>
<TMPL_LOOP NAME="missing">
<TMPL_VAR NAME="proc"><br />
</TMPL_LOOP>
<h1>Prozesse:</h1>
<table>
<TMPL_LOOP NAME="report">
<tr>
<td><TMPL_VAR NAME="cmdline"></td>
<td><TMPL_VAR NAME="pid"></td>
<td><TMPL_VAR NAME="state"></td>
</tr>
</TMPL_LOOP>
</table>
</body>
</html>