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: //usr/lib/python2.7/site-packages/lap/check_redis_replication.py
import os
import sys
import yaml
import netifaces

def __run__(params):

    try:
        import redis
    except ImportError:
        return [2, 'CRITICAL: Error: Please install python-redis']
        sys.exit(1)

    try:
        host = params.get("host", "localhost")
        port = int(params.get("port", "6379"))
        conn = redis.StrictRedis(host, port, db=0)
        info = conn.info()
        status = info['role']
    except redis.exceptions.ConnectionError:
        return  [2, 'CRITICAL: Connection refused' ]
        sys.exit(1)

    with open('/etc/ha.d/haresources', 'r') as file:
        data = file.read().split()
        ipmaster = data[-2]

    if "/24" in ipmaster:
        ipmaster = ipmaster.replace('/24','')

    if status == 'master':
        if ipmaster in [netifaces.ifaddresses(iface)[netifaces.AF_INET][0]['addr'] for iface in netifaces.interfaces() if netifaces.AF_INET in netifaces.ifaddresses(iface)]:
            return [0,'OK: Status %s - vip %s' % (status, ipmaster)]
        else:
            return [2, 'CRITICAL: Status %s - vip %s absent' % (status, ipmaster)]
    else:
        if status == 'slave':
            synctime = info['master_last_io_seconds_ago']
            if synctime > 0:
                return [2, 'CRITICAL: Replication failed']
            else:
                return [0, 'OK: Status %s' % status]