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/mysql_replication.py
#!/usr/bin/python

import MySQLdb
import yaml

def __run__(params):
    conn = None
##Get yaml info
    db_thresholds = yaml.load(params.get('thresholds'))
    db_host=params.get('host')
    db_port=int(params.get('port'))
#Connect_db
    try:
        f = params.get("defaults-file", "/etc/check_mk/mysql.cfg")
        conn = MySQLdb.connect(read_default_file=f)
        cursor = conn.cursor()
        cursor.execute( "SHOW SLAVE STATUS" )
        row =  cursor.fetchone()
        Slave_IO_Running = row[10]
        Slave_SQL_Running =  row[11]
        Last_Error = row[19]
        Seconds_Behind_Master = row[32]

        # check if a backup is running
        cursor.execute("SELECT COUNT(1) mysqldumpThreads FROM information_schema.processlist WHERE info LIKE 'SELECT /*!40001 SQL_NO_CACHE */%'")
        row = row =  cursor.fetchone()
        mysqldumpThreads = row[0]

        if mysqldumpThreads != 0:
            return [1, 'WARNING: Replication is delayed - Backup is running!']
        elif Slave_SQL_Running != 'Yes':
            return [2, 'CRITICAL - Slave SQL Running: %s - Slave is not running' % (Slave_SQL_Running)]
        elif Seconds_Behind_Master >= db_thresholds['critical']:
            return [2, 'CRITICAL: Seconds Behind Master: %s' % (Seconds_Behind_Master)]
        elif int(Seconds_Behind_Master) >= db_thresholds['warning']:
            return [1, 'WARNING: Seconds Behind Master: %s' % (Seconds_Behind_Master)]
        else:
            return [0, 'OK Seconds_Behind_Master: %s' % (Seconds_Behind_Master)]
    except Exception, e:
        return [2,'CRITICAL: %s' % repr(e)]