Close #159: Add the ability to hide the hostname of a service

This commit is contained in:
TwinProduction 2021-09-02 22:26:08 -04:00 committed by Chris
parent becc17202b
commit 9c99cc522d
7 changed files with 33 additions and 7 deletions

View File

@ -165,6 +165,8 @@ If you want to test it locally, see [Docker](#docker).
| `services[].alerts[].send-on-resolved` | Whether to send a notification once a triggered alert is marked as resolved. | `false` |
| `services[].alerts[].description` | Description of the alert. Will be included in the alert sent. | `""` |
| `services[].client` | Client configuration. <br />See [Client configuration](#client-configuration). | `{}` |
| `services[].ui` | UI configuration. | `{}` |
| `services[].ui.hide-hostname` | Whether to include the hostname in the result. | `false` |
| `alerting` | Configuration for alerting. <br />See [Alerting](#alerting). | `{}` |
| `security` | Security configuration. | `{}` |
| `security.basic` | Basic authentication security configuration. | `{}` |

View File

@ -15,6 +15,7 @@ import (
"github.com/TwinProduction/gatus/alerting/alert"
"github.com/TwinProduction/gatus/client"
"github.com/TwinProduction/gatus/core/ui"
"github.com/TwinProduction/gatus/util"
)
@ -86,6 +87,9 @@ type Service struct {
// ClientConfig is the configuration of the client used to communicate with the service's target
ClientConfig *client.Config `yaml:"client"`
// UIConfig is the configuration for the UI
UIConfig *ui.Config `yaml:"ui"`
// NumberOfFailuresInARow is the number of unsuccessful evaluations in a row
NumberOfFailuresInARow int
@ -106,6 +110,9 @@ func (service *Service) ValidateAndSetDefaults() error {
} else {
service.ClientConfig.ValidateAndSetDefaults()
}
if service.UIConfig == nil {
service.UIConfig = ui.GetDefaultConfig()
}
if service.Interval == 0 {
service.Interval = 1 * time.Minute
}
@ -175,6 +182,10 @@ func (service *Service) EvaluateHealth() *Result {
result.Timestamp = time.Now()
// No need to keep the body after the service has been evaluated
result.body = nil
// Clean up parameters that we don't need to keep in the results
if service.UIConfig.HideHostname {
result.Hostname = ""
}
return result
}

13
core/ui/ui.go Normal file
View File

@ -0,0 +1,13 @@
package ui
// Config is the UI configuration for services
type Config struct {
HideHostname bool `yaml:"hide-hostname"` // Whether to hide the hostname in the Result
}
// GetDefaultConfig retrieves the default UI configuration
func GetDefaultConfig() *Config {
return &Config{
HideHostname: false,
}
}

View File

@ -5,7 +5,7 @@
<router-link :to="generatePath()" class="font-bold hover:text-blue-800 hover:underline dark:hover:text-blue-400" title="View detailed service health">
{{ data.name }}
</router-link>
<span v-if="data.results && data.results.length" class='text-gray-500 font-light'> | {{ data.results[data.results.length - 1].hostname }}</span>
<span v-if="data.results && data.results.length && data.results[data.results.length - 1].hostname" class='text-gray-500 font-light'> | {{ data.results[data.results.length - 1].hostname }}</span>
</div>
<div class='w-1/4 text-right'>
<span class='font-light overflow-x-hidden cursor-pointer select-none' v-if="data.results && data.results.length" @click="toggleShowAverageResponseTime" :title="showAverageResponseTime ? 'Average response time' : 'Minimum and maximum response time'">

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long