moira
/
interfaces.go
233 строки · 10.2 Кб
1package moira
2
3import (
4"time"
5
6"gopkg.in/tomb.v2"
7)
8
9// Database implements DB functionality
10type Database interface {
11// SelfState
12UpdateMetricsHeartbeat() error
13GetMetricsUpdatesCount() (int64, error)
14GetChecksUpdatesCount() (int64, error)
15
16// Tag storing
17GetTagNames() ([]string, error)
18RemoveTag(tagName string) error
19GetTagTriggerIDs(tagName string) ([]string, error)
20GetTagsStats(tags ...string) ([]TagStats, error)
21
22// LastCheck storing
23GetTriggerLastCheck(triggerID string) (*CheckData, error)
24GetTriggerLastChecks(triggerIDs []string) (map[string]*CheckData, error)
25GetOrCreateTriggerLastCheck(triggerID string) (*CheckData, error)
26SetTriggerLastCheck(triggerID string, checkData *CheckData) error
27RemoveTriggerLastCheck(triggerID string) error
28GetTriggerCheckIDs(tags []string, onlyErrors bool) ([]string, error)
29
30// Maintenance operations
31GetMaintenanceSilent(spt SilentPatternType) (Maintenance, error)
32GetMaintenanceTrigger(id string) (Maintenance, error)
33GetOrCreateMaintenanceSilent(spt SilentPatternType) (Maintenance, error)
34GetOrCreateMaintenanceTrigger(id string) (Maintenance, error)
35SetMaintenanceTrigger(id string, maintenance Maintenance) error
36DelMaintenanceTrigger(id string) error
37
38// Trigger storing
39CheckTriggerExists(string) (bool, error)
40GetTriggerIDs(onlyPull bool) ([]string, error)
41GetTrigger(triggerID string) (*Trigger, error)
42GetTriggers(triggerIDs []string) ([]*Trigger, error)
43GetTriggerChecks(triggerIDs []string) ([]*TriggerCheck, error)
44SaveTrigger(triggerID string, trigger *Trigger) error
45RemoveTrigger(triggerID string) error
46GetPatternTriggerIDs(pattern string) ([]string, error)
47RemovePatternTriggerIDs(pattern string) error
48AddTriggerForcedNotification(triggerID string, metrics []string, time int64) error
49GetTriggerForcedNotifications(triggerID string) (map[string]bool, error)
50DeleteTriggerForcedNotification(triggerID string, metric string) error
51DeleteTriggerForcedNotifications(triggerID string, metrics []string) error
52
53// Throttling
54GetTriggerThrottling(triggerID string) (time.Time, time.Time)
55SetTriggerThrottling(triggerID string, next time.Time) error
56DeleteTriggerThrottling(triggerID string) error
57
58// NotificationEvent storing
59GetNotificationEvents(triggerID string, start, size int64) ([]*NotificationEvent, error)
60GetAllNotificationEvents(start, end int64) ([]*NotificationEvent, error)
61PushNotificationEvent(event *NotificationEvent) error
62GetNotificationEventCount(triggerID string, from int64) int64
63FetchNotificationEvent(withSaturations bool) (NotificationEvent, error)
64FetchDelayedNotificationEvents(to int64, withSaturations bool) ([]NotificationEvent, error)
65AddDelayedNotificationEvent(event NotificationEvent, timestamp int64) error
66
67// Event inheritance
68AddChildEvents(parentTriggerID string, parentMetric string, childTriggerID string, childMetrics []string) error
69GetChildEvents(parentTriggerID, parentMetric string) (map[string][]string, error)
70GetParentEvents(childTriggerID, childMetric string) (map[string][]string, error)
71DeleteChildEvents(parentTriggerID, parentMetric string, childTriggerID string, childMetrics []string) error
72
73// ContactData storing
74GetContact(contactID string) (ContactData, error)
75GetContacts(contactIDs []string) ([]*ContactData, error)
76GetAllContacts() ([]*ContactData, error)
77RemoveContact(contactID string) error
78SaveContact(contact *ContactData) error
79GetUserContactIDs(userLogin string) ([]string, error)
80
81// SilentPatterData storing
82GetSilentPatternsAll() ([]*SilentPatternData, error)
83GetSilentPatternsTyped(pt SilentPatternType) ([]*SilentPatternData, error)
84SaveSilentPatterns(pt SilentPatternType, spl ...*SilentPatternData) error
85RemoveSilentPatterns(pt SilentPatternType, spl ...*SilentPatternData) error
86LockSilentPatterns(pt SilentPatternType) error
87UnlockSilentPatterns(pt SilentPatternType) error
88
89// SubscriptionData storing
90GetSubscription(id string) (SubscriptionData, error)
91GetSubscriptions(subscriptionIDs []string) ([]*SubscriptionData, error)
92GetAllSubscriptions() ([]*SubscriptionData, error)
93MaybeUpdateEscalationsOfSubscription(subscription *SubscriptionData) error
94SaveSubscription(subscription *SubscriptionData) error
95SaveSubscriptions(subscriptions []*SubscriptionData) error
96RemoveSubscription(subscriptionID string) error
97GetUserSubscriptionIDs(userLogin string) ([]string, error)
98GetTagsSubscriptions(tags []string) ([]*SubscriptionData, error)
99
100// ScheduledNotification storing
101GetNotifications(start, end int64) ([]*ScheduledNotification, int64, error)
102RemoveNotification(notificationKey string) (int64, error)
103FetchNotifications(to int64) ([]*ScheduledNotification, error)
104AddNotification(notification *ScheduledNotification) error
105AddNotifications(notification []*ScheduledNotification, timestamp int64) error
106
107// Patterns and metrics storing
108GetPatterns() ([]string, error)
109AddPatternMetric(pattern, metric string) error
110GetPatternMetrics(pattern string) ([]string, error)
111RemovePattern(pattern string) error
112RemovePatternsMetrics(pattern []string) error
113RemovePatternWithMetrics(pattern string) error
114
115SubscribeMetricEvents(tomb *tomb.Tomb) (<-chan *MetricEvent, error)
116SaveMetrics(buffer map[string]*MatchedMetric) error
117GetMetricRetention(metric string) (int64, error)
118GetMetricsValues(metrics []string, from int64, until int64) (map[string][]*MetricValue, error)
119RemoveMetricValues(metric string, toTime int64) error
120RemoveMetricsValues(metrics []string, toTime int64) error
121
122// Locks
123AcquireLock(lockKey string, ttlSec int, timeout time.Duration) error
124AcquireTriggerCheckLock(triggerID string) error
125AcquireTriggerMaintenanceLock(triggerID string) error
126DeleteLock(lockKey string) error
127DeleteTriggerCheckLock(triggerID string) error
128DeleteTriggerMaintenanceLock(triggerID string) error
129SetLock(lockKey string, ttlSec int) (bool, error)
130SetTriggerCheckLock(triggerID string) (bool, error)
131SetTriggerCoolDown(triggerID string, ttlSec int) (bool, error)
132
133// Bot data storing
134GetIDByUsername(messenger, username string) (string, error)
135SetUsernameID(messenger, username, id string) error
136RemoveUser(messenger, username string) error
137RegisterBotIfAlreadyNot(messenger string, ttl time.Duration) bool
138RenewBotRegistration(messenger string) bool
139DeregisterBots()
140DeregisterBot(messenger string) bool
141
142// Escalations
143AddEscalations(ts int64, event NotificationEvent, trigger TriggerData, escalations []EscalationData) error
144TriggerHasPendingEscalations(triggerID string, withResolutions bool) (bool, error)
145MetricHasPendingEscalations(triggerID, metric string, withResolutions bool) (bool, error)
146AckEscalations(triggerID, metric string, withResolutions bool) error
147AckEscalationsBatch(triggerID string, metrics []string, withResolutions bool) error
148FetchScheduledEscalationEvents(to int64) ([]*ScheduledEscalationEvent, error)
149RegisterProcessedEscalationID(escalationID, triggerID, metric string) error
150AddUnacknowledgedMessage(triggerID string, metric string, link MessageLink) error
151GetUnacknowledgedMessages(triggerID, metric string) ([]MessageLink, error)
152AckUnacknowledgedMessages(triggerID, metric string) error
153
154// Global settings
155GetGlobalSettings() (GlobalSettings, error)
156SetGlobalSettings(GlobalSettings) error
157
158// Slack-specific
159GetSlackThreadLinks(contactID, triggerID string) (messages map[string]string, err error)
160AddSlackThreadLinks(contactID, triggerID, threadTs, payload string, expiryTime *time.Time) error
161RemoveSlackThreadLinks(contactID, triggerID string, threadsTs, completedThreads []string) error
162GetAllSlackThreadLinks(triggerID string) ([]SlackThreadLink, error)
163
164GetSlackDashboard(contactID, ts string) (SlackDashboard, error)
165UpdateSlackDashboard(contactID, ts string, db SlackDashboard, expiryTime *time.Time) error
166RemoveSlackDashboards(contactID string, dashboardsTs []string) error
167GetAllInheritedTriggerDashboards(triggerID, ancestorTriggerID, ancestorMetric string) ([]SlackThreadLink, error)
168SaveInheritedTriggerDashboard(contactID, threadTs, triggerID, ancestorTriggerID, ancestorMetric, newDashboardTs string) error
169DeleteInheritedTriggerDashboard(contactID, threadTs, triggerID, ancestorTriggerID, ancestorMetric, dashboardTs string) error
170
171UpdateInheritanceDataVersion() error
172
173FetchSlackDelayedActions(until time.Time) ([]SlackDelayedAction, error)
174SaveSlackDelayedAction(action SlackDelayedAction) error
175GetSlackUserGroups() (SlackUserGroupsCache, error)
176SaveSlackUserGroups(userGroups SlackUserGroupsCache) error
177
178GetServiceDuty(service string) (DutyData, error)
179UpdateServiceDuty(service string, dutyData DutyData) error
180}
181
182type TriggerInheritanceDatabase interface {
183Ping() bool
184
185GetMaxDepthInGraph(id string) (int, error)
186GetAllAncestors(id string) ([][]string, error)
187GetAllChildren(triggerID string) ([]string, error)
188SetTriggerParents(triggerID string, newParentIDs []string) error
189}
190
191// Logger implements logger abstraction
192type Logger interface {
193Debug(message string)
194DebugE(message string, extra interface{})
195DebugF(format string, args ...interface{})
196Info(message string)
197InfoE(message string, extra interface{})
198InfoF(format string, args ...interface{})
199Warn(message string)
200WarnE(message string, extra interface{})
201WarnF(format string, args ...interface{})
202Error(message string)
203ErrorE(message string, extra interface{})
204ErrorF(format string, args ...interface{})
205Fatal(message string)
206FatalE(message string, extra interface{})
207FatalF(format string, args ...interface{})
208TracePanic(message string, extra interface{})
209TraceSelfStats(id string, started time.Time)
210}
211
212// Sender interface for implementing specified contact type sender
213type Sender interface {
214Init(senderSettings map[string]string, location *time.Location) error
215SendEvents(events NotificationEvents, contact ContactData, trigger TriggerData, throttled, needAck bool) error
216}
217
218// SenderWithInheritance is a sender that can send messages to ancestor triggers' threads
219type SenderWithInheritance interface {
220Sender
221SendEventsWithInheritance(
222events NotificationEvents, contact ContactData, trigger TriggerData,
223ancestorTriggerID, ancestorMetric string,
224) error
225}
226
227// MessageLink is a link to a message sent in a Sender.
228type MessageLink interface {
229// StorageKey is used to serialize a Link to store it in a Database
230StorageKey() string
231FromString(string) error
232SenderName() string
233}
234