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/xtradb_cluster.py
import MySQLdb
import yaml

def __run__(params):
    conn = None

# get the parameters to connect
    try:
        f = params.get("defaults-file", "/etc/check_mk/mysql.cfg")
        conn = MySQLdb.connect(read_default_file=f)
        cursor = conn.cursor()


#check the role of node

        cursor.execute("select variable_value from information_schema.global_status where variable_name='wsrep_cluster_status'")
        node_role = cursor.fetchone()[0]

        if node_role != "Primary":
            return[2,'CRITICAL: Node is not Primary! Check your cluster! ']
        else:
            node_role_status = 0

# check if wsrep (MySQL Write Set Replication), is connected

        cursor.execute("select variable_value from information_schema.global_status where variable_name='wsrep_connected';")
        wsrep_connected = cursor.fetchone()[0]

        if wsrep_connected != "ON":
            return[2,'CRITICAL: wsrep is not connected ']
        else:
            wsrep_connected_status = 0

#check the number of nodes

        cursor.execute("select variable_value from information_schema.global_status where variable_name='wsrep_cluster_size'")
        number_nodes = cursor.fetchone()[0]
        cursor.execute("select variable_value from information_schema.global_variables where variable_name='wsrep_cluster_address';")
        nodes_adresses = cursor.fetchall()

        if number_nodes == "2":
            return[2, 'CRITICAL: 1 node is down! Check your cluster! Hosts: %s ' % nodes_adresses ]
        else:
            number_nodes_status = 0

# check sync between nodes

        cursor.execute("select variable_value from information_schema.global_status where variable_name='wsrep_local_state'")
        wsrep_local_state = cursor.fetchone()[0]
        cursor.execute("select variable_value from information_schema.global_status where variable_name='wsrep_local_state_comment'")
        wsrep_local_state_comment = cursor.fetchone()[0]

        if wsrep_local_state != "4" or wsrep_local_state_comment != "Synced":
            return[2,'CRITICAL: The node are not synced']
        else:
            wsrep_local_state_status = 0
            wsrep_local_state_comment_status =0

# validating checks

        if node_role_status == 0 and wsrep_connected_status == 0 and number_nodes_status == 0 and wsrep_local_state_status == 0 and wsrep_local_state_comment_status == 0:
            return[0,'OK: Cluster is working fine!' ]

    except Exception, e:
        return [2, 'CRITICAL: {0}'.format(str(e))]
    finally:
        try:
            if conn:
                conn.close()
        except:
            # finally clause, don't bother about errors here
            pass