diff --git a/pkg/dashboard/dashboard.go b/pkg/dashboard/dashboard.go index 482b4c60..b722fd20 100644 --- a/pkg/dashboard/dashboard.go +++ b/pkg/dashboard/dashboard.go @@ -1,3 +1,17 @@ +// Copyright 2019 ReactiveOps +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package dashboard import ( @@ -44,22 +58,13 @@ func MainHandler(w http.ResponseWriter, r *http.Request, c conf.Configuration, k JSON: template.JS(jsonData), } tmpl, err := template.New(TemplateName).Funcs(template.FuncMap{ - "getWarningWidth": func(rs validator.ResultSummary, fullWidth int) uint { - return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth)) - }, - "getSuccessWidth": func(rs validator.ResultSummary, fullWidth int) uint { - return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth)) - }, - "getIcon": func(rm validator.ResultMessage) string { - switch rm.Type { - case "success": - return "fas fa-check" - case "warning": - return "fas fa-exclamation" - default: - return "fas fa-times" - } - }, + "getWarningWidth": getWarningWidth, + "getSuccessWidth": getSuccessWidth, + "getWeatherIcon": getWeatherIcon, + "getWeatherText": getWeatherText, + "getGrade": getGrade, + "getScore": getScore, + "getIcon": getIcon, }).ParseFiles(TemplateFile) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/pkg/dashboard/helpers.go b/pkg/dashboard/helpers.go new file mode 100644 index 00000000..cc63317d --- /dev/null +++ b/pkg/dashboard/helpers.go @@ -0,0 +1,104 @@ +// Copyright 2019 ReactiveOps +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dashboard + +import ( + "github.com/reactiveops/fairwinds/pkg/validator" +) + +func getWarningWidth(rs validator.ResultSummary, fullWidth int) uint { + return uint(float64(rs.Successes+rs.Warnings) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth)) +} + +func getSuccessWidth(rs validator.ResultSummary, fullWidth int) uint { + return uint(float64(rs.Successes) / float64(rs.Successes+rs.Warnings+rs.Errors) * float64(fullWidth)) +} + +func getGrade(rs validator.ResultSummary) string { + score := getScore(rs) + if score >= 97 { + return "A+" + } else if score >= 93 { + return "A" + } else if score >= 90 { + return "A-" + } else if score >= 87 { + return "B+" + } else if score >= 83 { + return "B" + } else if score >= 80 { + return "B-" + } else if score >= 77 { + return "C+" + } else if score >= 73 { + return "C" + } else if score >= 70 { + return "C-" + } else if score >= 67 { + return "D+" + } else if score >= 63 { + return "D" + } else if score >= 60 { + return "D-" + } else { + return "F" + } +} + +func getScore(rs validator.ResultSummary) uint { + total := (rs.Successes * 2) + rs.Warnings + (rs.Errors * 2) + return uint((float64(rs.Successes*2) / float64(total)) * 100) +} + +func getWeatherIcon(rs validator.ResultSummary) string { + score := getScore(rs) + if score >= 90 { + return "fa-sun" + } else if score >= 80 { + return "fa-cloud-sun" + } else if score >= 70 { + return "fa-cloud" + } else if score >= 60 { + return "fa-cloud-rain" + } else { + return "fa-cloud-showers-heavy" + } +} + +func getWeatherText(rs validator.ResultSummary) string { + score := getScore(rs) + if score >= 90 { + return "Smooth sailing" + } else if score >= 80 { + return "Mostly smooth sailing" + } else if score >= 70 { + return "Smooth sailing within sight" + } else if score >= 60 { + return "A little stormy" + } else { + return "Storms ahead, be careful" + } +} + +func getIcon(rm validator.ResultMessage) string { + switch rm.Type { + case "success": + return "fas fa-check" + case "warning": + return "fas fa-exclamation" + default: + return "fas fa-times" + } +} diff --git a/pkg/dashboard/templates/dashboard.gohtml b/pkg/dashboard/templates/dashboard.gohtml index 2d2635b3..2d08ca1b 100644 --- a/pkg/dashboard/templates/dashboard.gohtml +++ b/pkg/dashboard/templates/dashboard.gohtml @@ -8,7 +8,7 @@ - + @@ -27,8 +27,8 @@
@@ -36,16 +36,22 @@
- Fairwinds
- |
- DaemonSet: datadog-agent
- |
-
-
-
-
-
-
-
-
- |
-
|
- Deployment: tiller-deployment
-
|
-
-
-
-
-
-
-
-
- |
-