- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
Recently community user pmendoza was looking for a way to be notified whenever the instance was unable to connect to one of the LDAP servers. We do have plans for better LDAP diagnostics and monitoring in a future release but there are other options today. The first one I thought of was run a recurring scheduled script to perform the action of "test connection" that's currently available as a UI action on the LDAP server form.
** This script was designed for Calgary instances. To use pre-Calgary, try replacing "new GlideLDAP()" with
"new Packages.com.glide.sys.ldap.LDAP()". I haven't tested the entire script in a pre-Calgary instance yet.
Here's the setup:
Create an event registry so we can trigger an email when a test fails.
1. Go to the System Policy -> Events -> Registry module
2. Create a new Event Registry record with the following fields:
Event name: ldap.connection_failed
Table: LDAP Server [ldap_server_config]
Fired by: LDAP Connection Test scheduled job
Create an email notification to alert the admin(s).
1. Set the following field values (customize subject, message and recipients to fit your needs)
Name: LDAP connection failed
Table: LDAP Server
Send when: Event is fired
Event name: ldap.connection_failed
Users: whoever you want to let know about the failure
Subject: LDAP Server ${name}: Failed test connection
Message: LDAP Server ${name} failed connection test
${event.parm2}
Link: ${URI_REF}
Create a scheduled script execution.
1. Go to System Definition -> Scheduled Jobs module
2. Create a new "Automatically run a script of your choosing"
Name: LDAP Connection Test
Run: Periodically
Repeat interval: whatever interval you want
Starting: now
Run this script
testLDAPServers();
function testLDAPServers() {
var ldapServer = new GlideRecord("ldap_server_config");
ldapServer.addActiveQuery();
ldapServer.query();
while (ldapServer.next()) {
var ldap = new GlideLDAP();
//get ldap server config
ldap.setConfigID(ldapServer.getUniqueValue());
//setup connection
var env = ldap.setup();
if (env == null) {
errMsg = "Failed environment setup, missing URL";
gs.eventQueue("ldap.connection_failed", ldapServer, ldapServer.getDisplayValue(), errMsg);
gs.logError("LDAP server " + ldapServer.getDisplayValue() + " failed scheduled connection test: " + errMsg, "LDAP");
continue;
}
//try connection
try {
var context = new Packages.javax.naming.ldap.InitialLdapContext(env, null);
context.close();
//no exception so we're good on this one
} catch(e) {
errMsg = "Go to LDAP server record and perform a manual connection test for additional information.";
//fire event to trigger email notification
//TODO - you need to create event registy and notification records
gs.eventQueue("ldap.connection_failed", ldapServer, ldapServer.getDisplayValue(), errMsg);
gs.logError("LDAP server " + ldapServer.getDisplayValue() + " failed scheduled connection test. " + errMsg, "LDAP");
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.