diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index ae1c5fc..97cf2a0 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -2,14 +2,20 @@
-
-
-
+
+
+
-
+
+
-
-
+
+
+
+
+
+
+
@@ -23,59 +29,59 @@
-
-
+
+
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
@@ -90,25 +96,22 @@
-
-
+
+
-
-
+
+
-
-
+
+
-
-
-
-
-
-
+
+
+
@@ -116,18 +119,18 @@
-
-
+
+
-
-
+
+
-
-
+
+
@@ -147,6 +150,8 @@
read_t
print
send_data
+ setup
+ add_
@@ -155,25 +160,29 @@
-
+
@@ -204,6 +213,11 @@
+
+
+
+
+
@@ -221,13 +235,14 @@
-
-
-
+
+
+
+
@@ -241,7 +256,7 @@
-
+
@@ -322,9 +337,9 @@
-
-
-
+
+
+
@@ -399,7 +414,14 @@
1514494342613
-
+
+ 1514671525222
+
+
+
+ 1514671525222
+
+
@@ -409,6 +431,7 @@
+
@@ -421,7 +444,6 @@
-
@@ -438,7 +460,8 @@
-
+
+
@@ -447,22 +470,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -484,11 +491,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -498,8 +505,7 @@
-
-
+
@@ -533,7 +539,7 @@
-
+
@@ -543,11 +549,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -557,8 +563,7 @@
-
-
+
@@ -584,11 +589,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -598,8 +603,7 @@
-
-
+
@@ -625,11 +629,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -639,8 +643,7 @@
-
-
+
@@ -666,11 +669,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -680,8 +683,7 @@
-
-
+
@@ -699,11 +701,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -713,8 +715,7 @@
-
-
+
@@ -724,11 +725,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -746,8 +747,7 @@
-
-
+
@@ -757,11 +757,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -779,8 +779,7 @@
-
-
+
@@ -790,11 +789,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -804,8 +803,7 @@
-
-
+
@@ -815,11 +813,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -829,11 +827,11 @@
-
-
-
-
-
+
+
+
+
+
@@ -852,42 +850,82 @@
-
+
-
-
+
+
-
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
-
+
-
-
+
+
-
+
-
+
+
+
+
+
+
+
+
+
@@ -900,66 +938,41 @@
-
+
-
-
-
-
-
+
+
+
-
+
-
-
-
-
-
-
+
+
+
-
+
-
-
+
+
-
-
-
-
-
+
-
-
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/SetupMinersClass.py b/SetupMinersClass.py
index 8ae41bf..a434ee5 100644
--- a/SetupMinersClass.py
+++ b/SetupMinersClass.py
@@ -32,7 +32,7 @@ class SSHSetup:
def send(self, command):
self.ssh.send(command + '\n')
time.sleep(1)
- print(self.ssh.recv(10000).decode())
+ self.ssh.recv(10000).decode()
def sendall(self, commlist=[]):
for command in commlist:
@@ -61,15 +61,15 @@ class TelnetSetup:
self.close()
def login(self):
- print(self.tn.read_until(b'login:'))
+ self.tn.read_until(b'login:')
self.tn.write(self.user.encode('utf8') + b'\n')
- print(self.tn.read_until(b'Password:'))
+ self.tn.read_until(b'Password:')
self.tn.write(self.passwd.encode('utf8') + b'\n')
self.tn.read_until(self.user.encode('utf8'))
def send(self, command):
self.tn.write(command.encode('utf8') + b'\n')
- print(self.tn.read_until(self.user.encode('utf8')).decode('utf8'))
+ self.tn.read_until(self.user.encode('utf8'))
def sendall(self, comlist=[]):
for command in comlist:
@@ -84,22 +84,27 @@ class SetupMiner:
self.host = host
self.conf = conf
if len(telnets) == 0:
- self.telnets = ["uname -a", "ps -A", "exit"]
+ self.telnets = ["exit"]
else:
self.telnets = telnets
if len(sshs) == 0:
- self.sshs = ["uname -a", "ps -A", "exit"]
+ self.sshs = ["exit"]
else:
self.sshs = sshs
try:
TelnetSetup(self.host, self.conf['telnetport'], self.conf['telnetuser'], self.conf['telnetpass'],
self.telnets)
+ self.result = "telnet OK; "
except Exception as exc:
- print(exc)
+ self.result = "{}; ".format(exc)
try:
SSHSetup(self.host, self.conf['sshport'], self.conf['sshuser'], conf['sshpass'], self.sshs)
+ self.result += '\n ssh OK'
except Exception as exc:
- raise exc
+ self.result += '\n {}; '.format(exc)
+
+ def ret_result(self):
+ return self.result
def read_conf():
@@ -117,10 +122,8 @@ def main():
"telnetpass": conf["telnetpass"],
"telnetport": conf["telnetport"]}
comlist = ["uname -a", "ps -A", "exit"]
- try:
- SetupMiner('10.100.0.48', minerconf)
- except Exception as exc:
- print(exc)
+ s = SetupMiner('10.100.4.10', minerconf)
+ print(s.result)
if __name__ == '__main__':
diff --git a/sshs.json b/commands/sshs.json
similarity index 100%
rename from sshs.json
rename to commands/sshs.json
diff --git a/telnets.json b/commands/telnets.json
similarity index 100%
rename from telnets.json
rename to commands/telnets.json
diff --git a/kea_host_wacher.py b/kea_host_wacher.py
index 5f03830..88bfdff 100644
--- a/kea_host_wacher.py
+++ b/kea_host_wacher.py
@@ -81,15 +81,12 @@ def main():
seen_list.append(seen_h['id_1c_import'])
for online_host in online_hosts:
if online_host['1c_id'] in seen_list:
- # print('need to update host 1c_id = %s' % online_host['1c_id'])
update_seen(qupdate_last_seen, online_host['1c_id'], *dbconf)
elif online_host not in seen:
- # print('need to add host 1c_id = %s' % online_host['1c_id'])
update_seen(qinsert_last_seen, online_host['1c_id'], *dbconf)
seen = read_table(qselect_last_seen, *dbconf)
for seen_host in seen:
if seen_host['datetime'] < (datetime.datetime.now() - datetime.timedelta(minutes=1)):
- # print('need to remove host 1c_id = %s' % seen_host['id_1c_import'])
update_hosts(qdelete_host, seen_host['id_1c_import'], *dbconf)
update_seen(qdelete_last_seen, seen_host['id_1c_import'], *dbconf)
diff --git a/kea_hosts_generane.py b/kea_hosts_generane.py
index 1a34a56..e48079e 100644
--- a/kea_hosts_generane.py
+++ b/kea_hosts_generane.py
@@ -2,8 +2,6 @@
# coding=utf-8
-import time
-import paramiko
import MySQLdb
import json
from SetupMinersClass import SetupMiner
@@ -48,6 +46,38 @@ qinsert_hosts = "START TRANSACTION; " \
qupdate_1c = "update 1c_import set imported = 1 where serial = '%s';"
+class ConfigClass:
+ def __init__(self):
+ self.conffile = 'config.json'
+ self.sshsfile = 'commands/sshs.json'
+ self.telnetsfile = 'commands/telnets.json'
+ self.config = list
+ self.minerconf = dict
+ self.dbconf = dict
+ self.sshs = list
+ self.telnets = list
+
+ def read_json(self, file):
+ with open(file) as f:
+ conf = json.load(f)
+ return conf
+
+ def readall(self):
+ conf = self.read_json(self.conffile)
+ self.sshs = self.read_json(self.sshsfile)
+ self.telnets = read_conf(self.telnetsfile)
+ self.minerconf = {"sshuser": conf["sshuser"],
+ "sshpass": conf["sshpass"],
+ "sshport": conf["sshport"],
+ "telnetuser": conf["telnetuser"],
+ "telnetpass": conf["telnetpass"],
+ "telnetport": conf["telnetport"]}
+ self.dbconf = {"dbhost": conf['dbhost'],
+ "dbuser": conf['dbuser'],
+ "dbpass": conf['dbpass'],
+ "dbbase": conf['dbbase']}
+
+
def read_table(sql, dbhost, dbuser, dbpass, dbbase):
try:
conn = MySQLdb.connect(host=dbhost, user=dbuser,
@@ -124,11 +154,8 @@ def read_conf(file):
def main():
conf = read_conf('config.json')
- sshs = read_conf('sshs.json')
- telnets = read_conf('telnets.json')
- print(sshs)
- print(telnets)
- telnets = read_conf('telnets.json')
+ sshs = read_conf('commands/sshs.json')
+ telnets = read_conf('commands/telnets.json')
minerconf = {"sshuser": conf["sshuser"],
"sshpass": conf["sshpass"],
"sshport": conf["sshport"],
diff --git a/tpl/a_add_hosts.tpl b/tpl/a_add_hosts.tpl
new file mode 100644
index 0000000..ec144bb
--- /dev/null
+++ b/tpl/a_add_hosts.tpl
@@ -0,0 +1,16 @@
+
+
+ DHCP web-viewer
+
+
+
+Таблица импорта обновлена.
+Если устройства не перезагружены автоматически, это необходимо сделать вручную.
+Лог действий:
+%for a in A:
+{{a}}
+
+%end
+Назад
+
+
\ No newline at end of file
diff --git a/tpl/add_hosts.tpl b/tpl/add_hosts.tpl
new file mode 100644
index 0000000..a4ab7b5
--- /dev/null
+++ b/tpl/add_hosts.tpl
@@ -0,0 +1,40 @@
+
+
+ DHCP web-viewer
+
+
+
+ отчет по хостам в статическом адресном пространстве
+ отчет по занятым хостам в динамическом адресном пространстве
+ Добавление хостов
+
+
+
+
diff --git a/tpl/hosts.tpl b/tpl/hosts.tpl
index ce14040..5a64173 100644
--- a/tpl/hosts.tpl
+++ b/tpl/hosts.tpl
@@ -7,7 +7,7 @@
отчет по занятым хостам в динамическом адресном пространстве
Статические адреса
-