-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patherrores.py
67 lines (65 loc) · 2.31 KB
/
errores.py
1
2
3
4
5
6
7
8
9
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/local/Zope-2.6.2/bin/python
# Script que se patea la BD de rtg
# e inserta los errores en la tabla errores
# Modificación creada en newmetricas-pull-request-via-github
import MySQLdb
db= MySQLdb.connect(host="localhost",user="snmp",passwd="rtgdefault",db="rtg")
cursor = db.cursor()
cursor.execute("SELECT id,rid,name FROM interface")
result=cursor.fetchall()
for interface in result:
ifInErrors=0
ifOutErrors=0
ifInDiscards=0
ifOutDiscards=0
ifFECN=0
ifBECN=0
try:
cursor.execute("SELECT sum(counter) FROM ifInErrors_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifInErrors=errores[0]
except:
ifInErrors=0
try:
cursor.execute("SELECT sum(counter) FROM ifOutErrors_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifOutErrors=errores[0]
except:
ifOutErrors=0
try:
cursor.execute("SELECT sum(counter) FROM ifInDiscards_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifInDiscards=errores[0]
except:
ifInDiscards=0
try:
cursor.execute("SELECT sum(counter) FROM ifOutDiscards_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifOutDiscards=errores[0]
except:
ifOutDiscards=0
try:
cursor.execute("SELECT sum(counter) FROM frCircuitReceivedFECNs_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifFECN=errores[0]
except:
ifFECN=0
try:
cursor.execute("SELECT sum(counter) FROM frCircuitReceivedBECNs_%i where id=%i and substring(dtime,1,10)=CURDATE()" % (interface[1],interface[0]))
errores=cursor.fetchone()
if errores[0]:
ifBECN=errores[0]
except:
ifBECN=0
# Modificación creada en pull newmetricas-pull-request-via-github
if (ifInErrors+ifOutErrors+ifInDiscards+ifOutDiscards+ifBECN+ifFECN)>0:
# print interface[2],"-->",ifInErrors,ifOutErrors,ifInDiscards,ifOutDiscards
try:
cursor.execute("INSERT INTO errores VALUES (%i,CURDATE(),%i,%i,%i,%i,%i,%i)" % (interface[0],ifInErrors,ifOutErrors,ifInDiscards,ifOutDiscards,ifFECN,ifBECN))
except:
pass