#!/usr/local/bin/perl # edit_mon.cgi # Display a form for editing or creating a monitor require './status-lib.pl'; $access{'edit'} || &error($text{'mon_ecannot'}); &foreign_require("servers", "servers-lib.pl"); &ReadParse(); @handlers = &list_handlers(); if ($in{'type'}) { # Create a new monitor $type = $in{'type'}; $title = $text{'mon_create'}; if ($in{'clone'}) { # Clone of existing $serv = &get_service($in{'clone'}); } else { # Totally new $serv = { 'notify' => 'email pager snmp sms', 'fails' => 1, 'nosched' => 0, 'remote' => '*' }; } } else { # Editing an existing monitor $serv = &get_service($in{'id'}); $type = $serv->{'type'}; $title = $text{'mon_edit'}; } ($han) = grep { $_->[0] eq $type } @handlers; if ($in{'type'} && !$in{'clone'}) { $serv->{'desc'} = $han->[1]; } &ui_print_header($han->[1], $title, ""); print &ui_form_start("save_mon.cgi", "post"); print &ui_hidden("type", $in{'type'}),"\n"; print &ui_hidden("id", $in{'id'}),"\n"; @tds = ( "width=30%" ); print &ui_table_start($text{'mon_header'}, "width=100%", 2, \@tds); # Check for clone modules of the monitor type if (-d "../$type") { local @st = stat("../$type"); opendir(DIR, ".."); foreach $m (readdir(DIR)) { local @lst = stat("../$m"); if (-l "../$m" && $st[1] == $lst[1]) { # found a clone push(@clones, $m); } } } # Show input for description print &ui_table_row($text{'mon_desc'}, &ui_textbox("desc", $serv->{'desc'}, 50), undef, \@tds); # Show current status if (!$in{'type'}) { @stats = &service_status($serv, 1); $stable = "
". ($stat->{'remote'} eq "*" ? $text{'mon_local'} : $stat->{'remote'}). " | \n"; $stable .= ": | \n"; } $stable .= "". ($stat->{'desc'} && $stat->{'up'} == 0 ? "$stat->{'desc'}" : $stat->{'desc'} ? $stat->{'desc'} : $stat->{'up'} == 1 ? $text{'mon_up'} : $stat->{'up'} == -1 ? $text{'mon_not'} : $stat->{'up'} == -2 ? $text{'mon_webmin'} : $stat->{'up'} == -3 ? $text{'mon_timeout'} : $stat->{'up'} == -4 ? $text{'mon_skip'} : "$text{'mon_down'}"). " | \n"; $stable .= "
\n"; print &ui_table_start($text{'mon_header2'}, "width=100%", 2, \@tds); # Show commands to run on up/down print &ui_table_row($text{'mon_ondown'}, &ui_textbox("ondown", $serv->{'ondown'}, 60), undef, \@tds); print &ui_table_row($text{'mon_onup'}, &ui_textbox("onup", $serv->{'onup'}, 60), undef, \@tds); print &ui_table_row($text{'mon_ontimeout'}, &ui_textbox("ontimeout", $serv->{'ontimeout'}, 60), undef, \@tds); print &ui_table_row(" ", "$text{'mon_oninfo'}", undef, \@tds); # Radio button for where to run commands print &ui_table_row($text{'mon_runon'}, &ui_radio("runon", $serv->{'runon'} ? 1 : 0, [ [ 0, $text{'mon_runon0'} ], [ 1, $text{'mon_runon1'} ] ]), undef, \@tds); print &ui_table_end(); # Display inputs for this monitor type if ($type =~ /^(\S+)::(\S+)$/) { # From another module ($mod, $mtype) = ($1, $2); &foreign_require($mod, "status_monitor.pl"); print &ui_table_start($text{'mon_header3'}, "width=100%", 4, \@tds); &foreign_call($mod, "load_theme_library"); print &foreign_call($mod, "status_monitor_dialog", $mtype, $serv); print &ui_table_end(); } else { # From this module do "./${type}-monitor.pl"; $func = "show_${type}_dialog"; if (defined(&$func)) { print &ui_table_start($text{'mon_header3'}, "width=100%", 4, \@tds); &$func($serv); print &ui_table_end(); } } # Show create/delete buttons if ($in{'type'}) { print &ui_form_end([ [ "create", $text{'create'} ] ]); } else { print &ui_form_end([ [ "save", $text{'save'} ], [ "newclone", $text{'mon_clone2'} ], [ "delete", $text{'delete'} ] ]); } &ui_print_footer("", $text{'index_return'});