Skip to content

Commit

Permalink
Add additional logging (#18)
Browse files Browse the repository at this point in the history
Should help us debug unnamed ikeSAs and all the connects and disconnects that
our metrics indicate.
  • Loading branch information
Crevil authored Feb 12, 2020
1 parent c2b8195 commit 59e55ea
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 7 additions & 2 deletions internal/strongswan/strongswan.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,25 @@ func collectSasStats(configs []map[string]vici.IKEConf, sas []map[string]vici.Ik
}
}

log.Infof("Sas: %d", len(sas))
for _, sa := range sas {
for ikeName, ikeSa := range sa {
conf, ok := expectedConnections[ikeName]
if !ok {
log.Errorf("Unexpected SA: %s: %#v", ikeName, ikeSa)
continue
}
log.Infof(" ikeName: %s: sa: %#v", ikeName, ikeSa)
log.With("conf", conf).
With("sa", ikeSa).
With("ikeName", ikeName).
Infof("Reporting on ike name '%s'", ikeName)
reporter.IKESAStatus(ikeName, conf, &ikeSa)
delete(expectedConnections, ikeName)
}
}
for ikeName, conf := range expectedConnections {
log.With("conf", conf).
With("ikeName", ikeName).
Infof("Reporting config without active SAs on '%s'", ikeName)
reporter.IKESAStatus(ikeName, conf, nil)
}
}
8 changes: 4 additions & 4 deletions internal/tcpchecker/logreporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@ type logReporter struct {
}

func (r *logReporter) ReportPortCheck(report Report) {
l := r.Logger.With("report", report)
switch {
case report.Open && r.lastOpen:
// Port is still open - great
case !report.Open && (r.lastOpen || r.lastReport == time.Time{}):
// Port closed
r.lastReport = time.Now()
r.lastOpen = report.Open
r.Logger.
l.
With("status", "closed").
Infof("TCP connection to %s closed", report.Name)
case report.Open && !r.lastOpen:
// Port opened
r.lastReport = time.Now()
r.lastOpen = report.Open
r.Logger.
l.
With("status", "opened").
With("content", report.Content).
Infof("TCP connection to %s opened", report.Name)
case !report.Open && !r.lastOpen:
// Port still closed
if time.Since(r.lastReport) > 5*time.Minute {
r.lastReport = time.Now()
r.lastOpen = report.Open
r.Logger.
l.
With("status", "closed").
Infof("TCP connection to %s is still closed", report.Name)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/tcpchecker/tcpchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Check(name string, address string, port int, reporter Reporter) {
Address: address,
Port: port,
Open: true,
Status: "Open",
Status: "Open (closed by us)",
Error: nil,
Content: output.String(),
})
Expand All @@ -75,7 +75,7 @@ func Check(name string, address string, port int, reporter Reporter) {
Address: address,
Port: port,
Open: true,
Status: "Open",
Status: "Open (closed by peer)",
Error: nil,
Content: output.String(),
})
Expand Down

0 comments on commit 59e55ea

Please sign in to comment.