<commit_before>#!/usr/bin/env python
import sys
import subprocess
import shlex


def galera_status_check(arg):
    proc = subprocess.Popen(shlex.split(arg),
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=False)

    out, err = proc.communicate()
    ret = proc.returncode
    return ret, out, err

RETCODE, OUTPUT, ERR = galera_status_check('/usr/bin/mysql \
       --defaults-file=/root/.my.cnf \
       -e "SHOW STATUS WHERE Variable_name REGEXP \'^(wsrep.*|queries)\'"')

if RETCODE:
    print >> sys.stderr, "There was an error (%d):\n" % RETCODE
    print >> sys.stderr, ERR

if OUTPUT != "":
    SHOW_STATUS_LIST = OUTPUT.split('\n')
    del SHOW_STATUS_LIST[0]
    del SHOW_STATUS_LIST[-1]

    SLAVE_STATUS = {}
    for i in SHOW_STATUS_LIST:
        SLAVE_STATUS[i.split('\t')[0]] = i.split('\t')[1]

    if SLAVE_STATUS['wsrep_cluster_status'] != "Primary":
        print "status err there is a partition in the cluster."

    if (SLAVE_STATUS['wrsep_local_state_uuid'] !=
            SLAVE_STATUS['wsrep_cluster_state_uuid']):
        print "status err the local node is out of sync"

    if (int(SLAVE_STATUS['wsrep_local_state']) == 4 and
            SLAVE_STATUS['wsrep_local_state_comment'] == "Synced"):

        print ("status OK\n"
               "metric WSREP_REPLICATED_BYTES int "
               + SLAVE_STATUS["wsrep_replicated_bytes"] + "\n"
               "metric WSREP_RECEIVED_BYTES int "
               + SLAVE_STATUS["wsrep_received_bytes"] + "\n"
               "metric WSREP_COMMIT_WINDOW float "
               + SLAVE_STATUS["wsrep_commit_window"] + "\n"
               "metric WSREP_CLUSTER_SIZE int "
               + SLAVE_STATUS["wsrep_cluster_size"] + "\n"
               "metric QUERIES_PER_SECOND int "
               + SLAVE_STATUS["Queries"])<commit_msg>Send Cluster & Local State UUID to MaaS<commit_after>#!/usr/bin/env python
import sys
import subprocess
import shlex


def galera_status_check(arg):
    proc = subprocess.Popen(shlex.split(arg),
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE,
                            shell=False)

    out, err = proc.communicate()
    ret = proc.returncode
    return ret, out, err

RETCODE, OUTPUT, ERR = galera_status_check('/usr/bin/mysql \
       --defaults-file=/root/.my.cnf \
       -e "SHOW STATUS WHERE Variable_name REGEXP \'^(wsrep.*|queries)\'"')

if RETCODE:
    print >> sys.stderr, "There was an error (%d):\n" % RETCODE
    print >> sys.stderr, ERR

if OUTPUT != "":
    SHOW_STATUS_LIST = OUTPUT.split('\n')
    del SHOW_STATUS_LIST[0]
    del SHOW_STATUS_LIST[-1]

    SLAVE_STATUS = {}
    for i in SHOW_STATUS_LIST:
        SLAVE_STATUS[i.split('\t')[0]] = i.split('\t')[1]

    if SLAVE_STATUS['wsrep_cluster_status'] != "Primary":
        print "status err there is a partition in the cluster."

    if (SLAVE_STATUS['wrsep_local_state_uuid'] !=
            SLAVE_STATUS['wsrep_cluster_state_uuid']):
        print "status err the local node is out of sync"

    if (int(SLAVE_STATUS['wsrep_local_state']) == 4 and
            SLAVE_STATUS['wsrep_local_state_comment'] == "Synced"):

        print ("status OK\n"
               "metric WSREP_REPLICATED_BYTES int "
               + SLAVE_STATUS["wsrep_replicated_bytes"] + "\n"
               "metric WSREP_RECEIVED_BYTES int "
               + SLAVE_STATUS["wsrep_received_bytes"] + "\n"
               "metric WSREP_COMMIT_WINDOW float "
               + SLAVE_STATUS["wsrep_commit_window"] + "\n"
               "metric WSREP_CLUSTER_SIZE int "
               + SLAVE_STATUS["wsrep_cluster_size"] + "\n"
               "metric QUERIES_PER_SECOND int "
               + SLAVE_STATUS["Queries"] + "\n"
               "metric WSREP_CLUSTER_STATE_UUID str "
               + SLAVE_STATUS["wsrep_cluster_state_uuid"] + "\n"
               "metric WSREP_LOCAL_STATE_UUID str "
               + SLAVE_STATUS["wsrep_local_state_uuid"] + "\n")
{'fraction_non_alphanumeric': 0.11908888338697697, 'fraction_numerical': 0.0024758603614756128, 'mean_word_length': 2.30335241210139, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7270887', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1338, 'n_words': 262}