initial commit with basic files and types

This commit is contained in:
Fabian Reinartz 2015-06-30 14:29:30 +02:00
parent 4c58dc90e6
commit e730242749
4 changed files with 209 additions and 0 deletions

22
main.go Normal file
View File

@ -0,0 +1,22 @@
// Copyright 2015 Prometheus Team
// 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 main
func main() {
state := NewMemState()
am := New(state)
go am.Run()
}

97
manager.go Normal file
View File

@ -0,0 +1,97 @@
package main
import (
"github.com/prometheus/common/model"
)
// Manager handles active alerts
type Manager struct {
state State
}
func New(s State) *Manager {
return &Manager{
state: s,
}
}
// Run starts the processing of the manager and blocks.
func (m *Manager) Run() {
}
// A State serves the Alertmanager's internal state about active silences.
type State interface {
AlertState
ConfigState
NotifyState
SilenceState
}
type AlertState interface{}
type ConfigState interface{}
type NotifyState interface{}
type SilenceState interface {
// Silences returns a list of all silences.
Silences() ([]*Silence, error)
// SetSilence sets the given silence.
SetSilence(*Silence) error
}
// memState implements the State interface based on in-memory storage.
type memState struct {
silences map[uint64]*Silence
}
func NewMemState() State {
return &memState{
silences: map[uint64]*Silence{},
}
}
func (s *memState) Silences() ([]*Silence, error) {
sils := make([]*Silence, 0, len(s.silences))
for _, sil := range s.silences {
sils = append(sils, sil)
}
return sils, nil
}
func (s *memState) SetSilence(sil *Silence) error {
s.silences[sil.ID] = sil
return nil
}
// Alert models an action triggered by Prometheus.
type Alert struct {
// Short summary of alert.
Summary string `json:"summary"`
// Long description of alert.
Description string `json:"description"`
// Runbook link or reference for the alert.
Runbook string `json:"runbook"`
// Label value pairs for purpose of aggregation, matching, and disposition
// dispatching. This must minimally include an "alertname" label.
Labels model.LabelSet `json:"labels"`
// Extra key/value information which is not used for aggregation.
Payload map[string]string `json:"payload"`
}
// Name returns the name of the alert. It is equivalent to the "alertname" label.
func (a *Alert) Name() string {
return string(a.Labels[model.AlertNameLabel])
}
// Fingerprint returns a unique hash for the alert. It is equivalent to
// the fingerprint of the alert's label set.
func (a *Alert) Fingerprint() model.Fingerprint {
return a.Labels.Fingerprint()
}

52
match.go Normal file
View File

@ -0,0 +1,52 @@
// Copyright 2015 Prometheus Team
// 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 main
import (
"regexp"
"github.com/prometheus/common/model"
)
// Matcher defines a matching rule for the value of a given label.
type Matcher struct {
Name model.LabelName
Value string
isRegex bool
regex *regexp.Regexp
}
func NewMatcher(name model.LabelName, value string) *Matcher {
return &Matcher{
Name: name,
Value: value,
}
}
func NewRegexMatcher(name model.LabelName, value string) (*Matcher, error) {
re, err := regexp.Compile(value)
if err != nil {
return nil, err
}
m := &Matcher{
Name: name,
Value: value,
isRegex: true,
regex: re,
}
return m, nil
}
type Matchers []*Matcher

38
silence.go Normal file
View File

@ -0,0 +1,38 @@
// Copyright 2015 Prometheus Team
// 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 main
import (
"time"
)
type Silence struct {
// The numeric ID of the silence.
ID uint64
// Name/email of the silence creator.
CreatedBy string
// When the silence was first created (Unix timestamp).
CreatedAt, EndsAt time.Time
// Additional comment about the silence.
Comment string
// Matchers that determine which alerts are silenced.
Matchers Matchers
// Timer used to trigger the deletion of the Silence after its expiry
// time.
expiryTimer *time.Timer
}