Created
August 26, 2015 04:06
-
-
Save JCotton1123/0cf69d01d6ff3ebddb78 to your computer and use it in GitHub Desktop.
ScoutApp LDAP Search Time plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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