Handle hostnames with upper-case letters
[webmin.git] / status / proc-monitor.pl
1 # proc-monitor.pl
2 # Check if some process is running
3
4 sub get_proc_status
5 {
6 local (@found, $count);
7 return { 'up' => -1 } if (!&foreign_check("proc"));
8 &foreign_require("proc", "proc-lib.pl");
9 foreach $p (&foreign_call("proc", "list_processes")) {
10         if (eval { $p->{'args'} =~ /$_[0]->{'cmd'}/i } &&
11             (!$_[0]->{'asuser'} || $_[0]->{'asuser'} eq $p->{'user'})) {
12                 push(@found, $p->{'pid'});
13                 $count++;
14                 }
15         }
16 local $thresh = $_[0]->{'thresh'} || 1;
17 if ($_[0]->{'not'}) {
18         if ($count >= $thresh) {
19                 return { 'up' => 0 };
20                 }
21         else {
22                 return { 'up' => 1 };
23                 }
24         }
25 else {
26         if ($count >= $thresh) {
27                 return { 'up' => 1, 'desc' => &text('proc_pid',
28                                                     join(" ", @found)) };
29                 }
30         else {
31                 return { 'up' => 0 };
32                 }
33         }
34 }
35
36 sub show_proc_dialog
37 {
38 print &ui_table_row($text{'proc_cmd'},
39         &ui_textbox("cmd", $_[0]->{'cmd'}, 30));
40
41 print &ui_table_row($text{'proc_not'},
42         &ui_radio("not", int($_[0]->{'not'}),
43                   [ [ 0, $text{'proc_not0'} ],
44                     [ 1, $text{'proc_not1'} ] ]));
45
46 print &ui_table_row($text{'proc_thresh'},
47         &ui_textbox("thresh", $_[0]->{'thresh'} || 1, 5));
48
49 print &ui_table_row($text{'proc_asuser'},
50         &ui_opt_textbox("asuser", $_[0]->{'asuser'}, 13,
51                         $text{'proc_anyuser'})." ".
52         &user_chooser_button("asuser"));
53 }
54
55 sub parse_proc_dialog
56 {
57 &depends_check($_[0], "proc");
58 $in{'cmd'} || &error($text{'proc_ecmd'});
59 $_[0]->{'cmd'} = $in{'cmd'};
60 $_[0]->{'not'} = $in{'not'};
61 $in{'thresh'} =~ /^\d+$/ || &error($text{'proc_ethresh'});
62 $_[0]->{'thresh'} = $in{'thresh'};
63 if ($in{'asuser_def'}) {
64         delete($_[0]->{'asuser'});
65         }
66 else {
67         defined(getpwnam($in{'asuser'})) || &error($text{'proc_easuser'});
68         $_[0]->{'asuser'} = $in{'asuser'};
69         }
70 }
71
72 1;
73