-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelaboroRequest.go
89 lines (73 loc) · 2.19 KB
/
elaboroRequest.go
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package main
import (
"context"
"fmt"
"log"
"time"
)
var sigma = configuration.Sigma
var eventi Jerks
func elaboroRequest(ctx context.Context, result []interface{}, device string) {
serieppptime, seriepppvalue := estraiSerie(result)
// Se non ci sono abbastanza valori per la serie esce
if len(seriepppvalue) < 300 {
log.Printf(
"Error %s Non ci sono abbastanza dati per elaborare statistiche\n",
device)
return
}
mean, stdev, xdet, y := elaboraSerie(serieppptime, seriepppvalue)
for i := 10; i < len(y); i++ {
// Individuo se è avvenuto un Jerk
if y[i] < mean-sigma*stdev {
unixtimeUTC := time.Unix(int64(xdet[i]/1000), 0)
// Serve per avere il timestamp di quando c'è stato il problema
unixtimeinRFC3339 := unixtimeUTC.Format(time.RFC3339)
// Devo verificare quali dopo il Jerk hanno avuto problemi
numvalori := len(seriepppvalue)
for l := 0; l <= 6; l++ {
// Evita che si arrivi alla fine della serie di valori
if i+l > numvalori-1 {
break
}
// Verifica i valori dopo il jerk
limite :=
(seriepppvalue[i] - seriepppvalue[i+l]) / seriepppvalue[i]
// Se il limite è negativo non ci interessa
if limite < 0 {
continue
}
if limite > configuration.Soglia {
summary :=
fmt.Sprintf(
"abbassamento sessioni ppp superiore al %2.0f%%\n",
configuration.Soglia*100)
// Attenzione NON usare log.Print perchè serve printare il
// timestamp non attuale ma di quando si è verificato
// il problema
fmt.Printf("%s Alert %s, %s\n", unixtimeinRFC3339,
device, summary)
evento := new(Jerk)
evento.NasName = device
evento.pppValue = seriepppvalue[i]
evento.Timestamp = unixtimeUTC
eventi = append(eventi, *evento)
// Mandamail di notifica solo se siamo negli ultimi
// 6 valori
if i > (numvalori - 6) {
mandamailAlert(configuration.SmtpFrom,
configuration.SmtpTo,
device, evento)
err := CreaTrap(device, "sessioni ppp", summary,
listanasip[device], 1, 5)
if err != nil {
log.Printf(
"Error %s Impossibile inviare trap\n", device)
}
nastrappati[device] = true
}
}
}
}
}
}