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/mongodb.py
import socket

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

    try:
        host = params.get("host", "localhost")
        port = int(params.get("port", "27017"))
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]


    try:
        connection = pymongo.Connection(host, port)
    except AttributeError:
        connection = pymongo.MongoClient(host, port)
    else:
        try:
            connection = pymongo.Connection(host, port, slave_okay=True)
        except Exception, e:
            return [2, "CRITICAL - Error: %s" % repr(e)]

    infos = {}
    try:
        ismaster = connection.admin.command("ismaster", "1")
        repl_status = connection.admin.command('replSetGetStatus')
        server_status = connection.admin.command('serverStatus')
        server_status.update(ismaster)
        server_status.update(repl_status)

        infos.update({'me': socket.gethostbyaddr(server_status['host'].split(':')[0])[0].split('.')[0]})
        infos.update({'repset_name': server_status['set']})
        infos.update({'version': server_status['version']})

        for member in server_status['members']:
            m_name = socket.gethostbyaddr(member['name'].split(':')[0])[0]
            s_host = socket.gethostbyaddr(server_status['host'].split(':')[0])[0]
            if m_name == s_host:
                infos.update({'status': member['stateStr']})

    except:
        try:
            server_status = connection.admin.command('serverStatus')
            infos.update({'me': socket.gethostbyaddr(server_status['host'].split(':')[0])[0].split('.')[0]})
            infos.update({'version': server_status['version']})

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

    try:
        if 'repset_name' in infos:
            if not infos.get('status', 'unknown') in [ 'PRIMARY', 'SECONDARY', 'ARBITER' ]:
                return [2, "CRITICAL - This server has the status %(status)s" % infos]
            else:
                return [0, "OK - version: %(version)s, replicaset name: %(repset_name)s, server status: %(status)s" % infos]
        else:
            return [0, "OK - version: %(version)s, this server is standalone" % infos]
    except Exception, e:
        return [2, "CRITICAL - Error: %s" % repr(e)]