- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 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