forked from moira-alert/moira
-
Notifications
You must be signed in to change notification settings - Fork 0
/
interfaces.go
136 lines (117 loc) · 5.17 KB
/
interfaces.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package moira
import (
"time"
"gopkg.in/tomb.v2"
)
// Database implements DB functionality
type Database interface {
// SelfState
UpdateMetricsHeartbeat() error
GetMetricsUpdatesCount() (int64, error)
GetChecksUpdatesCount() (int64, error)
GetRemoteChecksUpdatesCount() (int64, error)
GetNotifierState() (string, error)
SetNotifierState(string) error
// Tag storing
GetTagNames() ([]string, error)
RemoveTag(tagName string) error
GetTagTriggerIDs(tagName string) ([]string, error)
// LastCheck storing
GetTriggerLastCheck(triggerID string) (CheckData, error)
SetTriggerLastCheck(triggerID string, checkData *CheckData, isRemote bool) error
RemoveTriggerLastCheck(triggerID string) error
GetTriggerCheckIDs(tags []string, onlyErrors bool) ([]string, error)
SetTriggerCheckMetricsMaintenance(triggerID string, metrics map[string]int64) error
// Trigger storing
GetTriggerIDs() ([]string, error)
GetAllTriggerIDs() ([]string, error)
GetRemoteTriggerIDs() ([]string, error)
GetTrigger(triggerID string) (Trigger, error)
GetTriggers(triggerIDs []string) ([]*Trigger, error)
GetTriggerChecks(triggerIDs []string) ([]*TriggerCheck, error)
SaveTrigger(triggerID string, trigger *Trigger) error
RemoveTrigger(triggerID string) error
GetPatternTriggerIDs(pattern string) ([]string, error)
RemovePatternTriggerIDs(pattern string) error
// Throttling
GetTriggerThrottling(triggerID string) (time.Time, time.Time)
SetTriggerThrottling(triggerID string, next time.Time) error
DeleteTriggerThrottling(triggerID string) error
// NotificationEvent storing
GetNotificationEvents(triggerID string, start, size int64) ([]*NotificationEvent, error)
PushNotificationEvent(event *NotificationEvent, ui bool) error
GetNotificationEventCount(triggerID string, from int64) int64
FetchNotificationEvent() (NotificationEvent, error)
RemoveAllNotificationEvents() error
// ContactData storing
GetContact(contactID string) (ContactData, error)
GetContacts(contactIDs []string) ([]*ContactData, error)
GetAllContacts() ([]*ContactData, error)
RemoveContact(contactID string) error
SaveContact(contact *ContactData) error
GetUserContactIDs(userLogin string) ([]string, error)
// SubscriptionData storing
GetSubscription(id string) (SubscriptionData, error)
GetSubscriptions(subscriptionIDs []string) ([]*SubscriptionData, error)
SaveSubscription(subscription *SubscriptionData) error
SaveSubscriptions(subscriptions []*SubscriptionData) error
RemoveSubscription(subscriptionID string) error
GetUserSubscriptionIDs(userLogin string) ([]string, error)
GetTagsSubscriptions(tags []string) ([]*SubscriptionData, error)
// ScheduledNotification storing
GetNotifications(start, end int64) ([]*ScheduledNotification, int64, error)
RemoveNotification(notificationKey string) (int64, error)
RemoveAllNotifications() error
FetchNotifications(to int64) ([]*ScheduledNotification, error)
AddNotification(notification *ScheduledNotification) error
AddNotifications(notification []*ScheduledNotification, timestamp int64) error
// Patterns and metrics storing
GetPatterns() ([]string, error)
AddPatternMetric(pattern, metric string) error
GetPatternMetrics(pattern string) ([]string, error)
RemovePattern(pattern string) error
RemovePatternsMetrics(pattern []string) error
RemovePatternWithMetrics(pattern string) error
SubscribeMetricEvents(tomb *tomb.Tomb) (<-chan *MetricEvent, error)
SaveMetrics(buffer map[string]*MatchedMetric) error
GetMetricRetention(metric string) (int64, error)
GetMetricsValues(metrics []string, from int64, until int64) (map[string][]*MetricValue, error)
RemoveMetricValues(metric string, toTime int64) error
RemoveMetricsValues(metrics []string, toTime int64) error
AddTriggersToCheck(triggerIDs []string) error
GetTriggerToCheck() (string, error)
GetTriggersToCheckCount() (int64, error)
AddRemoteTriggersToCheck(triggerIDs []string) error
GetRemoteTriggerToCheck() (string, error)
GetRemoteTriggersToCheckCount() (int64, error)
// TriggerCheckLock storing
AcquireTriggerCheckLock(triggerID string, timeout int) error
DeleteTriggerCheckLock(triggerID string) error
SetTriggerCheckLock(triggerID string) (bool, error)
// Bot data storing
GetIDByUsername(messenger, username string) (string, error)
SetUsernameID(messenger, username, id string) error
RemoveUser(messenger, username string) error
RegisterBotIfAlreadyNot(messenger string, ttl time.Duration) bool
RenewBotRegistration(messenger string) bool
DeregisterBots()
DeregisterBot(messenger string) bool
}
// Logger implements logger abstraction
type Logger interface {
Debug(args ...interface{})
Debugf(format string, args ...interface{})
Info(args ...interface{})
Infof(format string, args ...interface{})
Error(args ...interface{})
Errorf(format string, args ...interface{})
Fatal(args ...interface{})
Fatalf(format string, args ...interface{})
Warning(args ...interface{})
Warningf(format string, args ...interface{})
}
// Sender interface for implementing specified contact type sender
type Sender interface {
SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, throttled bool) error
Init(senderSettings map[string]string, logger Logger, location *time.Location, dateTimeFormat string) error
}