1 |
95b003ff
|
Origo
|
#!/usr/bin/perl
|
2 |
|
|
# edit_service.cgi
|
3 |
|
|
# Display a new or existing service inside a watch
|
4 |
|
|
|
5 |
|
|
require './mon-lib.pl';
|
6 |
|
|
&ReadParse();
|
7 |
|
|
$conf = &get_mon_config();
|
8 |
|
|
$watch = $conf->[$in{'idx'}];
|
9 |
|
|
|
10 |
|
|
if ($in{'new'}) {
|
11 |
|
|
&ui_print_header(undef, $text{'service_title'}, "");
|
12 |
|
|
}
|
13 |
|
|
else {
|
14 |
|
|
&ui_print_header(undef, $text{'service_title2'}, "");
|
15 |
|
|
$service = $watch->{'members'}->[$in{'sidx'}];
|
16 |
|
|
}
|
17 |
|
|
|
18 |
|
|
print "<form action=save_service.cgi method=post>\n";
|
19 |
|
|
print "<input type=hidden name=idx value='$in{'idx'}'>\n";
|
20 |
|
|
print "<input type=hidden name=sidx value='$in{'sidx'}'>\n";
|
21 |
|
|
print "<input type=hidden name=new value='$in{'new'}'>\n";
|
22 |
|
|
|
23 |
|
|
print "<table border width=100%>\n";
|
24 |
|
|
print "<tr $tb> <td><b>$text{'service_header'}</b></td> </tr>\n";
|
25 |
|
|
print "<tr $cb> <td><table width=100%>\n";
|
26 |
|
|
|
27 |
|
|
print "<tr> <td><b>$text{'service_name'}</b></td>\n";
|
28 |
|
|
printf "<td><input name=name size=20 value='%s'></td>\n",
|
29 |
|
|
$service->{'values'}->[0];
|
30 |
|
|
|
31 |
|
|
$int = &find_value("interval", $service->{'members'});
|
32 |
|
|
print "<td><b>$text{'service_interval'}</b></td>\n";
|
33 |
|
|
print "<td>",&interval_input("interval", $int),"</td> </tr>\n";
|
34 |
|
|
|
35 |
|
|
$desc = &find("description", $service->{'members'});
|
36 |
|
|
print "<tr> <td><b>$text{'service_desc'}</b></td>\n";
|
37 |
|
|
printf "<td colspan=3><input name=desc size=50 value='%s'></td> </tr>\n",
|
38 |
|
|
$desc ? $desc->{'value'} : "";
|
39 |
|
|
|
40 |
|
|
@mons = &list_monitors();
|
41 |
|
|
$monitor = &find("monitor", $service->{'members'}) if (!$in{'new'});
|
42 |
|
|
if ($monitor->{'value'} =~ /^(\S+)\s*(.*)$/) {
|
43 |
|
|
$mon = $1; $args = $2;
|
44 |
|
|
}
|
45 |
|
|
$idx = &indexof($mon, @mons);
|
46 |
|
|
|
47 |
|
|
print "<tr> <td><b>$text{'service_monitor'}</b></td> <td colspan=3>\n";
|
48 |
|
|
printf "<input type=radio name=monitor_def value=1 %s> %s\n",
|
49 |
|
|
$in{'new'} || $idx >= 0 ? "checked" : "", $text{'service_mon1'};
|
50 |
|
|
print "<select name=monitor>\n";
|
51 |
|
|
foreach $m (@mons) {
|
52 |
|
|
printf "<option %s>%s\n", $m eq $mon ? "selected" : "", $m;
|
53 |
|
|
}
|
54 |
|
|
print "</select>\n";
|
55 |
|
|
printf "<input type=radio name=monitor_def value=0 %s> %s\n",
|
56 |
|
|
$in{'new'} || $idx >= 0 ? "" : "checked", $text{'service_mon0'};
|
57 |
|
|
printf "<input name=other size=20 value='%s'>\n",
|
58 |
|
|
$idx >= 0 ? "" : $mon;
|
59 |
|
|
print "</td> </tr>\n";
|
60 |
|
|
|
61 |
|
|
print "<tr> <td><b>$text{'service_args'}</b></td> <td colspan=3>\n";
|
62 |
|
|
print "<input name=args size=50 value='$args'></td> </tr>\n";
|
63 |
|
|
|
64 |
|
|
$i = 0;
|
65 |
|
|
@avail = &list_alerts();
|
66 |
|
|
@periods = &find("period", $service->{'members'});
|
67 |
|
|
push(@periods, { }) if ($in{'newperiod'} || $in{'new'});
|
68 |
|
|
@defperiods = &find("period", $conf);
|
69 |
|
|
foreach $p (@periods) {
|
70 |
|
|
print "<tr> <td colspan=4><hr></td> </tr>\n";
|
71 |
|
|
print "<tr> <td colspan=2><b><i>",&text($p->{'name'} ?
|
72 |
|
|
'service_period' : 'service_new', $i+1),"</i></b></td>\n";
|
73 |
|
|
print "<td colspan=2 align=right><input type=checkbox name=delete_$i> ",
|
74 |
|
|
"$text{'service_delperiod'}</td> </tr>\n";
|
75 |
|
|
|
76 |
|
|
print "<input type=hidden name=idx_$i value='$p->{'index'}'>\n";
|
77 |
|
|
local ($dfrom, $dto, $hfrom, $hto, $known, $name);
|
78 |
|
|
if ($p->{'value'} =~ /^\s*wd\s+{(\S+)-(\S+)}\s+hr\s+{(\S+)-(\S+)}\s*$/){
|
79 |
|
|
$dfrom = $1; $dto = $2; $hfrom = $3; $hto = $4;
|
80 |
|
|
$known = 1;
|
81 |
|
|
}
|
82 |
|
|
elsif ($p->{'value'} =~ /^\s*wd\s+{(\S+)-(\S+)}\s*$/) {
|
83 |
|
|
$dfrom = $1; $dto = $2;
|
84 |
|
|
$known = 1;
|
85 |
|
|
}
|
86 |
|
|
elsif ($p->{'value'} =~ /^\s*hr\s+{(\S+)-(\S+)}\s*$/) {
|
87 |
|
|
$hfrom = $1; $hto = $2;
|
88 |
|
|
$known = 1;
|
89 |
|
|
}
|
90 |
|
|
elsif ($p->{'value'} =~ /^\s*(\S+):\s*$/) {
|
91 |
|
|
$name = $1;
|
92 |
|
|
$known = 2;
|
93 |
|
|
}
|
94 |
|
|
elsif (!$p->{'value'}) {
|
95 |
|
|
$hfrom = $hto = "";
|
96 |
|
|
$known = 1;
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
# Specified days and hours
|
100 |
|
|
printf "<tr> <td><input type=radio name=known_$i value=1 %s> %s</td>\n",
|
101 |
|
|
$known == 1 ? "checked" : "", "<b>$text{'service_known1'}</b>";
|
102 |
|
|
|
103 |
|
|
print "<td colspan=3><b>$text{'service_days'}</b>\n";
|
104 |
|
|
printf "<input type=radio name=days_def_$i value=1 %s> %s\n",
|
105 |
|
|
$dfrom ? "" : "checked", $text{'service_all'};
|
106 |
|
|
printf "<input type=radio name=days_def_$i value=0 %s>\n",
|
107 |
|
|
$dfrom ? "checked" : "";
|
108 |
|
|
print &day_input("dfrom_$i", $dfrom)," - ",
|
109 |
|
|
&day_input("dto_$i", $dto);
|
110 |
|
|
|
111 |
|
|
print " \n";
|
112 |
|
|
print "<b>$text{'service_hours'}</b>\n";
|
113 |
|
|
printf "<input type=radio name=hours_def_$i value=1 %s> %s\n",
|
114 |
|
|
$hfrom ? "" : "checked", $text{'service_all'};
|
115 |
|
|
printf "<input type=radio name=hours_def_$i value=0 %s>\n",
|
116 |
|
|
$hfrom ? "checked" : "";
|
117 |
|
|
print "<input name=hfrom_$i size=4 value='$hfrom'> - ",
|
118 |
|
|
"<input name=hto_$i size=4 value='$hto'></td> </tr>\n";
|
119 |
|
|
|
120 |
|
|
# Selected defined period
|
121 |
|
|
if (@defperiods || $known == 2) {
|
122 |
|
|
printf "<tr> <td><input type=radio name=known_$i value=2 %s> %s</td>\n", $known == 2 ? "checked" : "", "<b>$text{'service_known2'}</b>";
|
123 |
|
|
print "<td><select name=name_$i>\n";
|
124 |
|
|
foreach $p (@defperiods) {
|
125 |
|
|
$p->{'value'} =~ /^(\S+):/;
|
126 |
|
|
printf "<option %s>%s\n",
|
127 |
|
|
$name eq $1 ? "selected" : "", $1;
|
128 |
|
|
}
|
129 |
|
|
print "</select></td> </tr>\n";
|
130 |
|
|
}
|
131 |
|
|
|
132 |
|
|
# Any Time::Period string
|
133 |
|
|
printf "<tr> <td><input type=radio name=known_$i value=0 %s> %s</td>\n",
|
134 |
|
|
$known == 0 ? "checked" : "", "<b>$text{'service_known0'}</b>";
|
135 |
|
|
printf "<td colspan=3><input name=pstr_$i size=50 value='%s'></td> </tr>\n", $known == 0 ? $p->{'value'} : "";
|
136 |
|
|
|
137 |
|
|
print "<tr> <td valign=top><b>$text{'service_alerts'}</b></td>\n";
|
138 |
|
|
print "<td colspan=3><table border>\n";
|
139 |
|
|
print "<tr $tb> <td><b>$text{'service_alert'}</b></td> ",
|
140 |
|
|
"<td><b>$text{'service_atype'}</b></td> ",
|
141 |
|
|
"<td><b>$text{'service_aargs'}</b></td> </tr>\n";
|
142 |
|
|
local @alerts = ( &find("alert", $p->{'members'}),
|
143 |
|
|
&find("upalert", $p->{'members'}),
|
144 |
|
|
&find("startupalert", $p->{'members'}) );
|
145 |
|
|
local $j = 0;
|
146 |
|
|
foreach $a (@alerts, { }) {
|
147 |
|
|
print "<tr $cb> <td><select name=alert_${i}_${j}>\n";
|
148 |
|
|
local ($found, $al, $ar);
|
149 |
|
|
if ($a->{'value'} =~ /^(\S+)\s*(.*)/) {
|
150 |
|
|
$al = $1; $ar = $2;
|
151 |
|
|
}
|
152 |
|
|
printf "<option value='' %s> \n",
|
153 |
|
|
$al ? "" : "selected";
|
154 |
|
|
foreach $av (@avail) {
|
155 |
|
|
printf "<option %s>%s\n",
|
156 |
|
|
$al eq $av ? "selected" : "", $av;
|
157 |
|
|
$found++ if ($al eq $av);
|
158 |
|
|
}
|
159 |
|
|
print "<option selected>$al\n" if (!$found && $al);
|
160 |
|
|
print "</select></td>\n";
|
161 |
|
|
print "<td><select name=atype_${i}_${j}>\n";
|
162 |
|
|
foreach $t ('alert', 'upalert', 'startupalert') {
|
163 |
|
|
printf "<option value=%s %s>%s\n",
|
164 |
|
|
$t, $a->{'name'} eq $t ? "selected" : "",
|
165 |
|
|
$text{"service_atype_$t"};
|
166 |
|
|
}
|
167 |
|
|
print "</select></td>\n";
|
168 |
|
|
$ar =~ s/"/"/g;
|
169 |
|
|
print "<td><input name=aargs_${i}_${j} size=30 ",
|
170 |
|
|
"value='$ar'></td> </tr>\n";
|
171 |
|
|
$j++;
|
172 |
|
|
}
|
173 |
|
|
print "</table></td> </tr>\n";
|
174 |
|
|
|
175 |
|
|
local $ev = &find_value("alertevery", $p->{'members'});
|
176 |
|
|
print "<tr> <td><b>$text{'service_every'}</b></td> <td colspan=3>\n";
|
177 |
|
|
printf "<input type=radio name=every_def_$i value=1 %s> %s\n",
|
178 |
|
|
$ev ? "" : "checked", $text{'service_every_def'};
|
179 |
|
|
printf "<input type=radio name=every_def_$i value=0 %s> %s\n",
|
180 |
|
|
$ev ? "checked" : "", $text{'service_every_time'};
|
181 |
|
|
print &interval_input("every_$i", $ev),"</td>\n";
|
182 |
|
|
|
183 |
|
|
local @aa = &find_value("alertafter", $p->{'members'});
|
184 |
|
|
print "<tr> <td><b>$text{'service_after'}</b></td> <td colspan=3>\n";
|
185 |
|
|
printf "<input type=radio name=after_def_$i value=1 %s> %s\n",
|
186 |
|
|
@aa ? "" : "checked", $text{'service_immediate'};
|
187 |
|
|
printf "<input type=radio name=after_def_$i value=0 %s>\n",
|
188 |
|
|
@aa ? "checked" : "";
|
189 |
|
|
print &text('service_after_num',
|
190 |
|
|
"<input name=after_$i size=6 value='$aa[0]'>"),"\n";
|
191 |
|
|
print " " x 3;
|
192 |
|
|
print $text{'service_aftertime'},"\n";
|
193 |
|
|
print &interval_input("after_interval_$i", $aa[1]),"</td> </tr>\n";
|
194 |
|
|
|
195 |
|
|
local $na = &find_value("numalerts", $p->{'members'});
|
196 |
|
|
print "<tr> <td><b>$text{'service_num'}</b></td>\n";
|
197 |
|
|
printf "<td><input type=radio name=num_def_$i value=1 %s> %s\n",
|
198 |
|
|
$na ? "" : "checked", $text{'service_unlimited'};
|
199 |
|
|
printf "<input type=radio name=num_def_$i value=0 %s>\n",
|
200 |
|
|
$na ? "checked" : "";
|
201 |
|
|
print "<input name=num_$i size=6 value='$na'></td> </tr>\n";
|
202 |
|
|
|
203 |
|
|
$i++;
|
204 |
|
|
}
|
205 |
|
|
|
206 |
|
|
if (!$in{'new'}) {
|
207 |
|
|
print "<tr> <td colspan=4><hr></td> </tr>\n";
|
208 |
|
|
print "<tr> <td colspan=4 align=right><a href='edit_service.cgi?",
|
209 |
|
|
"idx=$in{'idx'}&sidx=$in{'sidx'}&newperiod=1'>",
|
210 |
|
|
"$text{'service_newperiod'}</a></td> </tr>\n";
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
print "</table></td></tr></table>\n";
|
214 |
|
|
|
215 |
|
|
print "<table width=100%><tr>\n";
|
216 |
|
|
if ($in{'new'}) {
|
217 |
|
|
print "<td><input type=submit value='$text{'create'}'></td>\n";
|
218 |
|
|
}
|
219 |
|
|
else {
|
220 |
|
|
print "<td><input type=submit value='$text{'save'}'></td>\n";
|
221 |
|
|
print "<td align=right><input type=submit name=delete ",
|
222 |
|
|
"value='$text{'delete'}'></td>\n";
|
223 |
|
|
}
|
224 |
|
|
print "</tr></table></form>\n";
|
225 |
|
|
|
226 |
|
|
&ui_print_footer("list_watches.cgi", $text{'watches_return'});
|
227 |
|
|
|