mirror of
https://github.com/Luzifer/mondash.git
synced 2024-11-10 00:20:02 +00:00
Some small bugfixes and imporovements
+ More speaking errors + Use validation for data from input + Prevent NaN errors + Use correct initialization for objects
This commit is contained in:
parent
07a0f8ba79
commit
5773189317
2 changed files with 15 additions and 6 deletions
8
main.go
8
main.go
|
@ -113,6 +113,12 @@ func main() {
|
|||
return
|
||||
}
|
||||
|
||||
valid, reason := metricUpdate.IsValid()
|
||||
if !valid {
|
||||
http.Error(res, fmt.Sprintf("Invalid data: %s", reason), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
updated := false
|
||||
for _, m := range dash.Metrics {
|
||||
if m.MetricID == params["metricid"] {
|
||||
|
@ -123,7 +129,7 @@ func main() {
|
|||
}
|
||||
|
||||
if !updated {
|
||||
tmp := &DashboardMetric{MetricID: params["metricid"]}
|
||||
tmp := NewDashboardMetric()
|
||||
tmp.Update(metricUpdate)
|
||||
dash.Metrics = append(dash.Metrics, tmp)
|
||||
}
|
||||
|
|
13
structs.go
13
structs.go
|
@ -30,11 +30,12 @@ func LoadDashboard(dashid string) (*Dashboard, error) {
|
|||
func (d *Dashboard) Save() {
|
||||
data, err := json.Marshal(d)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error while marshalling dashboard: %s", err)
|
||||
return
|
||||
}
|
||||
err = s3Storage.Put(d.DashboardID, data, "application/json", s3.Private)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
log.Printf("Error while storing dashboard: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -114,9 +115,11 @@ func (dm *DashboardMetric) Update(m *DashboardMetric) {
|
|||
dm.HistoricalData = tmp
|
||||
|
||||
dm.Meta.LastUpdate = time.Now()
|
||||
dm.Meta.PercCrit = countStatus["Critical"] / countStatus["Total"] * 100
|
||||
dm.Meta.PercWarn = countStatus["Warning"] / countStatus["Total"] * 100
|
||||
dm.Meta.PercOK = countStatus["OK"] / countStatus["Total"] * 100
|
||||
if countStatus["Total"] > 0 {
|
||||
dm.Meta.PercCrit = countStatus["Critical"] / countStatus["Total"] * 100
|
||||
dm.Meta.PercWarn = countStatus["Warning"] / countStatus["Total"] * 100
|
||||
dm.Meta.PercOK = countStatus["OK"] / countStatus["Total"] * 100
|
||||
}
|
||||
}
|
||||
|
||||
func (dm *DashboardMetric) IsValid() (bool, string) {
|
||||
|
|
Loading…
Reference in a new issue