1. Python / Говнокод #5257

    −81

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    import psycopg2
    from loki.libs.net.ipaddr import IPAddress
    import sys
    sys.path.append('../libs/')
    
    try:
        loki_db = psycopg2.connect (port="15432", host="noc2.t72.ru", database="loki_db", user="utkin", password="2UtaWEvaspuv")
        loki_cur = loki_db.cursor()
    except:
        print "Нет коннекта к локи_дб"
    
    try:
        cherry_db = psycopg2.connect (port="5432", host="noc2.72.ru", database="cherry", user="utkin", password="2UtaWEvaspuv")
        cherry_cur = cherry_db.cursor()
    except:
        print "Нет коннекта к черри_дб"
    
    loki_cur.execute("""
    select id, nas_id, service, ip_addr_id from inet_inetsessionactive;
    """);
    
    rows = loki_cur.fetchall()
    
    for (id, nas_id, service, ip_addr_id) in rows:
        loki_cur.execute("""select ip from inet_nasserver where id = %s;""",(nas_id,))
        try:
            nas_ip = loki_cur.fetchone()[0]
        except:
            print "Нет записи о NAS-сервере"
        loki_cur.execute("""select addr from inet_ouripall where id = %s;""",(ip_addr_id,))
    
        ip = str(IPAddress(int(loki_cur.fetchone()[0]))._ip)
    
        cherry_cur.execute("""select client_id, water_mark from inet_dynamic_ip_services where id = %s;""", (service,))
        try:
            (client_id, water_mark) = cherry_cur.fetchone()
        except:
            print "Нет записи в таблице inet_dynamic_ip_services: id, nas_id, service = (%s, %s, %s)"%(id, nas_id, service)
            
        cherry_cur.execute("""select balance from base_clients where client_id = %s;""",(client_id,));
        try:
            balance = cherry_cur.fetchone()[0]
            if balance <= water_mark:
                kill(ip, nas_ip)
        except:
            print "Нет записи в base_clients: client_id = %s"%client_id

    Запостил: tanenn, 13 Января 2011

    Комментарии (15) RSS

    Добавить комментарий