Failure to run a command on a remote system is now properly detected.
---- Changes since 1.390 ----
Added T-COM, Skytel, Vodaphone and several more as a carriers for SMS.
+---- Changes since 1.400 ----
+Email, SMS and SNMP messages sent by Webmin can be customized, with multiple message templates defined and a different one selected for each monitor.
columns=Columns for services table,1,2-2,1-1
output=Capture output from programs run when down?,1,1-Yes,0-No
subject_mode=Email subject mode,1,0-New style,1-Old style
+def_tmpl=Default template,10,-None,Named template
pinger=Send pings with command,10,-Use builtin code,linux-Use command suitable for Linux or FreeBSD,Other command
snmp_server=Send SNMP traps to server,3,None
snmp_version=SNMP protocol version,1,3-v3,2-v2,1-v1
@d = split(/\0/, $in{'d'});
@d || &error($text{'dtmpls_enone'});
+# Check for users
+@servs = &list_services();
+foreach $d (@d) {
+ @users = grep { $_->{'tmpl'} eq $d } @servs;
+ if (@users) {
+ $tmpl = &get_template($d);
+ &error(&text('dtmpls_eusers', "<i>$tmpl->{'desc'}</i>",
+ join(", ", map { "<i>$_->{'desc'}</i>" } @users)));
+ }
+ }
+
# Waste them
foreach $d (@d) {
$tmpl = &get_template($d);
# Show template to use
@tmpls = &list_templates();
if (@tmpls) {
+ if ($in{'type'}) {
+ ($deftmpl) = grep { $_->{'desc'} eq $config{'def_tmpl'}} @tmpls;
+ if ($deftmpl) {
+ $tid = $deftmpl->{'id'};
+ }
+ }
+ else {
+ $tid = $serv->{'tmpl'};
+ }
print &ui_table_row($text{'mon_tmpl'},
- &ui_select("tmpl", $serv->{'tmpl'},
+ &ui_select("tmpl", $tid,
[ [ "", "<$text{'mon_notmpl'}>" ],
map { [ $_->{'id'}, $_->{'desc'} ] } @tmpls ]));
}
&ui_textbox("desc", $tmpl->{'desc'}, 60));
# Email message
-print &ui_table_row($text{'tmpl_msg'},
- &ui_textarea("msg", $tmpl->{'msg'}, 5, 60));
+print &ui_table_row($text{'tmpl_email'},
+ &ui_textarea("email", $tmpl->{'email'}, 5, 60));
-# SMS message
+# SMS / pager message
print &ui_table_row($text{'tmpl_sms'},
&ui_radio("sms_def", $tmpl->{'sms'} ? 0 : 1,
[ [ 1, $text{'tmpl_sms1'} ], [ 0, $text{'tmpl_sms0'} ] ]).
"<br>\n".
&ui_textarea("sms", $tmpl->{'sms'}, 3, 60));
-# Pager message
-print &ui_table_row($text{'tmpl_pager'},
- &ui_opt_textbox("pager", $tmpl->{'pager'}, 50, $text{'tmpl_sms1'}));
+# SNMP message
+print &ui_table_row($text{'tmpl_snmp'},
+ &ui_opt_textbox("snmp", $tmpl->{'snmp'}, 50, $text{'tmpl_sms1'}));
# Save buttons
print &ui_table_end();
tmpls_ecannot=You are not allowed to edit email templates
tmpls_none=No email templates have been defined yet. All alerts will be sent using the Webmin default messages.
tmpls_desc=Description
-tmpls_msg=Email message
+tmpls_email=Email message
tmpls_add=Add a new email template.
tmpls_return=templates list
tmpls_delete=Delete Selected Templates
tmpl_title2=Edit Email Template
tmpl_header=Alert email template messages
tmpl_desc=Template description
-tmpl_msg=Email message
-tmpl_sms=SMS message
+tmpl_email=Email message
+tmpl_sms=SMS / pager message
tmpl_sms1=Webmin default
tmpl_sms0=Custom message below ..
-tmpl_pager=Pager message
+tmpl_snmp=Pager message
tmpl_instr=Instructions and substitutions
tmpl_subs=The email, SMS and pager messages defined on this page can use the following substitutions :
tmpl_subs_desc=Service description
tmpl_err=Failed to save email template
tmpl_edesc=Missing template description
tmpl_emsg=Missing email message
-tmpl_epager=Missing SMS message
-tmpl_epager=Missing pager message
+tmpl_esms=Missing SMS message
+tmpl_esnmp=Missing SNMP message
+tmpl_err2=Failed to delete email template
+tmpl_eusers=It is in use by the following monitors : $1
+
+dtmpls_err=Failed to delete templates
+dtmpls_enone=None selected
+dtmpls_eusers=$1 is in use by the following monitors : $2
print &ui_form_start("delete_tmpls.cgi", "post");
print &ui_links_row(\@links);
@tds = ( "width=5" );
- print &ui_columns_start([ "", $text{'tmpls_desc'}, $text{'tmpls_msg'} ],
- 100, 0, \@tds);
+ print &ui_columns_start(
+ [ "", $text{'tmpls_desc'}, $text{'tmpls_email'} ], 100, 0, \@tds);
foreach $tmpl (@tmpls) {
- $msg = $tmpl->{'msg'};
+ $msg = $tmpl->{'email'};
$msg = substr($msg, 0, 80)." ..." if (length($msg) > 80);
print &ui_checked_columns_row(
[ "<a href='edit_tmpl.cgi?id=$tmpl->{'id'}'>".
@services = sort { &sort_func($a, $b) } @services;
# Check for services that are down
-$now = localtime(time());
+$nowunix = time();
+$now = &make_date($nowunix);
+($nowdate, $nowtime) = split(/\s+/, $now);
$thishost = &get_system_hostname();
$ecount = 0;
foreach $serv (@services) {
$subj = &text('monitor_sub_'.$suffix,
$serv->{'desc'}, $host);
if ($notify{'pager'}) {
- $pager_msg .= &text('monitor_pager_'.$suffix,
- $host, $serv->{'desc'}, $now);
+ $pager_msg .= &make_message($suffix, $host,
+ $serv, 'pager');
}
if ($notify{'sms'}) {
- $sms_msg .= &text('monitor_pager_'.$suffix,
- $host, $serv->{'desc'}, $now);
+ $sms_msg .= &make_message($suffix, $host,
+ $serv, 'sms');
}
if ($notify{'snmp'}) {
- push(@snmp_msg, &text('monitor_snmp_'.$suffix,
- $host, $serv->{'desc'}));
+ push(@snmp_msg, &make_message($suffix, $host,
+ $serv, 'snmp'));
}
if ($notify{'email'}) {
- $thisemail .= &text('monitor_email_'.$suffix,
- $host, $serv->{'desc'}, $now)."\n";
+ $thisemail .= &make_message($suffix, $host,
+ $serv, 'email');
if ($out) {
$thisemail .= $out;
}
return $t;
}
+# make_message(status, host, &server, type)
+# Returns the message for some email, SMS or SNMP. May use a template, or
+# the built-in default.
+sub make_message
+{
+local ($suffix, $host, $serv, $type) = @_;
+local $tmpl = $serv->{'tmpl'} ? &get_template($serv->{'tmpl'}) : undef;
+if ($tmpl && $tmpl->{$type}) {
+ # Construct from template
+ local %hash = ( 'DESC' => $serv->{'desc'},
+ 'HOST' => $host,
+ 'DATE' => $nowdate,
+ 'TIME' => $nowtime,
+ 'STATUS' => $text{'mon_'.$suffix},
+ uc($suffix) => 1,
+ );
+ foreach my $k (keys %$serv) {
+ $hash{'SERVICE_'.uc($k)} = $serv->{$k};
+ }
+ local $rv = &substitute_template($tmpl->{$type}, \%hash);
+ $rv =~ s/[\r\n]+$//;
+ $rv .= "\n";
+ return $rv;
+ }
+else {
+ # Use built-in
+ if ($type eq 'sms') {
+ return &text('monitor_pager_'.$suffix,
+ $host, $serv->{'desc'}, $now);
+ }
+ elsif ($type eq 'snmp') {
+ return &text('monitor_snmp_'.$suffix,
+ $host, $serv->{'desc'});
+ }
+ elsif ($type eq 'email') {
+ return &text('monitor_email_'.$suffix,
+ $host, $serv->{'desc'}, $now)."\n";
+ }
+ }
+}
+
if ($in{'delete'}) {
# Remove this template
+ &error_setup($text{'tmpl_err2'});
+ @users = grep { $_->{'tmpl'} eq $tmpl->{'id'} } &list_services();
+ @users && &error(&text('tmpl_eusers',
+ join(", ", map { "<i>$_->{'desc'}</i>" } @users)));
&delete_template($tmpl);
&webmin_log("delete", "template", $tmpl->{'desc'});
}
# Validate and store inputs
$in{'desc'} =~ /\S/ || &error($text{'tmpl_edesc'});
$tmpl->{'desc'} = $in{'desc'};
- $in{'msg'} =~ /\S/ || &error($text{'tmpl_emsg'});
- $tmpl->{'msg'} = $in{'msg'};
+ $in{'email'} =~ /\S/ || &error($text{'tmpl_eemail'});
+ $tmpl->{'email'} = $in{'email'};
if ($in{'sms_def'}) {
delete($tmpl->{'sms'});
}
$in{'sms'} =~ /\S/ || &error($text{'tmpl_esms'});
$tmpl->{'sms'} = $in{'sms'};
}
- if ($in{'pager_def'}) {
- delete($tmpl->{'pager'});
+ if ($in{'snmp_def'}) {
+ delete($tmpl->{'snmp'});
}
else {
- $in{'pager'} =~ /\S/ || &error($text{'tmpl_epager'});
- $tmpl->{'pager'} = $in{'pager'};
+ $in{'snmp'} =~ /\S/ || &error($text{'tmpl_esnmp'});
+ $tmpl->{'snmp'} = $in{'snmp'};
}
# Save or create
{
local ($id) = @_;
local %tmpl;
-&read_file("$templates_dir/$id", \%tmpl);
+&read_file("$templates_dir/$id", \%tmpl) || return undef;
$tmpl{'id'} = $id;
$tmpl{'file'} = "$templates_dir/$id";
-$tmpl{'msg'} =~ s/\\n/\n/g;
-$tmpl{'msg'} =~ s/\\\\/\\/g;
+$tmpl{'email'} =~ s/\\n/\n/g;
+$tmpl{'email'} =~ s/\\\\/\\/g;
return \%tmpl;
}
$tmpl->{'id'} ||= time().$$;
$tmpl->{'file'} = "$templates_dir/$tmpl->{'id'}";
local %write = %$tmpl;
-$write{'msg'} =~ s/\\/\\\\/g;
-$write{'msg'} =~ s/\n/\\n/g;
+$write{'email'} =~ s/\\/\\\\/g;
+$write{'email'} =~ s/\n/\\n/g;
if (!-d $templates_dir) {
&make_dir($templates_dir, 0755);
}