New monitor types for LDAP

This commit is contained in:
Jamie Cameron
2014-05-12 15:03:25 -07:00
parent d539c6603a
commit b5b52c3f5c
4 changed files with 83 additions and 7 deletions

View File

@@ -179,7 +179,7 @@ elsif ($_[0]) { return $err; } # Caller asked for error return
else { &error($err); } # Caller asked for error() call
}
# generic_ldap_connect([host], [port], [login], [password])
# generic_ldap_connect([host], [port], [ssl], [login], [password])
# A generic function for connecting to an LDAP server. Uses the system's
# LDAP client config file if any parameters are missing. Returns the LDAP
# handle on success or an error message on failure.
@@ -207,6 +207,7 @@ local $cafile = &find_svalue("tls_cacertfile", $conf);
local $certfile = &find_svalue("tls_cert", $conf);
local $keyfile = &find_svalue("tls_key", $conf);
local $ciphers = &find_svalue("tls_ciphers", $conf);
local $host;
if ($ldap_hosts) {
# Using hosts from parameter
local @hosts = split(/[ \t,]+/, $ldap_hosts);
@@ -220,11 +221,11 @@ if ($ldap_hosts) {
local $port = $ldap_port ||
&find_svalue("port", $conf) ||
($use_ssl == 1 ? 636 : 389);
foreach my $host (@hosts) {
foreach my $h (@hosts) {
eval {
$ldap = Net::LDAP->new($host, port => $port,
$ldap = Net::LDAP->new($h, port => $port,
scheme => $use_ssl == 1 ? 'ldaps' : 'ldap',
inet6 => &should_use_inet6($host));
inet6 => &should_use_inet6($h));
};
if ($@) {
$err = &text('ldap_econn2',
@@ -236,6 +237,7 @@ if ($ldap_hosts) {
"<tt>$host</tt>", "<tt>$port</tt>");
}
else {
$host = $h;
$err = undef;
last;
}
@@ -280,15 +282,16 @@ else {
($use_ssl == 1 ? 636 : 389);
@hosts = ( "localhost" ) if (!@hosts);
foreach $host (@hosts) {
$ldap = Net::LDAP->new($host, port => $port,
foreach my $h (@hosts) {
$ldap = Net::LDAP->new($h, port => $port,
scheme => $use_ssl == 1 ? 'ldaps' : 'ldap',
inet6 => &should_use_inet6($host));
inet6 => &should_use_inet6($h));
if (!$ldap) {
$err = &text('ldap_econn',
"<tt>$host</tt>", "<tt>$port</tt>");
}
else {
$host = $h;
$err = undef;
last;
}

View File

@@ -80,3 +80,5 @@ Update the SSL certificate monitor to check alternate names as well when looking
---- Changes since 1.590 ----
Commands run when a monitor goes up or down can now access details of the monitor via environment variables starting with STATUS_
A history of the status of each monitor's scheduled checks is now logged for 30 days, and can be viewed on the Edit Monitor page. This also includes the value associated with the monitor (such as free disk space), if any.
---- Changes since 1.670 ----
Added new monitor types to check if an LDAP server is up, and if an LDAP connection is possible.

View File

@@ -526,4 +526,12 @@ du_edir=Missing or non-absolute directory path
du_emax=Missing or non-numeric maximum size
du_over=Size is $1
du_under=Size is only $1
ldap_edriver=The Perl module $1 is not installed
ldap_host=LDAP server hostname
ldap_port=LDAP server port
ldap_ssl=Use SSL connection?
ldap_user=LDAP server login
ldap_pass=LDAP server password
__norefs=1

63
status/ldap-monitor.pl Executable file
View File

@@ -0,0 +1,63 @@
# ldap-monitor.pl
# Try an LDAP ldap on a server
sub get_ldap_status
{
# Check for the Perl module
eval "use Net::LDAP";
if ($@) {
return { 'up' => -1,
'desc' => &text('ldap_edriver', '<tt>Net::LDAP</tt>') };
}
&foreign_require("ldap-client");
my $err = &ldap_client::generic_ldap_connect($_[0]->{'host'}, $_[0]->{'port'},
$_[0]->{'ssl'}, $_[0]->{'user'},
$_[0]->{'pass'});
if (!ref($err)) {
return { 'up' => 0,
'desc' => $err };
}
return { 'up' => 1 };
}
sub show_ldap_dialog
{
print &ui_table_row($text{'ldap_host'},
&ui_textbox("host", $_[0]->{'host'}, 60), 3);
print &ui_table_row($text{'ldap_port'},
&ui_opt_textbox("port", $_[0]->{'port'}, 6, $text{'default'}));
print &ui_table_row($text{'ldap_ssl'},
&ui_yesno_radio("ssl", $_[0]->{'ssl'}), 3);
print &ui_table_row($text{'ldap_user'},
&ui_textbox("quser", $_[0]->{'user'}, 60), 3);
print &ui_table_row($text{'ldap_pass'},
&ui_password("qpass", $_[0]->{'pass'}, 20), 3);
}
sub parse_ldap_dialog
{
eval "use Net::LDAP";
return &text('ldap_edriver', '<tt>Net::LDAP</tt>') if ($@);
&to_ipaddress($in{'host'}) || &to_ip6address($in{'host'}) ||
&error($text{'ldap_ehost'});
$_[0]->{'host'} = $in{'host'};
$in{'port_def'} || $in{'port'} =~ /^\d+$/ || &error($text{'ldap_eport'});
$_[0]->{'port'} = $in{'port_def'} ? undef : $in{'port'};
$_[0]->{'ssl'} = $in{'ssl'};
$in{'quser'} =~ /^\S*$/ || &error($text{'ldap_euser'});
$_[0]->{'user'} = $in{'quser'};
$in{'qpass'} =~ /^\S*$/ || &error($text{'ldap_epass'});
$_[0]->{'pass'} = $in{'qpass'};
}