HEX
Server: Apache
System: Linux vpshost0650.publiccloud.com.br 4.4.79-grsec-1.lc.x86_64 #1 SMP Wed Aug 2 14:18:21 -03 2017 x86_64
User: bandeirantesbomb3 (10068)
PHP: 8.0.7
Disabled: apache_child_terminate,dl,escapeshellarg,escapeshellcmd,exec,link,mail,openlog,passthru,pcntl_alarm,pcntl_exec,pcntl_fork,pcntl_get_last_error,pcntl_getpriority,pcntl_setpriority,pcntl_signal,pcntl_signal_dispatch,pcntl_sigprocmask,pcntl_sigtimedwait,pcntl_sigwaitinfo,pcntl_strerror,pcntl_wait,pcntl_waitpid,pcntl_wexitstatus,pcntl_wifexited,pcntl_wifsignaled,pcntl_wifstopped,pcntl_wstopsig,pcntl_wtermsig,php_check_syntax,php_strip_whitespace,popen,proc_close,proc_open,shell_exec,symlink,system
Upload Files
File: //lib/python2.7/site-packages/lap/ldapattr.py
#  author: Jean Michel Feltrin (jean.feltrin@locaweb.com.br)

import subprocess
import os
import re

def __run__(params):
    try:
        import ldap
        import ldap.modlist as modlist
    except ImportError:
        return [2, "CRITICAL - Error: Please install python-ldap"]

    class ldapConn(object):
        serverUri = None
        bindDn = None
        passwd = None
        conn = None

        baseDn = None
        searchFilter = None
        searchScope = ldap.SCOPE_SUBTREE
        retrieveAttr = None

        def __init__(self,uri,bindDN,passwd):
            self.serverUri = uri
            self.bindDn = bindDN
            self.passwd = passwd
            self.conn = self.connect()

        def connect(self):
            for server in self.serverUri.split(','):
                try:
                    conn = ldap.initialize(server)
                    conn.set_option(ldap.OPT_NETWORK_TIMEOUT, 10.0)
                    conn.simple_bind_s(self.bindDn, self.passwd)
                    return conn

                except ldap.LDAPError, e:
                    return [2, "CRIT - Could not connect to LDAP server [%s]" % server]

        def search(self, searchFilter):
            self.searchFilter = searchFilter

            try:
                ldap_result_id = self.conn.search(self.baseDn, self.searchScope, self.searchFilter, self.retrieveAttr)
                result_set = []

                while 1:
                    result_type, result_data = self.conn.result(ldap_result_id, 0)
                    if (result_data == []):
                        break
                    else:
                        if result_type == ldap.RES_SEARCH_ENTRY:
                            result_set.append(result_data)

                return result_set

            except ldap.LDAPError, e:
                return [2, "CRIT - LDAP search failed: [filter=%s, baseDn=%s] - %s" % (self.searchFilter, self.baseDn, e)]

        def close(self):
            self.conn.unbind_s()
            del self.conn

    try:
        warn = int(params.get("warn",0))
        crit = int(params.get("crit",0))
        bindDN = params.get("bindDN","")
        baseDN = params.get("baseDN","")
        passwd = params.get("passwd","")
        uri = params.get("uri")
        attr = params.get("attr")
    except Exception, e:
        return [2, "CRITICAL - Error getting params: %s" % repr(e)]

    try:
        lconn = ldapConn(uri,bindDN,passwd)
        lconn.baseDn = baseDN
        lconn.retrieveAttr = [attr]
        result = lconn.search("objectClass=*")[0][0][1].get(attr)
        if isinstance(result,list):
            result = int(result[0])
        print crit
        if result < crit:
            return [0, "OK - Ldap attribute(%s) monitoring: %s" % (attr,result)]
        else:
            return [2, "CRIT - Ldap attribute(%s) monitoring: %s" % (attr,result)]

    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]