# mon-lib.pl # Common functions for mon BEGIN { push(@INC, ".."); }; use WebminCore; &init_config(); $mon_config_file = "$config{'cfbasedir'}/mon.cf"; $under = { '' => [ 'authtype', 'hostgroup', 'watch', 'use', 'period', 'serverbind', 'trapbind' ], 'watch' => [ 'service' ], 'service' => [ 'description', 'interval', 'monitor', 'period', 'depend', 'allow_empty_group', 'traptimeout', 'trapduration', 'randskew', 'dep_behavior', 'dep_behaviour', 'exclude_hosts', 'exclude_period', 'failure_interval', 'redistribute' ], 'period' => [ 'alert', 'upalert', 'alertevery', 'alertafter', 'numalerts', 'comp_alerts', 'startupalert', 'upalertafter', 'no_comp_alerts' ] }; # get_mon_config() # Parses the mon config file into a heirachical structure sub get_mon_config { if (@get_mon_config_cache) { return \@get_mon_config_cache; } local @rv; local $cv = \@rv; local ($last_indent, $parent); local $lnum = 0; open(CONF, "<".$mon_config_file); while(<CONF>) { local $slnum = $lnum; s/\s+$//; s/#.*$//g; while(s/\\$//) { local $nl = <CONF>; $nl =~ s/\s+$//; $nl =~ s/^\s+//; $_ .= $nl; $lnum++; } if (/^(\S+)\s*=\s*(.*)$/) { # Global directive local $str = { 'name' => $1, 'values' => [ split(/\s+/, $2) ], 'value' => $2, 'global' => 1, 'index' => scalar(@rv), 'line' => $slnum, 'eline' => $lnum }; push(@rv, $str); } elsif (/^(\s*)(\S+)\s*(.*)$/) { # Normal directive, possibly in a hierarchy local $str = { 'name' => $2, 'values' => [ split(/\s+/, $3) ], 'value' => $3, 'members' => [ { 'dummy' => 1, 'line' => $lnum, 'eline' => $lnum } ], 'indent' => $1, 'line' => $slnum, 'eline' => $lnum }; # Check if under the previous directive local $found; if (@$cv > 0) { local $ld = $cv->[@$cv-1]; local $pu = $under->{$ld->{'name'}}; foreach $u (@$pu) { $found++ if ($u eq $str->{'name'}); } if ($found) { # It is .. so just update the parent $parent = $ld; $cv = $ld ? $ld->{'members'} : \@rv; } } if (!$found) { # Check if under a parent local $pp = $parent; while(1) { local $pu = $under->{$pp ? $pp->{'name'} : ""}; foreach $u (@$pu) { $found++ if ($u eq $str->{'name'}); } if ($found) { # Under some ancestor .. make that # the current parent $parent = $pp; $cv = $pp ? $pp->{'members'} : \@rv; last; } else { last if (!$pp); $pp = $pp->{'parent'}; } } if (!$found) { # Check if a hostname under a previous hostgroup if (@$cv && $cv->[$#cv]->{'name'} eq 'hostgroup') { push(@{$cv->[$#cv]->{'values'}}, $str->{'name'}); $cv->[$#cv]->{'eline'} = $lnum; goto nextline; } } &error("Unknown directive $str->{'name'}") if (!$found); } $str->{'index'} = scalar(@$cv); $str->{'parent'} = $parent; push(@$cv, $str); # Set parent end lines local $pp = $parent; do { $pp->{'eline'} = $lnum; $pp = $pp->{'parent'}; } while($pp); } nextline: $lnum++; } close(CONF); @get_mon_config_cache = @rv; return \@get_mon_config_cache; } # find_value(name, &config) sub find_value { foreach $c (@{$_[1]}) { if ($c->{'name'} eq $_[0]) { return wantarray ? @{$c->{'values'}} : $c->{'values'}->[0]; } } return wantarray ? ( ) : undef; } # find(name, &config) sub find { local @rv; foreach $c (@{$_[1]}) { if ($c->{'name'} eq $_[0]) { push(@rv, $c); } } return wantarray ? @rv : $rv[0]; } # save_directive(&config, [&old|undef], [&new|undef]) sub save_directive { local $lref = &read_file_lines($mon_config_file); local @same = &find($_[2]->{'name'}, $_[0]) if ($_[2]); local $idx = &indexof($_[1], @{$_[0]}) if ($_[1]); local $olen = $_[1]->{'eline'} - $_[1]->{'line'} + 1 if ($_[1]); local $conf = &get_mon_config(); local @dirs = &directive_lines($_[2], $_[2]->{'indent'}) if ($_[2]); if ($_[1] && $_[2]) { # Replace the old directive splice(@$lref, $_[1]->{'line'}, $_[1]->{'eline'} - $_[1]->{'line'} + 1, @dirs); $_[0]->[$idx] = $_[2]; &renumber($conf, $_[1]->{'line'}, @dirs - $olen); $_[2]->{'line'} = $_[1]->{'line'}; $_[2]->{'eline'} = $_[2]->{'line'} + @dirs - 1; } elsif ($_[1] && !$_[2]) { # Remove the old directive splice(@$lref, $_[1]->{'line'}, $_[1]->{'eline'} - $_[1]->{'line'} + 1); splice(@{$_[0]}, $idx, 1); &renumber($conf, $_[1]->{'line'}, -$olen); } elsif (@same) { # Add after last directive of same type splice(@$lref, $same[@same-1]->{'eline'}+1, 0, @dirs); splice(@{$_[0]}, $idx+1, 0, $_[2]); &renumber($conf, $same[@same-1]->{'eline'}+1, scalar(@dirs)); $_[2]->{'line'} = $same[@same-1]->{'eline'}+1; $_[2]->{'eline'} = $_[2]->{'line'} + @dirs - 1; } else { # Add after last directive in config local $ld = $_[0]->[@{$_[0]}-1]; splice(@$lref, $ld->{'eline'} + 1, 0, @dirs); push(@{$_[0]}, $_[2]); &renumber($conf, $ld->{'eline'} + 1, scalar(@dirs)); $_[2]->{'line'} = $ld->{'eline'} + 1; $_[2]->{'eline'} = $ld->{'eline'} + @dirs - 1; } } # renumber(&config, position, offset) sub renumber { foreach $c (@{$_[0]}) { $c->{'line'} += $_[2] if ($c->{'line'} >= $_[1]); $c->{'eline'} += $_[2] if ($c->{'eline'} >= $_[1]); &renumber($c->{'members'}, $_[1], $_[2]); } } # directive_lines(&directive, [indent]) sub directive_lines { local @rv; @rv = ( $_[1].join(" ", $_[0]->{'name'}, $_[0]->{'global'} ? ( "=" ) : ( ), @{$_[0]->{'values'}}) ); foreach $m (@{$_[0]->{'members'}}) { push(@rv, &directive_lines($m, "$_[1] ")) if (!$m->{'dummy'}); } return @rv; } # list_monitors() # Returns a list of all monitors sub list_monitors { local $conf = &get_mon_config(); local $mondir = &find_value("mondir", $conf); local @rv; foreach my $dir (split(/:/, $mondir)) { opendir(DIR, $dir); foreach my $f (readdir(DIR)) { push(@rv, $f) if ($f =~ /\.monitor$/); } closedir(DIR); } return @rv; } # list_alerts() # Returns a list of all alerts sub list_alerts { local $conf = &get_mon_config(); local $mondir = &find_value("alertdir", $conf); local @rv; foreach my $dir (split(/:/, $mondir)) { opendir(DIR, $dir); foreach $f (readdir(DIR)) { push(@rv, $f) if ($f =~ /\.alert$/ || $f =~ /^alert\./); } closedir(DIR); } return @rv; } # mon_users_file() # Returns the file in which MON users are stored sub mon_users_file { local $conf = &get_mon_config(); local $uf = &find_value("userfile", $conf); $uf = "monusers.cf" if (!$uf); if ($uf =~ /^\//) { return $uf; } else { local $bd = &find_value("cfbasedir", $conf); $bd = $config{'cfbasedir'} if (!$bd); return "$bd/$uf"; } } # list_users() sub list_users { local(@rv, $lnum = 0); open(USERS, "<".&mon_users_file()); while(<USERS>) { s/\r|\n//g; s/#.*//; if (/^([^:]+):(\S+)/) { push(@rv, { 'user' => $1, 'pass' => $2, 'line' => $lnum }); } $lnum++; } close(USERS); return @rv; } # create_user(&user) sub create_user { local $lref = &read_file_lines(&mon_users_file()); push(@$lref, $_[0]->{'user'}.":".$_[0]->{'pass'}); &flush_file_lines(&mon_users_file()); } # modify_user(&user) sub modify_user { local $lref = &read_file_lines(&mon_users_file()); $lref->[$_[0]->{'line'}] = $_[0]->{'user'}.":".$_[0]->{'pass'}; &flush_file_lines(&mon_users_file()); } # delete_user(&user) sub delete_user { local $lref = &read_file_lines(&mon_users_file()); splice(@$lref, $_[0]->{'line'}, 1); &flush_file_lines(&mon_users_file()); } # mon_auth_file() sub mon_auth_file { local $conf = &get_mon_config(); local $af = &find_value("authfile", $conf); $af = "auth.cf" if (!$af); if ($af =~ /^\//) { return $af; } else { local $bd = &find_value("cfbasedir", $conf); return "$bd/$af"; } } sub list_auth_types { return ('list', 'servertime', 'reset', 'loadstate', 'savestate', 'term', 'stop', 'start', 'set', 'get', 'dump', 'disable', 'enable', 'test', 'ack', 'reload', 'clear'); } # day_input(name, value) sub day_input { local @days = ( 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun' ); local $rv = "<select name=$_[0]>\n"; foreach $d (@days) { $rv .= sprintf "<option %s>%s</option>\n", lc($d) eq lc($_[1]) ? "selected" : "", $d; } $rv .= "</select>\n"; return $rv; } # interval_input(name, value) sub interval_input { local ($int, $units, $rv); if ($_[1] =~ /^([\d\.]+)(\S)$/) { $int = $1; $units = $2; } $rv = "<input name=$_[0] size=6 value='$int'>\n"; $rv .= "<select name=$_[0]_u>\n"; foreach $u ('s', 'm', 'h', 'd') { $rv .= sprintf "<option value=%s %s>%s</option>\n", $u, $units eq $u ? "selected" : "", $text{"service_units_$u"}; } $rv .= "</select>\n"; return $rv; } # restart_mon() # Re-start the MON process, returning undef on success or an error message # on failure sub restart_mon { if ($config{'restart_cmd'}) { local $out = &backquote_logged("$config{'restart_cmd'} 2>&1 </dev/null"); return "<tt>$out</tt>" if ($?); } else { local $pid = &check_pid_file($config{'pid_file'}); if ($pid) { kill('HUP', $pid); return undef; } else { return $text{'restart_epid'}; } } } 1;
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
help | Folder | 0755 |
|
|
images | Folder | 0755 |
|
|
lang | Folder | 0755 |
|
|
CHANGELOG | File | 113 B | 0644 |
|
README | File | 287 B | 0644 |
|
backup_config.pl | File | 732 B | 0755 |
|
config | File | 201 B | 0644 |
|
config-Fedora-Linux | File | 189 B | 0644 |
|
config.info | File | 362 B | 0644 |
|
config.info.ca | File | 397 B | 0644 |
|
config.info.cs | File | 375 B | 0644 |
|
config.info.de | File | 429 B | 0644 |
|
config.info.es | File | 399 B | 0644 |
|
config.info.nl | File | 420 B | 0644 |
|
config.info.no | File | 381 B | 0644 |
|
config.info.ru | File | 506 B | 0644 |
|
config.info.uk | File | 511 B | 0644 |
|
create_watch.cgi | File | 281 B | 0755 |
|
edit_auth.cgi | File | 1.43 KB | 0755 |
|
edit_global.cgi | File | 2.01 KB | 0755 |
|
edit_service.cgi | File | 8.05 KB | 0755 |
|
edit_user.cgi | File | 1.38 KB | 0755 |
|
edit_watch.cgi | File | 2.21 KB | 0755 |
|
feedback_files.pl | File | 113 B | 0755 |
|
index.cgi | File | 1.52 KB | 0755 |
|
install_check.pl | File | 329 B | 0755 |
|
list_groups.cgi | File | 832 B | 0755 |
|
list_periods.cgi | File | 2.09 KB | 0755 |
|
list_users.cgi | File | 1.03 KB | 0755 |
|
list_watches.cgi | File | 1.26 KB | 0755 |
|
module.info | File | 181 B | 0644 |
|
module.info.af | File | 0 B | 0644 |
|
module.info.af.auto | File | 108 B | 0644 |
|
module.info.ar | File | 0 B | 0644 |
|
module.info.ar.auto | File | 136 B | 0644 |
|
module.info.be | File | 0 B | 0644 |
|
module.info.be.auto | File | 166 B | 0644 |
|
module.info.bg | File | 0 B | 0644 |
|
module.info.bg.auto | File | 171 B | 0644 |
|
module.info.ca | File | 117 B | 0644 |
|
module.info.ca.auto | File | 13 B | 0644 |
|
module.info.cs | File | 37 B | 0644 |
|
module.info.cs.auto | File | 86 B | 0644 |
|
module.info.da | File | 0 B | 0644 |
|
module.info.da.auto | File | 108 B | 0644 |
|
module.info.de | File | 111 B | 0644 |
|
module.info.de.auto | File | 12 B | 0644 |
|
module.info.el | File | 0 B | 0644 |
|
module.info.el.auto | File | 192 B | 0644 |
|
module.info.es | File | 32 B | 0644 |
|
module.info.es.auto | File | 91 B | 0644 |
|
module.info.eu | File | 0 B | 0644 |
|
module.info.eu.auto | File | 121 B | 0644 |
|
module.info.fa | File | 0 B | 0644 |
|
module.info.fa.auto | File | 168 B | 0644 |
|
module.info.fi | File | 0 B | 0644 |
|
module.info.fi.auto | File | 105 B | 0644 |
|
module.info.fr | File | 0 B | 0644 |
|
module.info.fr.auto | File | 126 B | 0644 |
|
module.info.he | File | 0 B | 0644 |
|
module.info.he.auto | File | 136 B | 0644 |
|
module.info.hr | File | 0 B | 0644 |
|
module.info.hr.auto | File | 119 B | 0644 |
|
module.info.hu | File | 0 B | 0644 |
|
module.info.hu.auto | File | 122 B | 0644 |
|
module.info.it | File | 0 B | 0644 |
|
module.info.it.auto | File | 121 B | 0644 |
|
module.info.ja | File | 0 B | 0644 |
|
module.info.ja.auto | File | 160 B | 0644 |
|
module.info.ko | File | 0 B | 0644 |
|
module.info.ko.auto | File | 138 B | 0644 |
|
module.info.lt | File | 0 B | 0644 |
|
module.info.lt.auto | File | 141 B | 0644 |
|
module.info.lv | File | 0 B | 0644 |
|
module.info.lv.auto | File | 128 B | 0644 |
|
module.info.ms | File | 105 B | 0644 |
|
module.info.ms.auto | File | 12 B | 0644 |
|
module.info.mt | File | 0 B | 0644 |
|
module.info.mt.auto | File | 132 B | 0644 |
|
module.info.nl | File | 28 B | 0644 |
|
module.info.nl.auto | File | 89 B | 0644 |
|
module.info.no | File | 31 B | 0644 |
|
module.info.no.auto | File | 82 B | 0644 |
|
module.info.pl | File | 0 B | 0644 |
|
module.info.pl.auto | File | 112 B | 0644 |
|
module.info.pt | File | 0 B | 0644 |
|
module.info.pt.auto | File | 122 B | 0644 |
|
module.info.pt_BR | File | 0 B | 0644 |
|
module.info.pt_BR.auto | File | 131 B | 0644 |
|
module.info.ro | File | 0 B | 0644 |
|
module.info.ro.auto | File | 128 B | 0644 |
|
module.info.ru | File | 38 B | 0644 |
|
module.info.ru.auto | File | 154 B | 0644 |
|
module.info.sk | File | 0 B | 0644 |
|
module.info.sk.auto | File | 122 B | 0644 |
|
module.info.sl | File | 0 B | 0644 |
|
module.info.sl.auto | File | 113 B | 0644 |
|
module.info.sv | File | 0 B | 0644 |
|
module.info.sv.auto | File | 117 B | 0644 |
|
module.info.th | File | 0 B | 0644 |
|
module.info.th.auto | File | 255 B | 0644 |
|
module.info.tr | File | 0 B | 0644 |
|
module.info.tr.auto | File | 123 B | 0644 |
|
module.info.uk | File | 0 B | 0644 |
|
module.info.uk.auto | File | 214 B | 0644 |
|
module.info.ur | File | 0 B | 0644 |
|
module.info.ur.auto | File | 158 B | 0644 |
|
module.info.vi | File | 0 B | 0644 |
|
module.info.vi.auto | File | 155 B | 0644 |
|
module.info.zh | File | 0 B | 0644 |
|
module.info.zh.auto | File | 121 B | 0644 |
|
module.info.zh_TW | File | 0 B | 0644 |
|
module.info.zh_TW.auto | File | 130 B | 0644 |
|
mon-lib.pl | File | 8.96 KB | 0755 |
|
mon.cgi | File | 998 B | 0755 |
|
mon_action.cgi | File | 415 B | 0755 |
|
moncmd.diff | File | 2.52 KB | 0644 |
|
moncmd.pl | File | 5.66 KB | 0755 |
|
monshow.cgi | File | 564 B | 0755 |
|
monshowrc | File | 166 B | 0644 |
|
restart.cgi | File | 180 B | 0755 |
|
save_auth.cgi | File | 625 B | 0755 |
|
save_global.cgi | File | 1.7 KB | 0755 |
|
save_groups.cgi | File | 656 B | 0755 |
|
save_periods.cgi | File | 1.11 KB | 0755 |
|
save_service.cgi | File | 4.71 KB | 0755 |
|
save_user.cgi | File | 823 B | 0755 |
|
save_watch.cgi | File | 370 B | 0755 |
|
start.cgi | File | 226 B | 0755 |
|
stop.cgi | File | 423 B | 0755 |
|