• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

infrawatch / sg-core / 9545321080

17 Jun 2024 09:29AM UTC coverage: 49.783% (-0.1%) from 49.891%
9545321080

push

github

web-flow
Merge pull request #137 from infrawatch/jwysogla-test-ci

Fix sg-bridge in integration CI

916 of 1840 relevant lines covered (49.78%)

0.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.33
/plugins/handler/events/pkg/lib/source.go
1
package lib
2

3
import (
4
        "regexp"
5
)
6

7
var (
8
        // Ceilometer data parsers
9
        rexForOsloMessage = regexp.MustCompile(`\\*"oslo.message\\*"\s*:\s*\\*"({.*})\\*"`)
10
        rexForPayload     = regexp.MustCompile(`\\+"payload\\+"\s*:\s*\[(.*)\]`)
11
        rexForEventType   = regexp.MustCompile(`\\+"event_type\\+"\s*:\s*\\*"`)
12
        // collectd data parsers
13
        rexForLabelsField     = regexp.MustCompile(`\\?"labels\\?"\w?:\w?\{`)
14
        rexForAnnotationField = regexp.MustCompile(`\\?"annotations\\?"\w?:\w?\{`)
15
)
16

17
func recognizeCeilometer(jsondata []byte) bool {
1✔
18
        match := rexForOsloMessage.FindSubmatchIndex(jsondata)
1✔
19
        if match == nil {
1✔
20
                return false
×
21
        }
×
22
        match = rexForEventType.FindSubmatchIndex(jsondata)
1✔
23
        if match == nil {
1✔
24
                return false
×
25
        }
×
26
        match = rexForPayload.FindSubmatchIndex(jsondata)
1✔
27
        return match != nil
1✔
28
}
29

30
func recognizeCollectd(jsondata []byte) bool {
1✔
31
        labels := rexForLabelsField.FindIndex(jsondata)
1✔
32
        annots := rexForAnnotationField.FindIndex(jsondata)
1✔
33
        return labels != nil && annots != nil
1✔
34
}
1✔
35

36
var recognizers = map[string](func([]byte) bool){
37
        "collectd":   recognizeCollectd,
38
        "ceilometer": recognizeCeilometer,
39
}
40

41
// DataSource indentifies a format of incoming data in the message bus channel.
42
type DataSource int
43

44
// ListAll returns slice of supported data sources in form of human readable names.
45
func (src DataSource) ListAll() []string {
1✔
46
        return []string{"ceilometer", "collectd", "generic"}
1✔
47
}
1✔
48

49
// SetFromString resets value according to given human readable identification. Returns false if invalid identification was given.
50
func (src *DataSource) SetFromString(name string) bool {
1✔
51
        for index, value := range src.ListAll() {
2✔
52
                if name == value {
2✔
53
                        *src = DataSource(index)
1✔
54
                        return true
1✔
55
                }
1✔
56
        }
57
        return false
×
58
}
59

60
// SetFromMessage resets value according to given message data format
61
func (src *DataSource) SetFromMessage(jsondata []byte) {
1✔
62
        for source, rec := range recognizers {
2✔
63
                if rec(jsondata) {
2✔
64
                        src.SetFromString(source)
1✔
65
                        return
1✔
66
                }
1✔
67
        }
68
        // TODO: right now generic event message is everything else than collectd or ceilometer event,
69
        //      but once we come up with SG generic event format, we need to add it's recognizer
70
        src.SetFromString("generic")
×
71
}
72

73
// String returns human readable data type identification.
74
func (src DataSource) String() string {
1✔
75
        return (src.ListAll())[src]
1✔
76
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc