<commit_before>#!/bin/bash

# Purpose of the script is to clean up the tokens that are being generated to 
# validated the request.
# Author - <NAME>

source /etc/contrail/ha/cmon_param

LOGFILE=/var/log/contrail/ha/token-cleanup.log
MYIPS=$(ip addr show | sed -ne '/127.0.0.1/!{s/^[ \t]*inet[ \t]*\([0-9.]\+\)\/.*$/\1/p}')
viponme=0
mysql_user=keystone
mysql_password=<PASSWORD>
mysql_host=$VIP
mysql_port=33306
mysql=$(which mysql)
cmon_user_pass=<PASSWORD>
cmon_stats_purge="call sp_cmon_purge_history;"

timestamp() {
    date +"%T"
}
    
log_error_msg() {
    msg=$1
    echo "$(timestamp): ERROR: $msg" >> $LOGFILE
}

log_warn_msg() {
    msg=$1
    echo "$(timestamp): WARNING: $msg" >> $LOGFILE
}

log_info_msg() {
    msg=$1
    echo "$(timestamp): INFO: $msg" >> $LOGFILE
}

for myip in $MYIPS
 do
  if [ $myip == $VIP ]; then
     viponme=1
     break
  fi
 done

if [ $viponme -eq 1 ]; then
    log_info_msg "keystone-cleaner::Starting token cleanup"

    mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -P${mysql_port} -e "USE keystone ; DELETE FROM token where expires <= convert_tz(now(),@@session.time_zone,'+01:00');"
    valid_token=$($mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -P${mysql_port} -e "USE keystone ; SELECT count(*) FROM token;")
    valid_token=$(echo $valid_token | awk '{print $2}')<commit_msg>Fixes: Openstack HA : Glance image list fails on juno<commit_after>#!/bin/bash

# Purpose of the script is to clean up the tokens that are being generated to 
# validated the request.
# Author - <NAME>

source /etc/contrail/ha/cmon_param

LOGFILE=/var/log/contrail/ha/token-cleanup.log
MYIPS=$(ip addr show | sed -ne '/127.0.0.1/!{s/^[ \t]*inet[ \t]*\([0-9.]\+\)\/.*$/\1/p}')
viponme=0
mysql_user=keystone
mysql_password=<PASSWORD>
mysql_host=$VIP
mysql_port=33306
mysql=$(which mysql)
cmon_user_pass=cmon
cmon_stats_purge="call sp_cmon_purge_history;"

timestamp() {
    date +"%T"
}
    
log_error_msg() {
    msg=$1
    echo "$(timestamp): ERROR: $msg" >> $LOGFILE
}

log_warn_msg() {
    msg=$1
    echo "$(timestamp): WARNING: $msg" >> $LOGFILE
}

log_info_msg() {
    msg=$1
    echo "$(timestamp): INFO: $msg" >> $LOGFILE
}

for myip in $MYIPS
 do
  if [ $myip == $VIP ]; then
     viponme=1
     break
  fi
 done

if [ $viponme -eq 1 ]; then
    log_info_msg "keystone-cleaner::Starting token cleanup"

    NOW=`date -u +"%Y-%m-%d %T"`
    mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -P${mysql_port} -e "USE keystone ; DELETE FROM token where expires <= '${NOW}';"
    valid_token=$($mysql -u${mysql_user} -p${mysql_password} -h${mysql_host} -P${mysql_port} -e "USE keystone ; SELECT count(*) FROM token;")
    valid_token=$(echo $valid_token | awk '{print $2}')
{'fraction_non_alphanumeric': 0.17926250456370937, 'fraction_numerical': 0.016794450529390288, 'mean_word_length': 3.963768115942029, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4263332', 'n_tokens_mistral': 1108, 'n_tokens_neox': 1067, 'n_words': 249}