Commit a39e8c806fa8b07d58b7487bc606d7e265fab95f
Committed by
Eduardo Santos
Exists in
master
Conserta erro de impressora com o IP repetido
Showing
1 changed file
with
13 additions
and
3 deletions
Show diff stats
cocar/commands/scan_commands.py
... | ... | @@ -18,6 +18,7 @@ from ..csv_utils import NetworkCSV |
18 | 18 | from ..session import NmapSession, SnmpSession |
19 | 19 | from multiprocessing import Process, Queue |
20 | 20 | from ..xml_utils import NmapXML |
21 | +from sqlalchemy.exc import IntegrityError | |
21 | 22 | |
22 | 23 | log = logging.getLogger() |
23 | 24 | |
... | ... | @@ -197,7 +198,10 @@ class ScanCommands(command.Command): |
197 | 198 | results = session.query(Printer).filter(Printer.network_ip == hostname).first() |
198 | 199 | if results is None: |
199 | 200 | log.info("Inserindo impressora com o IP %s", hostname) |
200 | - session.add(host) | |
201 | + try: | |
202 | + session.add(host) | |
203 | + except IntegrityError, e: | |
204 | + log.error("Erro adicionando impressora com o IP %s. IP Repetido\n%s", hostname, e.message) | |
201 | 205 | else: |
202 | 206 | log.info("Impressora com o IP %s já cadastrada", hostname) |
203 | 207 | elif isinstance(host, Computer): |
... | ... | @@ -205,7 +209,10 @@ class ScanCommands(command.Command): |
205 | 209 | results = session.query(Computer).filter(Computer.network_ip == hostname).first() |
206 | 210 | if results is None: |
207 | 211 | log.info("Inserindo computador com o IP %s", hostname) |
208 | - session.add(host) | |
212 | + try: | |
213 | + session.add(host) | |
214 | + except IntegrityError, e: | |
215 | + log.error("Erro adicionando computador com o IP %s. IP Repetido\n%s", hostname, e.message) | |
209 | 216 | else: |
210 | 217 | log.info("Computador com o IP %s já cadastrado", hostname) |
211 | 218 | else: |
... | ... | @@ -213,7 +220,10 @@ class ScanCommands(command.Command): |
213 | 220 | results = session.query(Host).filter(Host.network_ip == hostname).first() |
214 | 221 | if results is None: |
215 | 222 | log.info("Inserindo host genérico com o IP %s", hostname) |
216 | - session.add(host) | |
223 | + try: | |
224 | + session.add(host) | |
225 | + except IntegrityError, e: | |
226 | + log.error("Erro adicionando host genérico com o IP %s. IP Repetido\n%s", hostname, e.message) | |
217 | 227 | else: |
218 | 228 | log.info("Host genérico com o IP %s já cadastrado", hostname) |
219 | 229 | ... | ... |