<commit_before>'''
Return data to a mysql server

To enable this returner the minion will need the python client for mysql
installed and the following values configured in the minion or master
config, these are the defaults:

    mysql.host: 'salt'
    mysql.user: 'salt'
    mysql.passwd: '<PASSWORD>'
    mysql.db: 'salt'
    mysql.port: 3306
'''

# Import python libs
import json

try:
    import MySQLdb 
    has_mysql = True
except ImportError:
    has_mysql = False


def __virtual__():
    if not has_mysql:
        return False
    return 'mysql'


def _get_serv():
    '''
    Return a mysql cursor
    '''
    return MySQLdb.connect(
            host=__salt__['config.option']('mysql.host'),
            user=__salt__['config.option']('mysql.user'),
            passwd=__salt__['config.option']('mysql.passwd'),
            db=__salt__['config.option']('mysql.db'),
            port=__salt__['config.option']('mysql.port'))


def returner(ret):
    '''
    Return data to a mysql server
    '''
    serv = _get_serv()
    with serv:

        cur = serv.cursor()
        sql = '''INSERT INTO `salt`.`salt_returns`
                (`fun`, `jid`, `return`, `id`, `success` )
                VALUES (%s, %s, %s, %s, %s)''' #json.dumps(ret))

        cur.execute(sql, (ret['fun'], ret['jid'], ret['return'], ret['id'], 
                            ret['success']))
        #serv.lpush('{0}:{1}'.format(ret['id'], ret['fun']), ret['jid'])

        sql2 = '''INSERT IGNORE INTO `salt`.`minions`
                (`id`) VALUES (%s)'''

        cur.execute(sql2, (ret['id'],))

        #serv.sadd('minions', ret['id'])
<commit_msg>Add json.dump of full return<commit_after>'''
Return data to a mysql server

To enable this returner the minion will need the python client for mysql
installed and the following values configured in the minion or master
config, these are the defaults:

    mysql.host: 'salt'
    mysql.user: 'salt'
    mysql.passwd: '<PASSWORD>'
    mysql.db: 'salt'
    mysql.port: 3306
'''

# Import python libs
import json

try:
    import MySQLdb 
    has_mysql = True
except ImportError:
    has_mysql = False


def __virtual__():
    if not has_mysql:
        return False
    return 'mysql'


def _get_serv():
    '''
    Return a mysql cursor
    '''
    return MySQLdb.connect(
            host=__salt__['config.option']('mysql.host'),
            user=__salt__['config.option']('mysql.user'),
            passwd=__salt__['config.option']('mysql.passwd'),
            db=__salt__['config.option']('mysql.db'),
            port=__salt__['config.option']('mysql.port'))


def returner(ret):
    '''
    Return data to a mysql server
    '''
    serv = _get_serv()
    with serv:

        cur = serv.cursor()
        sql = '''INSERT INTO `salt`.`salt_returns`
                (`fun`, `jid`, `return`, `id`, `success`, `full_ret' )
                VALUES (%s, %s, %s, %s, %s)''' #json.dumps(ret))

        cur.execute(sql, (ret['fun'], ret['jid'], ret['return'], ret['id'], 
                            ret['success'], json.dumps(ret)))
        #serv.lpush('{0}:{1}'.format(ret['id'], ret['fun']), ret['jid'])

        sql2 = '''INSERT IGNORE INTO `salt`.`minions`
                (`id`) VALUES (%s)'''

        cur.execute(sql2, (ret['id'],))

        #serv.sadd('minions', ret['id'])

{'fraction_non_alphanumeric': 0.1675741076830006, 'fraction_numerical': 0.004839685420447671, 'mean_word_length': 2.529348986125934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4601628', 'n_tokens_mistral': 1111, 'n_tokens_neox': 1046, 'n_words': 272}