diff --git a/features/stats.go b/features/stats.go index b964270..aed4f60 100644 --- a/features/stats.go +++ b/features/stats.go @@ -205,10 +205,10 @@ func (s *Stats) Write(field string, count uint64) { if err != nil { log.Warn(err) } - if resp.StatusCode != 200 { + if resp != nil && resp.StatusCode != 200 { log.Warnf("Recieved %d status code from Splunk", resp.StatusCode) + defer resp.Body.Close() } - defer resp.Body.Close() }(splunkstats) } // Update stats DB diff --git a/notifications/splunkhec.go b/notifications/splunkhec.go index 2c3e69e..60a67c2 100644 --- a/notifications/splunkhec.go +++ b/notifications/splunkhec.go @@ -72,10 +72,10 @@ func (d SplunkHEC) Notify(title string, description string, notifType string, pa if err != nil { log.Warn(err) } - if resp.StatusCode != 200 { + if resp != nil && resp.StatusCode != 200 { log.Warnf("Recieved %d status code from Splunk", resp.StatusCode) + defer resp.Body.Close() } - defer resp.Body.Close() }(splunkevent) return true }