Merge pull request #423 from TheTincho/Remove_yaml-js_dependency

Remove yaml js dependency
This commit is contained in:
Fabian Reinartz 2016-07-13 17:05:36 +02:00 committed by GitHub
commit 862cf71637
8 changed files with 148 additions and 164 deletions

17
api.go
View File

@ -28,6 +28,7 @@ import (
"github.com/prometheus/common/version"
"golang.org/x/net/context"
"github.com/prometheus/alertmanager/config"
"github.com/prometheus/alertmanager/provider"
"github.com/prometheus/alertmanager/types"
)
@ -56,6 +57,7 @@ type API struct {
alerts provider.Alerts
silences provider.Silences
config string
configJSON config.Config
resolveTimeout time.Duration
uptime time.Time
@ -101,12 +103,18 @@ func (api *API) Register(r *route.Router) {
}
// Update sets the configuration string to a new value.
func (api *API) Update(config string, resolveTimeout time.Duration) {
func (api *API) Update(cfg string, resolveTimeout time.Duration) {
api.mtx.Lock()
defer api.mtx.Unlock()
api.config = config
api.config = cfg
api.resolveTimeout = resolveTimeout
configJSON, err := config.Load(cfg)
if err != nil {
log.Errorf("error: %v", err)
}
api.configJSON = *configJSON
}
type errorType string
@ -131,10 +139,12 @@ func (api *API) status(w http.ResponseWriter, req *http.Request) {
var status = struct {
Config string `json:"config"`
ConfigJSON config.Config `json:"configJSON"`
VersionInfo map[string]string `json:"versionInfo"`
Uptime time.Time `json:"uptime"`
}{
Config: api.config,
Config: api.config,
ConfigJSON: api.configJSON,
VersionInfo: map[string]string{
"version": version.Version,
"revision": version.Revision,
@ -397,6 +407,7 @@ func respond(w http.ResponseWriter, data interface{}) {
Data: data,
})
if err != nil {
log.Errorf("errorr: %v", err)
return
}
w.Write(b)

View File

@ -86,14 +86,14 @@ func resolveFilepaths(baseDir string, cfg *Config) {
// Config is the top-level configuration for Alertmanager's config files.
type Config struct {
Global *GlobalConfig `yaml:"global,omitempty"`
Route *Route `yaml:"route,omitempty"`
InhibitRules []*InhibitRule `yaml:"inhibit_rules,omitempty"`
Receivers []*Receiver `yaml:"receivers,omitempty"`
Templates []string `yaml:"templates"`
Global *GlobalConfig `yaml:"global,omitempty" json:"global,omitempty"`
Route *Route `yaml:"route,omitempty" json:"route,omitempty"`
InhibitRules []*InhibitRule `yaml:"inhibit_rules,omitempty" json:"inhibit_rules,omitempty"`
Receivers []*Receiver `yaml:"receivers,omitempty" json:"receivers,omitempty"`
Templates []string `yaml:"templates" json:"templates"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
// original is the input from which the config was parsed.
original string
@ -271,19 +271,19 @@ var DefaultGlobalConfig = GlobalConfig{
type GlobalConfig struct {
// ResolveTimeout is the time after which an alert is declared resolved
// if it has not been updated.
ResolveTimeout model.Duration `yaml:"resolve_timeout"`
ResolveTimeout model.Duration `yaml:"resolve_timeout" json:"resolve_timeout"`
SMTPFrom string `yaml:"smtp_from"`
SMTPSmarthost string `yaml:"smtp_smarthost"`
SMTPAuthUsername string `yaml:"smtp_auth_username"`
SMTPAuthPassword Secret `yaml:"smtp_auth_password"`
SMTPAuthSecret Secret `yaml:"smtp_auth_secret"`
SMTPAuthIdentity string `yaml:"smtp_auth_identity"`
SlackAPIURL Secret `yaml:"slack_api_url"`
PagerdutyURL string `yaml:"pagerduty_url"`
HipchatURL string `yaml:"hipchat_url"`
HipchatAuthToken Secret `yaml:"hipchat_auth_token"`
OpsGenieAPIHost string `yaml:"opsgenie_api_host"`
SMTPFrom string `yaml:"smtp_from" json:"smtp_from"`
SMTPSmarthost string `yaml:"smtp_smarthost" json:"smtp_smarthost"`
SMTPAuthUsername string `yaml:"smtp_auth_username" json:"smtp_auth_username"`
SMTPAuthPassword Secret `yaml:"smtp_auth_password" json:"smtp_auth_password"`
SMTPAuthSecret Secret `yaml:"smtp_auth_secret" json:"smtp_auth_secret"`
SMTPAuthIdentity string `yaml:"smtp_auth_identity" json:"smtp_auth_identity"`
SlackAPIURL Secret `yaml:"slack_api_url" json:"slack_api_url"`
PagerdutyURL string `yaml:"pagerduty_url" json:"pagerduty_url"`
HipchatURL string `yaml:"hipchat_url" json:"hipchat_url"`
HipchatAuthToken Secret `yaml:"hipchat_auth_token" json:"hipchat_auth_token"`
OpsGenieAPIHost string `yaml:"opsgenie_api_host" json:"opsgenie_api_host"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -295,20 +295,20 @@ func (c *GlobalConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// A Route is a node that contains definitions of how to handle alerts.
type Route struct {
Receiver string `yaml:"receiver,omitempty"`
GroupBy []model.LabelName `yaml:"group_by,omitempty"`
Receiver string `yaml:"receiver,omitempty" json:"receiver,omitempty"`
GroupBy []model.LabelName `yaml:"group_by,omitempty" json:"group_by,omitempty"`
Match map[string]string `yaml:"match,omitempty"`
MatchRE map[string]Regexp `yaml:"match_re,omitempty"`
Continue bool `yaml:"continue,omitempty"`
Routes []*Route `yaml:"routes,omitempty"`
Match map[string]string `yaml:"match,omitempty" json:"match,omitempty"`
MatchRE map[string]Regexp `yaml:"match_re,omitempty" json:"match_re,omitempty"`
Continue bool `yaml:"continue,omitempty" json:"continue,omitempty"`
Routes []*Route `yaml:"routes,omitempty" json:"routes,omitempty"`
GroupWait *model.Duration `yaml:"group_wait,omitempty"`
GroupInterval *model.Duration `yaml:"group_interval,omitempty"`
RepeatInterval *model.Duration `yaml:"repeat_interval,omitempty"`
GroupWait *model.Duration `yaml:"group_wait,omitempty" json:"group_wait,omitempty"`
GroupInterval *model.Duration `yaml:"group_interval,omitempty" json:"group_interval,omitempty"`
RepeatInterval *model.Duration `yaml:"repeat_interval,omitempty" json:"repeat_interval,omitempty"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -348,22 +348,22 @@ func (r *Route) UnmarshalYAML(unmarshal func(interface{}) error) error {
type InhibitRule struct {
// SourceMatch defines a set of labels that have to equal the given
// value for source alerts.
SourceMatch map[string]string `yaml:"source_match"`
SourceMatch map[string]string `yaml:"source_match" json:"source_match"`
// SourceMatchRE defines pairs like SourceMatch but does regular expression
// matching.
SourceMatchRE map[string]Regexp `yaml:"source_match_re"`
SourceMatchRE map[string]Regexp `yaml:"source_match_re" json:"source_match_re"`
// TargetMatch defines a set of labels that have to equal the given
// value for target alerts.
TargetMatch map[string]string `yaml:"target_match"`
TargetMatch map[string]string `yaml:"target_match" json:"target_match"`
// TargetMatchRE defines pairs like TargetMatch but does regular expression
// matching.
TargetMatchRE map[string]Regexp `yaml:"target_match_re"`
TargetMatchRE map[string]Regexp `yaml:"target_match_re" json:"target_match_re"`
// A set of labels that must be equal between the source and target alert
// for them to be a match.
Equal model.LabelNames `yaml:"equal"`
Equal model.LabelNames `yaml:"equal" json:"equal"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -403,18 +403,18 @@ func (r *InhibitRule) UnmarshalYAML(unmarshal func(interface{}) error) error {
// Receiver configuration provides configuration on how to contact a receiver.
type Receiver struct {
// A unique identifier for this receiver.
Name string `yaml:"name"`
Name string `yaml:"name" json:"name"`
EmailConfigs []*EmailConfig `yaml:"email_configs,omitempty"`
PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs,omitempty"`
HipchatConfigs []*HipchatConfig `yaml:"hipchat_configs,omitempty"`
SlackConfigs []*SlackConfig `yaml:"slack_configs,omitempty"`
WebhookConfigs []*WebhookConfig `yaml:"webhook_configs,omitempty"`
OpsGenieConfigs []*OpsGenieConfig `yaml:"opsgenie_configs,omitempty"`
PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty"`
EmailConfigs []*EmailConfig `yaml:"email_configs,omitempty" json:"email_configs,omitempty"`
PagerdutyConfigs []*PagerdutyConfig `yaml:"pagerduty_configs,omitempty" json:"pagerduty_configs,omitempty"`
HipchatConfigs []*HipchatConfig `yaml:"hipchat_configs,omitempty" json:"hipchat_configs,omitempty"`
SlackConfigs []*SlackConfig `yaml:"slack_configs,omitempty" json:"slack_configs,omitempty"`
WebhookConfigs []*WebhookConfig `yaml:"webhook_configs,omitempty" json:"webhook_configs,omitempty"`
OpsGenieConfigs []*OpsGenieConfig `yaml:"opsgenie_configs,omitempty" json:"opsgenie_configs,omitempty"`
PushoverConfigs []*PushoverConfig `yaml:"pushover_configs,omitempty" json:"pushover_configs,omitempty"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.

View File

@ -108,7 +108,7 @@ var (
// NotifierConfig contains base options common across all notifier configurations.
type NotifierConfig struct {
VSendResolved bool `yaml:"send_resolved"`
VSendResolved bool `yaml:"send_resolved" json:"send_resolved"`
}
func (nc *NotifierConfig) SendResolved() bool {
@ -117,22 +117,22 @@ func (nc *NotifierConfig) SendResolved() bool {
// EmailConfig configures notifications via mail.
type EmailConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
// Email address to notify.
To string `yaml:"to"`
From string `yaml:"from"`
Smarthost string `yaml:"smarthost,omitempty"`
AuthUsername string `yaml:"auth_username"`
AuthPassword Secret `yaml:"auth_password"`
AuthSecret Secret `yaml:"auth_secret"`
AuthIdentity string `yaml:"auth_identity"`
Headers map[string]string `yaml:"headers"`
HTML string `yaml:"html"`
RequireTLS bool `yaml:"require_tls"`
To string `yaml:"to" json:"to"`
From string `yaml:"from" json:"from"`
Smarthost string `yaml:"smarthost,omitempty" json:"smarthost,omitempty"`
AuthUsername string `yaml:"auth_username" json:"auth_username"`
AuthPassword Secret `yaml:"auth_password" json:"auth_password"`
AuthSecret Secret `yaml:"auth_secret" json:"auth_secret"`
AuthIdentity string `yaml:"auth_identity" json:"auth_identity"`
Headers map[string]string `yaml:"headers" json:"headers"`
HTML string `yaml:"html" json:"html"`
RequireTLS bool `yaml:"require_tls" json:"require_tls"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -161,17 +161,17 @@ func (c *EmailConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// PagerdutyConfig configures notifications via PagerDuty.
type PagerdutyConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
ServiceKey Secret `yaml:"service_key"`
URL string `yaml:"url"`
Client string `yaml:"client"`
ClientURL string `yaml:"client_url"`
Description string `yaml:"description"`
Details map[string]string `yaml:"details"`
ServiceKey Secret `yaml:"service_key" json:"service_key"`
URL string `yaml:"url" json:"url"`
Client string `yaml:"client" json:"client"`
ClientURL string `yaml:"client_url" json:"client_url"`
Description string `yaml:"description" json:"description"`
Details map[string]string `yaml:"details" json:"details"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -189,24 +189,24 @@ func (c *PagerdutyConfig) UnmarshalYAML(unmarshal func(interface{}) error) error
// SlackConfig configures notifications via Slack.
type SlackConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
APIURL Secret `yaml:"api_url"`
APIURL Secret `yaml:"api_url" json:"api_url"`
// Slack channel override, (like #other-channel or @username).
Channel string `yaml:"channel"`
Username string `yaml:"username"`
Color string `yaml:"color"`
Channel string `yaml:"channel" json:"channel"`
Username string `yaml:"username" json:"username"`
Color string `yaml:"color" json:"color"`
Title string `yaml:"title"`
TitleLink string `yaml:"title_link"`
Pretext string `yaml:"pretext"`
Text string `yaml:"text"`
Fallback string `yaml:"fallback"`
IconEmoji string `yaml:"icon_emoji"`
Title string `yaml:"title" json:"title"`
TitleLink string `yaml:"title_link" json:"title_link"`
Pretext string `yaml:"pretext" json:"pretext"`
Text string `yaml:"text" json:"text"`
Fallback string `yaml:"fallback" json:"fallback"`
IconEmoji string `yaml:"icon_emoji" json:"icon_emoji"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -224,19 +224,19 @@ func (c *SlackConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// HipchatConfig configures notifications via Hipchat.
type HipchatConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
APIURL string `yaml:"api_url"`
AuthToken Secret `yaml:"auth_token"`
RoomID string `yaml:"room_id"`
From string `yaml:"from"`
Notify bool `yaml:"notify"`
Message string `yaml:"message"`
MessageFormat string `yaml:"message_format"`
Color string `yaml:"color"`
APIURL string `yaml:"api_url" json:"api_url"`
AuthToken Secret `yaml:"auth_token" json:"auth_token"`
RoomID string `yaml:"room_id" json:"room_id"`
From string `yaml:"from" json:"from"`
Notify bool `yaml:"notify" json:"notify"`
Message string `yaml:"message" json:"message"`
MessageFormat string `yaml:"message_format" json:"message_format"`
Color string `yaml:"color" json:"color"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -255,13 +255,13 @@ func (c *HipchatConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// WebhookConfig configures notifications via a generic webhook.
type WebhookConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
// URL to send POST request to.
URL string `yaml:"url"`
URL string `yaml:"url" json:"url"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -279,18 +279,18 @@ func (c *WebhookConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
// OpsGenieConfig configures notifications via OpsGenie.
type OpsGenieConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
APIKey Secret `yaml:"api_key"`
APIHost string `yaml:"api_host"`
Description string `yaml:"description"`
Source string `yaml:"source"`
Details map[string]string `yaml:"details"`
Teams string `yaml:"teams"`
Tags string `yaml:"tags"`
APIKey Secret `yaml:"api_key" json:"api_key"`
APIHost string `yaml:"api_host" json:"api_host"`
Description string `yaml:"description" json:"description"`
Source string `yaml:"source" json:"source"`
Details map[string]string `yaml:"details" json:"details"`
Teams string `yaml:"teams" json:"teams"`
Tags string `yaml:"tags" json:"tags"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.
@ -321,19 +321,19 @@ func (d duration) MarshalText() ([]byte, error) {
}
type PushoverConfig struct {
NotifierConfig `yaml:",inline"`
NotifierConfig `yaml:",inline" json:",inline"`
UserKey Secret `yaml:"user_key"`
Token Secret `yaml:"token"`
Title string `yaml:"title"`
Message string `yaml:"message"`
URL string `yaml:"url"`
Priority string `yaml:"priority"`
Retry duration `yaml:"retry"`
Expire duration `yaml:"expire"`
UserKey Secret `yaml:"user_key" json:"user_key"`
Token Secret `yaml:"token" json:"token"`
Title string `yaml:"title" json:"title"`
Message string `yaml:"message" json:"message"`
URL string `yaml:"url" json:"url"`
Priority string `yaml:"priority" json:"priority"`
Retry duration `yaml:"retry" json:"retry"`
Expire duration `yaml:"expire" json:"expire"`
// Catches all undefined fields and must be empty after parsing.
XXX map[string]interface{} `yaml:",inline"`
XXX map[string]interface{} `yaml:",inline" json:"-"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.

View File

@ -83,7 +83,7 @@ func templateDefaultTmpl() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "template/default.tmpl", size: 15667, mode: os.FileMode(420), modTime: time.Unix(1461810859, 0)}
info := bindataFileInfo{name: "template/default.tmpl", size: 15667, mode: os.FileMode(420), modTime: time.Unix(1466785633, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}

View File

@ -32,6 +32,5 @@
</div>
</div>
<script src="lib/d3.v3.min.js"></script>
<script src="lib/js-yaml.min.js"></script>
<script src="lib/routing-tree.js"></script>
</div>

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -43,7 +43,7 @@ function resetSVG() {
// Handler for reading config.yml
d3.json("api/v1/status", function(error, data) {
var parsedConfig = jsyaml.load(data.data.config);
var parsedConfig = data.data.configJSON;
// Create a new SVG for each time a config is loaded.
resetSVG();