Skip to content

Instantly share code, notes, and snippets.

@JCotton1123
Created August 26, 2015 04:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JCotton1123/0cf69d01d6ff3ebddb78 to your computer and use it in GitHub Desktop.
Save JCotton1123/0cf69d01d6ff3ebddb78 to your computer and use it in GitHub Desktop.
ScoutApp LDAP Search Time plugin
class LDAPSearchTime < Scout::Plugin
OPTIONS=<<-EOS
uri:
default: ldapi:///
name: URI
authmech:
default: EXTERNAL
name: Auth Mechanism
username:
name: Username
password:
name: Password
base:
name: Base
filter:
name: Filter
EOS
def build_report
before = Time.now
result = execute_cli_search(
option(:uri),
option(:authmech),
option(:username),
option(:password),
option(:base),
option(:filter)
)
after = Time.now
if result[0] != 0
raise RuntimeError, "Exit status #{result[0]}: #{result[1]}"
end
search_time = after - before
report(:time => search_time)
end
def execute_cli_search(uri, authmech, username, password, base, filter)
params = []
params.push("-H #{uri}")
params.push("-Y #{authmech}") unless authmech.nil?
params.push("-D #{username}") unless username.nil?
params.push("-w \"#{password}\"") unless password.nil?
params.push("-b \"#{base}\"")
params.push("\"#{filter}\"")
params_string = params.join(" ")
result = `ldapsearch #{params_string} 2>&1`
return [$?.exitstatus, result]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment