import six, uuid, csv, datetime, threading, socket, shutil, argparse, glob, os, copy, pprint, time, sys
from kombu.connection import BrokerConnection
from kombu.messaging import Exchange, Queue, Consumer, Producer

XAGG_CSV_DIR="/xsight/var/opt/xagg/tmp"
XAGG_CSV_PROCESSED_DIR="/xsight/var/opt/xagg/tmp/processed"

class RabbitMQ:
    def __init__(self, rabbit_host, rabbit_user, rabbit_password, exchange_name):
        exchange = Exchange(exchange_name, "topic", durable=False)
        connection = BrokerConnection(rabbit_host, rabbit_user, rabbit_password)
        channel = connection.channel()
        self.producer = Producer(channel, exchange=exchange, routing_key="notifications.info")

    def publish(self, stats):
        self.producer.publish(stats)


class CeilometerStats:
    def __init__(self, keystone_user_id, keystone_tenant_id):
        self.message_template = {'publisher_id': "monitoring_on_"+socket.gethostname(),
                                 'priority':'INFO'}
        self.keystone_user_id = keystone_user_id
        self.keystone_tenant_id = keystone_tenant_id

    def _get_stat_template(self):
        retval = copy.copy(self.message_template)
        retval['message_id'] = six.text_type(uuid.uuid4())
        retval['timestamp'] = datetime.datetime.now().isoformat()
        retval['payload'] = {'user_id':self.keystone_user_id,'project_id':self.keystone_tenant_id}
        return retval

    def get_stat(self,name,event_type,stats={}):
        retval = self._get_stat_template()
        retval['event_type']=event_type
        retval['payload']['resource_id']=name
        for k,v in stats.iteritems():
            retval['payload'][k]=v
        return retval


class XaggStatsReader:
    XAGG_COLUMNS=[
        {"name":"dn_thruput_min","unit":"kb/s","type":"gauge"},
        {"name":"dn_thruput_max","unit":"kb/s","type":"gauge"},
        {"name":"dn_thruput_avg","unit":"kb/s","type":"gauge"},
        {"name":"up_thruput_min","unit":"kb/s","type":"gauge"},
        {"name":"up_thruput_max","unit":"kb/s","type":"gauge"},
        {"name":"up_thruput_avg","unit":"kb/s","type":"gauge"},
        {"name":"up_byte","unit":"B","type":"cumulative"},
        {"name":"dn_byte","unit":"B","type":"cumulative"},
        {"name":"up_pkt","unit":"packet","type":"cumulative"},
        {"name":"dn_pkt","unit":"packet","type":"cumulative"},
        {"name":"tcp_rtt","unit":"ms","type":"gauge"},
        {"name":"tcp_dn_retrans","unit":"packet","type":"gauge"},
        {"name":"tcp_up_retrans","unit":"packet","type":"gauge"},
        {"name":"tcp_attempt","unit":"attempt","type":"gauge"},
        {"name":"tcp_success","unit":"attempt","type":"gauge"}
    ]
    CSV_FILE_COLUMNS=["user_src_ip","user_dst_ip","enb_id","customer_group","technology",
                      "handset","os","apn","service_category","service_type","service_name",
                      "application_name","app_attempt","app_success","app_response_time",
                      "dn_byte","dn_thruput_min","dn_thruput_max","dn_thruput_avg","up_byte",
                      "up_thruput_min","up_thruput_max","up_thruput_avg","tcp_dn_retrans",
                      "tcp_up_retrans","dn_pkt","up_pkt","tcp_rtt","tcp_attempt","tcp_success"]
    def __init__(self, ceilometer_stats):
        self.stats = ceilometer_stats

    def get_stats(self, csvfile):
        fp = open(csvfile)
        f = csv.DictReader(filter(lambda row: row[0] !='#',fp),fieldnames=self.CSV_FILE_COLUMNS)
        retval = []
        for row in f:
            name=row["user_src_ip"]+"_"+row["user_dst_ip"]
            for stat in self.XAGG_COLUMNS:
                stat['volume'] = row[stat["name"]]
                retval.append(self.stats.get_stat(name,"passivetest.stats",stat))
        return retval

def periodic_publish(rabbit_mq,xagg_stats_reader):
    for stats_file in glob.glob(XAGG_CSV_DIR+"/*.csv"):
        if not os.path.isdir(stats_file):
            stats = xagg_stats_reader.get_stats(stats_file)
            for stat in stats:
                rabbit_mq.publish(stat)
            shutil.move(stats_file,XAGG_CSV_PROCESSED_DIR)

    # Publish every minute
    threading.Timer(60, periodic_publish, args=(rabbit_mq, xagg_stats_reader)).start()

def main():
    parser = argparse.ArgumentParser(description='Process xagg telemetry and send to ceilometer/monitoring service.')
    for arg in ["keystone-tenant-id","keystone-user-id","rabbit-host","rabbit-user","rabbit-password","rabbit-exchange-name"]:
        parser.add_argument("--"+arg,required=True)

    args = parser.parse_args()

    while True:
        try:
            rabbit_mq = RabbitMQ(args.rabbit_host, args.rabbit_user, args.rabbit_password, args.rabbit_exchange_name)
            ceilometer_stats = CeilometerStats(args.keystone_user_id, args.keystone_tenant_id)
            xagg_stats_reader = XaggStatsReader(ceilometer_stats)
            periodic_publish(rabbit_mq,xagg_stats_reader)
        except Exception as e:
            print(e)
            sys.stdout.flush()
        print("Trying again in one minute...")
        time.sleep(60)

if __name__ == "__main__":
   exit(main())
