<commit_before>nagios_probe = '';
nagios_warn = 85;
nagios_critical = 95;

function run(link, cli_args){
    gs = globals();
    opt = '';
    foreach(cli_args as arg){
		if(opt == '' && arg.startswith('-')){
			opt = arg;
		}else{
			switch(opt){
				case '-n':
                    opt = '';
                    gs['nagios_probe'] = arg;
					break;
				case '-w':
                    gs['nagios_warn'] = arg;
                    opt = '';
					break;
				case '-c':
                    gs['nagios_critical'] = arg;
                    opt = '';
                    break;
                default: 
                    # ignore args '-h host -p port'
                    opt = '';
                    break;
			}
		}
	}
	try{
           resp = link.request('info', []);
           if(nagios_probe == 'info'){
               nagios_info(resp);
           }
           if(nagios_probe == 'dbsize'){
               nagios_dbsize(resp);
           }
           if(nagios_probe == 'replication'){
               nagios_replication(resp);
           }
           if(nagios_probe == 'write_read'){
               nagios_write_read(link);
           }
           # Possible future checks:
           # - check if binlogs.max_seq == replication.client.last_seq
           # - does total_calls is growing
	}catch(Exception e){
           sys.stderr.write(str(e) + '\n');
	}
	#sys.stderr.write('exit\n');
	exit(0);
}

function nagios_info(resp){
    is_val = false;
    for(i=1; i<len(resp.data); i++){
        s = resp.data[i];
        if(is_val){
            s = '	' + s.replace('\n', '\n	');
        }
        print s;
        is_val = !is_val;
    }
}

function nagios_probe_check(resp){
    next_val = false;
    ret = '';
    for(i=1; i<len(resp.data); i++){
        s = resp.data[i];
        if(next_val){
            s = s.replace('\n', '\n	');
            next_val = !next_val;
            #print s;
            ret += s;
        }
        if(s == nagios_probe){
            next_val = !next_val;
        }
    }
    return ret;
}

function nagios_dbsize(resp){
    dbsize = nagios_probe_check(resp);
    if(dbsize > nagios_critical){
        print 'CRITICAL: dbsize ' + str(dbsize) + ' larger than ' + str(nagios_critical);
        exit(2);
    }else if(dbsize > nagios_warn){
        print 'WARN: dbsize ' + str(dbsize) + ' larger than ' + str(nagios_warn);
        exit(1);
    }else{
        print 'OK: dbsize ' + str(dbsize) + ' less than ' + str(nagios_critical);
        exit(0);
    }
}

function nagios_replication(resp){
    replication = nagios_probe_check(resp);
    replication = replication.replace('slaveof', '\nslaveof');
    if(replication.find('DISCONNECTED') > 0 ){
        print 'CRITICAL: ' + replication;
        exit(2);
    }else if(replication.find('COPY') > 0 || replication.find('INIT') > 0 || replication.find('OUT_OF_SYNC') > 0){
        print 'WARN: ' + replication;
        exit(1);
    }else if(replication.find('SYNC') > 0){
        print 'OK: ' + replication;
        exit(0);
    }else{
        print 'WARN, is replication configured? Status: ' + replication;
        exit(1);
    }
}

function nagios_write_read(link){
    test_key = 'write_read_test_key';
    resp = link.request('set', ['nagiostest', test_key]);
    #print resp;
    resp = link.request('get', ['nagiostest']);
    #print resp;
    if (resp.data == test_key){
       print 'OK: ' + resp.data;
       exit(0);
    }else{
       print 'WRITE_READ failed: ' + resp.data;
       exit(2);
    }
}<commit_msg>fix indention - space to tab<commit_after>nagios_probe = '';
nagios_warn = 85;
nagios_critical = 95;

function run(link, cli_args){
		gs = globals();
		opt = '';
		foreach(cli_args as arg){
		if(opt == '' && arg.startswith('-')){
			opt = arg;
		}else{
			switch(opt){
				case '-n':
					opt = '';
					gs['nagios_probe'] = arg;
					break;
				case '-w':
					gs['nagios_warn'] = arg;
					opt = '';
					break;
				case '-c':
					gs['nagios_critical'] = arg;
					opt = '';
					break;
				default: 
					# ignore args '-h host -p port'
					opt = '';
					break;
			}
		}
	}
	try{
		resp = link.request('info', []);
		if(nagios_probe == 'info'){
			nagios_info(resp);
		}
		if(nagios_probe == 'dbsize'){
			nagios_dbsize(resp);
		}
		if(nagios_probe == 'replication'){
			nagios_replication(resp);
		}
		if(nagios_probe == 'write_read'){
			nagios_write_read(link);
		}
		# Possible future checks:
		# - check if binlogs.max_seq == replication.client.last_seq
		# - does total_calls is growing
	}catch(Exception e){
		sys.stderr.write(str(e) + '\n');
	}
	#sys.stderr.write('exit\n');
	exit(0);
}

function nagios_info(resp){
	is_val = false;
	for(i=1; i<len(resp.data); i++){
		s = resp.data[i];
		if(is_val){
			s = '	' + s.replace('\n', '\n	');
		}
		print s;
		is_val = !is_val;
		}
}

function nagios_probe_check(resp){
	next_val = false;
	ret = '';
	for(i=1; i<len(resp.data); i++){
		s = resp.data[i];
		if(next_val){
			s = s.replace('\n', '\n	');
			next_val = !next_val;
			#print s;
			ret += s;
		}
		if(s == nagios_probe){
			next_val = !next_val;
		}
	}
	return ret;
}

function nagios_dbsize(resp){
	dbsize = nagios_probe_check(resp);
	if(dbsize > nagios_critical){
		print 'CRITICAL: dbsize ' + str(dbsize) + ' larger than ' + str(nagios_critical);
		exit(2);
	}else if(dbsize > nagios_warn){
		print 'WARN: dbsize ' + str(dbsize) + ' larger than ' + str(nagios_warn);
		exit(1);
	}else{
		print 'OK: dbsize ' + str(dbsize) + ' less than ' + str(nagios_critical);
		exit(0);
	}
}

function nagios_replication(resp){
	replication = nagios_probe_check(resp);
	replication = replication.replace('slaveof', '\nslaveof');
	if(replication.find('DISCONNECTED') > 0 ){
		print 'CRITICAL: ' + replication;
		exit(2);
	}else if(replication.find('COPY') > 0 || replication.find('INIT') > 0 || replication.find('OUT_OF_SYNC') > 0){
		print 'WARN: ' + replication;
		exit(1);
	}else if(replication.find('SYNC') > 0){
		print 'OK: ' + replication;
		exit(0);
	}else{
		print 'WARN, is replication configured? Status: ' + replication;
		exit(1);
	}
}

function nagios_write_read(link){
	test_key = 'write_read_test_key';
	resp = link.request('set', ['nagiostest', test_key]);
	#print resp;
	resp = link.request('get', ['nagiostest']);
	#print resp;
	if (resp.data == test_key){
		print 'OK: ' + resp.data;
		exit(0);
	}else{
		print 'WRITE_READ failed: ' + resp.data;
		exit(2);
	}
}
{'fraction_non_alphanumeric': 0.17028928850664582, 'fraction_numerical': 0.006567630961688819, 'mean_word_length': 2.3364632237871676, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '6855888', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2396, 'n_words': 452}