Exemplo n.º 1
0
def import_cdr_backend(shell=False,backend=None):
    #TODO : dont use the args here
    # Browse settings.ASTERISK_MYSQL and for each IP
    # check if the IP exist in our Switch objects if it does we will
    # connect to that Database and import the data as we do below

    print_shell(shell, "Starting the synchronization...")

    if backend not in ['mysql','freeswitch']:
        print_shell(shell, "The switch is not configured to import CDRS")
        return False

    #loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        switch = data['switch']

        #Connect to Database
        db_name = settings.CDR_BACKENDS[ipaddress]['db_name']
        table_name = settings.CDR_BACKENDS[ipaddress]['table_name']
        user = settings.CDR_BACKEND[ipaddress]['user']
        password = settings.CDR_BACKEND[ipaddress]['password']
        host = settings.CDR_BACKEND[ipaddress]['host']
        try:
            connection = Database.connect(user=user, passwd=password, \
                                            db=db_name, host=host)
            connection.autocommit(True)
            cursor = connection.cursor()
            #update cursor used as we update at the end and we need
            #to fetch on 1st cursor
            cursor_updated = connection.cursor()
        except Exception, e:
            sys.stderr.write("Could not connect to Database: %s - %s" % \
                                                            (e, ipaddress))
            sys.exit(1)

        try:
            cursor.execute("SELECT VERSION() from %s WHERE import_cdr "\
                            "IS NOT NULL LIMIT 0,1" % table_name)
            row = cursor.fetchone()
        except Exception, e:
            #Add missing field to flag import
            cursor.execute("ALTER TABLE %s  ADD import_cdr TINYINT NOT NULL "\
                            "DEFAULT '0'" % table_name)
            cursor.execute("ALTER TABLE %s ADD INDEX (import_cdr)" % \
                            table_name)
Exemplo n.º 2
0
def import_cdr_asterisk_mysql(shell=False):
    #TODO : dont use the args here
    # Browse settings.ASTERISK_MYSQL and for each IP
    # check if the IP exist in our Switch objects if it does we will
    # connect to that Database and import the data as we do below

    print_shell(shell, "Starting the synchronization...")

    if settings.LOCAL_SWITCH_TYPE != 'asterisk':
        print_shell(shell, "The switch is not configured to import Asterisk")
        return False

    #loop within the Mongo CDR Import List
    for ipaddress in settings.ASTERISK_MYSQL:

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        switch = data['switch']

        #Connect on Mysql Database
        db_name = settings.ASTERISK_MYSQL[ipaddress]['db_name']
        table_name = settings.ASTERISK_MYSQL[ipaddress]['table_name']
        user = settings.ASTERISK_MYSQL[ipaddress]['user']
        password = settings.ASTERISK_MYSQL[ipaddress]['password']
        host = settings.ASTERISK_MYSQL[ipaddress]['host']
        try:
            connection = Database.connect(user=user, passwd=password, \
                                            db=db_name, host=host)
            connection.autocommit(True)
            cursor = connection.cursor()
            #update cursor used as we update at the end and we need
            #to fetch on 1st cursor
            cursor_updated = connection.cursor()
        except Exception, e:
            sys.stderr.write("Could not connect to Mysql: %s - %s" % \
                                                            (e, ipaddress))
            sys.exit(1)

        try:
            cursor.execute("SELECT VERSION() from %s WHERE import_cdr "\
                            "IS NOT NULL LIMIT 0,1" % table_name)
            row = cursor.fetchone()
        except Exception, e:
            #Add missing field to flag import
            cursor.execute("ALTER TABLE %s  ADD import_cdr TINYINT NOT NULL "\
                            "DEFAULT '0'" % table_name)
            cursor.execute("ALTER TABLE %s ADD INDEX (import_cdr)" % \
                            table_name)
Exemplo n.º 3
0
def diagnostic(request):
    """
    To run diagnostic test

    **Attributes**:

        * ``template`` - frontend/diagnostic.html
    """
    error_msg = ''
    info_msg = ''
    success_ip = []
    error_ip = []
    CDR_COUNT = 0
    backend_cdr_data = []
    #loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        #Connect to Database
        db_name = settings.CDR_BACKEND[ipaddress]['db_name']
        table_name = settings.CDR_BACKEND[ipaddress]['table_name']
        db_engine = settings.CDR_BACKEND[ipaddress]['db_engine']
        #cdr_type = settings.CDR_BACKEND[ipaddress]['cdr_type']
        host = settings.CDR_BACKEND[ipaddress]['host']
        port = settings.CDR_BACKEND[ipaddress]['port']
        user = settings.CDR_BACKEND[ipaddress]['user']
        password = settings.CDR_BACKEND[ipaddress]['password']

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        collection_data = {}

        #Connect on MongoDB Database
        try:
            if db_engine == 'mysql':
                import MySQLdb as Database
                connection = Database.connect(user=user, passwd=password,
                    db=db_name, host=host, port=port, connect_timeout=4)
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == 'pgsql':
                import psycopg2 as Database
                connection = Database.connect(user=user, passwd=password,
                    db=db_name, host=host, port=port)
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == 'mongodb':
                connection = Connection(host, port)
                DBCON = connection[db_name]
                CDR = DBCON[table_name]
                CDR_COUNT = CDR.find().count()

            if db_engine == 'mysql' or db_engine == 'pgsql':
                cursor.execute("SELECT count(*) FROM %s" % (table_name))
                row = cursor.fetchone()
                CDR_COUNT = row[0]

            success_ip.append(ipaddress)

            CDR_COMMON = settings.DBCON[settings.MONGO_CDRSTATS['CDR_COMMON']]
            DAILY_ANALYTIC = settings.DBCON[settings.MONGO_CDRSTATS['DAILY_ANALYTIC']]
            MONTHLY_ANALYTIC = settings.DBCON[settings.MONGO_CDRSTATS['MONTHLY_ANALYTIC']]
            CONC_CALL = settings.DBCON[settings.MONGO_CDRSTATS['CONC_CALL']]
            CONC_CALL_AGG = settings.DBCON[settings.MONGO_CDRSTATS['CONC_CALL_AGG']]

            collection_data = {
                'CDR_COMMON': CDR_COMMON.find().count(),
                'DAILY_ANALYTIC': DAILY_ANALYTIC.find().count(),
                'MONTHLY_ANALYTIC': MONTHLY_ANALYTIC.find().count(),
                'CONC_CALL': CONC_CALL.find().count(),
                'CONC_CALL_AGG': CONC_CALL_AGG.find().count()
            }
        except:
            CDR_COUNT = _('Error')
            error_ip.append(ipaddress)

        backend_cdr_data.append({
            'ip': ipaddress,
            'cdr_count': CDR_COUNT,
        })

    if success_ip:
        info_msg = _("CDR Backend %s connected successfully." % (str(success_ip)))

    if error_ip:
        error_msg = _("Please review the 'CDR_BACKEND' Settings in your file /usr/share/cdr-stats/settings_local.py make sure the settings, username, password are correct. Check also that the backend authorize a connection from your server")
        info_msg = _("After changes in your 'CDR_BACKEND' settings, you will need to restart celery: $ /etc/init.d/newfies-celeryd restart")

    data = {
        'backend_cdr_data': backend_cdr_data,
        'collection_data': collection_data,
        'settings': settings,
        'info_msg': info_msg,
        'error_msg': error_msg,
        'success_ip': success_ip,
        'error_ip': error_ip,
    }
    template = 'frontend/diagnostic.html'
    return render_to_response(template, data,
           context_instance=RequestContext(request))
Exemplo n.º 4
0
def import_cdr_asterisk(shell=False):
    #TODO : dont use the args here
    # Browse settings.CDR_BACKEND and for each IP
    # check if the IP exist in our Switch objects if it does we will
    # connect to that Database and import the data as we do below

    print_shell(shell, "Starting the synchronization...")

    if settings.CDR_BACKEND[settings.LOCAL_SWITCH_IP]['cdr_type'] != 'asterisk':
        print_shell(shell, "The switch is not configured to import Asterisk")
        return False

    #loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        db_engine = settings.CDR_BACKEND[ipaddress]['db_engine']
        if db_engine == 'mysql':
            import MySQLdb as Database
        elif db_engine == 'pgsql':
            import psycopg2 as Database
        else:
            sys.stderr.write("Wrong setting for db_engine: %s" %
                (str(db_engine)))
            sys.exit(1)

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        switch = data['switch']

        #Connect to Database
        db_name = settings.CDR_BACKEND[ipaddress]['db_name']
        table_name = settings.CDR_BACKEND[ipaddress]['table_name']
        user = settings.CDR_BACKEND[ipaddress]['user']
        password = settings.CDR_BACKEND[ipaddress]['password']
        host = settings.CDR_BACKEND[ipaddress]['host']
        port = settings.CDR_BACKEND[ipaddress]['port']
        try:
            connection = Database.connect(user=user, passwd=password,
                db=db_name, host=host, port=port)
            if db_engine == 'mysql':
                connection.autocommit(True)
            elif db_engine == 'pgsql':
                connection.autocommit = True
            cursor = connection.cursor()
            #update cursor used as we update at the end and we need
            #to fetch on 1st cursor
            cursor_updated = connection.cursor()
        except Exception, e:
            sys.stderr.write("Could not connect to Database: %s - %s" %
                (e, ipaddress))
            sys.exit(1)

        try:
            cursor.execute("SELECT VERSION() from %s WHERE import_cdr "
                "IS NOT NULL LIMIT 0,1" % table_name)
            row = cursor.fetchone()
        except Exception, e:
            #Add missing field to flag import
            cursor.execute("ALTER TABLE %s ADD import_cdr TINYINT NOT NULL "
                "DEFAULT '0'" % table_name)
            cursor.execute("ALTER TABLE %s ADD INDEX (import_cdr)" %
                table_name)
Exemplo n.º 5
0
def import_cdr_asterisk(shell=False):
    #TODO : dont use the args here
    # Browse settings.CDR_BACKEND and for each IP
    # check if the IP exist in our Switch objects if it does we will
    # connect to that Database and import the data as we do below

    print_shell(shell, "Starting the synchronization...")

    if settings.CDR_BACKEND[settings.LOCAL_SWITCH_IP]['cdr_type'] != 'asterisk':
        print_shell(shell, "The switch is not configured to import Asterisk")
        return False

    #loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        db_engine = settings.CDR_BACKEND[ipaddress]['db_engine']
        if db_engine == 'mysql':
            import MySQLdb as Database
        elif db_engine == 'pgsql':
            import psycopg2 as PgDatabase
        else:
            sys.stderr.write("Wrong setting for db_engine: %s" %
                (str(db_engine)))
            sys.exit(1)

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        switch = data['switch']

        #Connect to Database
        db_name = settings.CDR_BACKEND[ipaddress]['db_name']
        table_name = settings.CDR_BACKEND[ipaddress]['table_name']
        user = settings.CDR_BACKEND[ipaddress]['user']
        password = settings.CDR_BACKEND[ipaddress]['password']
        host = settings.CDR_BACKEND[ipaddress]['host']
        port = settings.CDR_BACKEND[ipaddress]['port']
        try:
            if db_engine == 'mysql':
                connection = Database.connect(user=user, passwd=password,
                    db=db_name, host=host, port=port)
                connection.autocommit(True)
            elif db_engine == 'pgsql':
                connection = PgDatabase.connect(user=user, password=password,
                    database=db_name, host=host, port=port)
                connection.autocommit = True
            cursor = connection.cursor()
            #update cursor used as we update at the end and we need
            #to fetch on 1st cursor
            cursor_updated = connection.cursor()
        except Exception, e:
            sys.stderr.write("Could not connect to Database: %s - %s" %
                (e, ipaddress))
            sys.exit(1)

        try:
            if db_engine == 'mysql':
                cursor.execute("SELECT VERSION() from %s WHERE import_cdr "
                    "IS NOT NULL LIMIT 0,1" % table_name)
            elif db_engine == 'pgsql':
                cursor.execute("SELECT VERSION() from %s WHERE import_cdr "
                    "IS NOT NULL LIMIT 1" % table_name)
            row = cursor.fetchone()
        except Exception, e:
            #Add missing field to flag import
            if db_engine == 'mysql':
                cursor.execute("ALTER TABLE %s ADD import_cdr TINYINT NOT NULL "
                    "DEFAULT '0'" % table_name)
            elif db_engine == 'pgsql':
                cursor.execute("ALTER TABLE %s ADD import_cdr SMALLINT NOT NULL "
                    "DEFAULT '0'" % table_name)
            cursor.execute("ALTER TABLE %s ADD INDEX (import_cdr)" %
                table_name)
Exemplo n.º 6
0
def diagnostic(request):
    """
    To run diagnostic test

    **Attributes**:

        * ``template`` - frontend/diagnostic.html
    """
    error_msg = ''
    info_msg = ''
    success_ip = []
    error_ip = []
    CDR_COUNT = 0
    backend_cdr_data = []
    #loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        #Connect to Database
        db_name = settings.CDR_BACKEND[ipaddress]['db_name']
        table_name = settings.CDR_BACKEND[ipaddress]['table_name']
        db_engine = settings.CDR_BACKEND[ipaddress]['db_engine']
        #cdr_type = settings.CDR_BACKEND[ipaddress]['cdr_type']
        host = settings.CDR_BACKEND[ipaddress]['host']
        port = settings.CDR_BACKEND[ipaddress]['port']
        user = settings.CDR_BACKEND[ipaddress]['user']
        password = settings.CDR_BACKEND[ipaddress]['password']

        data = chk_ipaddress(ipaddress)
        ipaddress = data['ipaddress']
        collection_data = {}

        #Connect on MongoDB Database
        try:
            if db_engine == 'mysql':
                import MySQLdb as Database
                connection = Database.connect(user=user,
                                              passwd=password,
                                              db=db_name,
                                              host=host,
                                              port=port,
                                              connect_timeout=4)
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == 'pgsql':
                import psycopg2 as Database
                connection = Database.connect(user=user,
                                              password=password,
                                              database=db_name,
                                              host=host,
                                              port=port)
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == 'mongodb':
                connection = Connection(host, port)
                DBCON = connection[db_name]
                CDR = DBCON[table_name]
                CDR_COUNT = CDR.find().count()

            if db_engine == 'mysql' or db_engine == 'pgsql':
                cursor.execute("SELECT count(*) FROM %s" % (table_name))
                row = cursor.fetchone()
                CDR_COUNT = row[0]

            success_ip.append(ipaddress)

            CDR_COMMON = settings.DBCON[settings.MONGO_CDRSTATS['CDR_COMMON']]
            DAILY_ANALYTIC = settings.DBCON[
                settings.MONGO_CDRSTATS['DAILY_ANALYTIC']]
            MONTHLY_ANALYTIC = settings.DBCON[
                settings.MONGO_CDRSTATS['MONTHLY_ANALYTIC']]
            CONC_CALL = settings.DBCON[settings.MONGO_CDRSTATS['CONC_CALL']]
            CONC_CALL_AGG = settings.DBCON[
                settings.MONGO_CDRSTATS['CONC_CALL_AGG']]

            collection_data = {
                'CDR_COMMON': CDR_COMMON.find().count(),
                'DAILY_ANALYTIC': DAILY_ANALYTIC.find().count(),
                'MONTHLY_ANALYTIC': MONTHLY_ANALYTIC.find().count(),
                'CONC_CALL': CONC_CALL.find().count(),
                'CONC_CALL_AGG': CONC_CALL_AGG.find().count()
            }
        except:
            CDR_COUNT = _('Error')
            error_ip.append(ipaddress)

        backend_cdr_data.append({
            'ip': ipaddress,
            'cdr_count': CDR_COUNT,
        })

    if success_ip:
        info_msg = _("CDR Backend %s connected successfully." %
                     (str(success_ip)))

    if error_ip:
        error_msg = _(
            "Please review the 'CDR_BACKEND' Settings in your file /usr/share/cdr-stats/settings_local.py make sure the settings, username, password are correct. Check also that the backend authorize a connection from your server"
        )
        info_msg = _(
            "After changes in your 'CDR_BACKEND' settings, you will need to restart celery: $ /etc/init.d/newfies-celeryd restart"
        )

    data = {
        'backend_cdr_data': backend_cdr_data,
        'collection_data': collection_data,
        'settings': settings,
        'info_msg': info_msg,
        'error_msg': error_msg,
        'success_ip': success_ip,
        'error_ip': error_ip,
    }
    template = 'frontend/diagnostic.html'
    return render_to_response(template,
                              data,
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
def diagnostic(request):
    """
    To run diagnostic test

    **Attributes**:

        * ``template`` - frontend/diagnostic.html
    """
    error_msg = ""
    info_msg = ""
    success_ip = []
    error_ip = []
    CDR_COUNT = 0
    backend_cdr_data = []
    # loop within the Mongo CDR Import List
    for ipaddress in settings.CDR_BACKEND:

        # Connect to Database
        db_name = settings.CDR_BACKEND[ipaddress]["db_name"]
        table_name = settings.CDR_BACKEND[ipaddress]["table_name"]
        db_engine = settings.CDR_BACKEND[ipaddress]["db_engine"]
        # cdr_type = settings.CDR_BACKEND[ipaddress]['cdr_type']
        host = settings.CDR_BACKEND[ipaddress]["host"]
        port = settings.CDR_BACKEND[ipaddress]["port"]
        user = settings.CDR_BACKEND[ipaddress]["user"]
        password = settings.CDR_BACKEND[ipaddress]["password"]

        data = chk_ipaddress(ipaddress)
        ipaddress = data["ipaddress"]
        collection_data = {}

        # Connect on MongoDB Database
        try:
            if db_engine == "mysql":
                import MySQLdb as Database

                connection = Database.connect(
                    user=user, passwd=password, db=db_name, host=host, port=port, connect_timeout=4
                )
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == "pgsql":
                import psycopg2 as Database

                connection = Database.connect(user=user, password=password, database=db_name, host=host, port=port)
                connection.autocommit(True)
                cursor = connection.cursor()
            elif db_engine == "mongodb":
                connection = Connection(host, port)
                DBCON = connection[db_name]
                CDR = DBCON[table_name]
                CDR_COUNT = CDR.find().count()

            if db_engine == "mysql" or db_engine == "pgsql":
                cursor.execute("SELECT count(*) FROM %s" % (table_name))
                row = cursor.fetchone()
                CDR_COUNT = row[0]

            success_ip.append(ipaddress)

            CDR_COMMON = settings.DBCON[settings.MONGO_CDRSTATS["CDR_COMMON"]]
            DAILY_ANALYTIC = settings.DBCON[settings.MONGO_CDRSTATS["DAILY_ANALYTIC"]]
            MONTHLY_ANALYTIC = settings.DBCON[settings.MONGO_CDRSTATS["MONTHLY_ANALYTIC"]]
            CONC_CALL = settings.DBCON[settings.MONGO_CDRSTATS["CONC_CALL"]]
            CONC_CALL_AGG = settings.DBCON[settings.MONGO_CDRSTATS["CONC_CALL_AGG"]]

            collection_data = {
                "CDR_COMMON": CDR_COMMON.find().count(),
                "DAILY_ANALYTIC": DAILY_ANALYTIC.find().count(),
                "MONTHLY_ANALYTIC": MONTHLY_ANALYTIC.find().count(),
                "CONC_CALL": CONC_CALL.find().count(),
                "CONC_CALL_AGG": CONC_CALL_AGG.find().count(),
            }
        except:
            CDR_COUNT = _("Error")
            error_ip.append(ipaddress)

        backend_cdr_data.append({"ip": ipaddress, "cdr_count": CDR_COUNT})

    if success_ip:
        info_msg = _("CDR Backend %s connected successfully." % (str(success_ip)))

    if error_ip:
        error_msg = _(
            "Please review the 'CDR_BACKEND' Settings in your file /usr/share/cdr-stats/settings_local.py make sure the settings, username, password are correct. Check also that the backend authorize a connection from your server"
        )
        info_msg = _(
            "After changes in your 'CDR_BACKEND' settings, you will need to restart celery: $ /etc/init.d/newfies-celeryd restart"
        )

    data = {
        "backend_cdr_data": backend_cdr_data,
        "collection_data": collection_data,
        "settings": settings,
        "info_msg": info_msg,
        "error_msg": error_msg,
        "success_ip": success_ip,
        "error_ip": error_ip,
    }
    template = "frontend/diagnostic.html"
    return render_to_response(template, data, context_instance=RequestContext(request))