Example #1
0
def main(argv):

    if os.name == 'nt':
        cfgpath = os.path.expandvars('%APPDATA%\IPhistdb')
    elif os.name == 'posix':
        cfgpath = '/etc/IPhistdb'

    cfg = Config(os.path.join(cfgpath, 'processcnr.ini'))

    logging.config.fileConfig(os.path.join(cfgpath, 'processcnr.logging.ini'))
    logger = logging.getLogger('file')

    logger.debug('INIT')

    try:
        lock(cfg.getpath('App', 'lockfile'))

        try:

            db = AggDB()
            db.connect(cfg.get('AggDB', 'host'),
                       cfg.get('AggDB', 'user'),
                       cfg.get('AggDB', 'pass'),
                       cfg.get('AggDB', 'db'))

            iphist = Iphist(cfg.get('CNR', 'iphist'),
                            cfg.get('CNR', 'user'),
                            cfg.get('CNR', 'pass'))

            for lease in iphist.leases('all'):
                try:
                    db.addlease(lease)
                    logger.debug(' '.join(['addlease',
                                           lease.ip,
                                           lease.start.strftime('%Y-%m-%d %H:%M:%S'),
                                           lease.end.strftime('%Y-%m-%d %H:%M:%S')]))
                except ParseException as e:
                    logger.warning(e)

            nrcmd = Nrcmd(cfg.get('CNR', 'nrcmd'),
                          cfg.get('CNR', 'user'),
                          cfg.get('CNR', 'pass'))

            nrcmd.dhcp_trimIPHistory(cfg.get('CNR', 'keep_history_days'))
            logger.debug('dhcp trimIPhistory')
            nrcmd.dhcp_reload()
            logger.debug('dhcp reload')

        finally:
            unlock(cfg.getpath('App', 'lockfile'))
    except:
        e = sys.exc_info()[1]
        sendmail(cfg.get('SMTP', 'smtp'),
                 cfg.get('SMTP', 'from'),
                 cfg.get('SMTP', 'to'),
                 'CNR iphistory importer errors',
                 str(e))
        raise

    logger.debug('DONE')
Example #2
0
def main(argv):
    hdb = HistDB()
    adb = AggDB()
    cfg = ConfigParser()

    cfg.read(hconfig_filename)

    hdb.connect(cfg.get("MySQL", "host"),
                cfg.get("MySQL", "user"),
                cfg.get("MySQL", "pass"),
                cfg.get("MySQL", "db"))

    cfg.read(aconfig_filename)
    adb.connect(cfg.get("MySQL", "host"),
                cfg.get("MySQL", "user"),
                cfg.get("MySQL", "pass"),
                cfg.get("MySQL", "db"))

    logging.config.fileConfig(config_logging_filename)
    logger = logging.getLogger("file")

    # All history:
    for item in hdb.aggregate_history():
        adb.addlease(item)
        if item.complete:
            hdb.del_history_records(item.rows)
            logger.debug(str(item.rows) + " IDs deleted from history")

    nr = adb.cleanup(cfg.get("Maintenance", "record_keep_days"))
    logger.info(str(nr) + " leases deleted from aggregated")
Example #3
0
def main(argv):
    db = AggDB()
    cfg = ConfigParser()

    cfg.read(config_filename)

    db.connect(cfg.get("MySQL", "host"),
               cfg.get("MySQL", "user"),
               cfg.get("MySQL", "pass"),
               cfg.get("MySQL", "db"))

    target_date = datetime.strptime(argv[1], "%Y-%m-%d %H:%M:%S")

    print fmt.format("IP", "MAC", "Start", "End", "Circuit-ID",
                     "Remote-ID", "giaddr")

    for item in db.lookup_by_ip(argv[0], target_date):

        print fmt.format(item["ip"], item["mac"],
                         item["start"],
                         item["end"],
                         item["circuit_id"],
                         item["remote_id"],
                         item["giaddr"])
Example #4
0
def mac(request, mac):

    adb = AggDB()
    adb.lookup_tz = requested_tz(request)
    adb.connect(settings.APIV1_AGGDB_HOST,
                settings.APIV1_AGGDB_USER,
                settings.APIV1_AGGDB_PASS,
                settings.APIV1_AGGDB_DB)

    body = []

    for item in adb.lookup_by_mac(mac):
        body.append(item)

    adb.close()

    return HttpResponse(json.dumps(body, encoding="latin_1"), mimetype="application/json")
Example #5
0
def ipbydate(request, ip, date):
    adb = AggDB()
    adb.lookup_tz = requested_tz(request)
    adb.connect(settings.APIV1_AGGDB_HOST,
                settings.APIV1_AGGDB_USER,
                settings.APIV1_AGGDB_PASS,
                settings.APIV1_AGGDB_DB)

    body = []

    dt = datetime.datetime.strptime(date, "%Y-%m-%d %H:%M:%S")
    for item in adb.lookup_by_ip(ip, dt):
        body.append(item)

    adb.close()

    return HttpResponse(json.dumps(body, encoding="latin_1"), mimetype="application/json")