Skip to content

Commit

Permalink
Reverted optimizations because they caused the program not to work pr…
Browse files Browse the repository at this point in the history
…operly.
  • Loading branch information
PatMis16 committed Apr 22, 2021
1 parent 27cff0f commit f5008f6
Showing 1 changed file with 8 additions and 31 deletions.
39 changes: 8 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prometheus/client_golang/prometheus/promhttp"
"gopkg.in/yaml.v2"
"io"
"io/ioutil"
"log"
"math/rand"
Expand Down Expand Up @@ -56,12 +55,7 @@ func NewConfig(configPath string) (*Config, error) {
if err != nil {
return nil, err
}
defer func(file *os.File) {
err := file.Close()
if err != nil {

}
}(file)
defer file.Close()

d := yaml.NewDecoder(file)

Expand Down Expand Up @@ -107,8 +101,8 @@ type TSEventAttributes struct {
McObjectURI string `json:"mc_object_uri"`
}

func NewTSEventAttributes(CLASS string, severity string, msg string, mcObjectClass string, mcObject string, mcParameter string, mcObjectUri string) *TSEventAttributes {
return &TSEventAttributes{CLASS: CLASS, Severity: severity, Msg: msg, McObjectClass: mcObjectClass, McObject: mcObject, McParameter: mcParameter, McObjectURI: mcObjectUri}
func NewTSEventAttributes(CLASS string, severity string, msg string, mc_object_class string, mc_object string, mc_parameter string, mc_object_uri string) *TSEventAttributes {
return &TSEventAttributes{CLASS: CLASS, Severity: severity, Msg: msg, McObjectClass: mc_object_class, McObject: mc_object, McParameter: mc_parameter, McObjectURI: mc_object_uri}
}

type TSEvent struct {
Expand Down Expand Up @@ -231,16 +225,10 @@ func (config Config) Run() {
if events != nil {
if SendEventToTS(tsToken.getToken(), config.Server.TrueSight.TSIMServer, config.Server.TrueSight.TSIMPort, config.Server.TrueSight.TSCell, events) {
InfoLogger.Println("Event sent to TrueSight.")
_, err := fmt.Fprintf(w, "Event(s) created")
if err != nil {
return
}
fmt.Fprintf(w, "Event(s) created")
} else {
WarningLogger.Println("Failed to send event(s) to TrueSight.")
err := promAlertsCache.Add(RandomString(10), events, cache.DefaultExpiration)
if err != nil {
return
}
promAlertsCache.Add(RandomString(10), events, cache.DefaultExpiration)
http.Error(w, "Something went wrong on the server!", http.StatusInternalServerError)
}
}
Expand Down Expand Up @@ -273,10 +261,7 @@ func GetTSToken(tspsServer string, tspsPort string, tsUser string, tsUserPw stri
rawData, _ := ioutil.ReadAll(resp.Body)
InfoLogger.Println("Get TS auth token response: ", rawData)
var data map[string]map[string]interface{}
err := json.Unmarshal(rawData, &data)
if err != nil {
return ""
}
json.Unmarshal(rawData, &data)
authToken = data["response"]["authToken"].(string)
break
}
Expand All @@ -302,12 +287,7 @@ func VerifyTSToken(token string, tspsServer string, tspsPort string) bool {
if err != nil {
log.Fatal("Unable to perform request: ", err)
} else {
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {

}
}(resp.Body)
defer resp.Body.Close()
rawData, _ := ioutil.ReadAll(resp.Body)
var data map[string]interface{}
if err := json.Unmarshal(rawData, &data); err != nil {
Expand Down Expand Up @@ -418,10 +398,7 @@ func main() {
fmt.Println("starting heartbeat")
go Heartbeat()
http.Handle("/metrics", promhttp.Handler())
err = http.ListenAndServe(":"+cfg.Server.PromMetricPort, nil)
if err != nil {
return
}
http.ListenAndServe(":"+cfg.Server.PromMetricPort, nil)
time.Sleep(1 * time.Second)

}

0 comments on commit f5008f6

Please sign in to comment.