File tree 14 files changed +206
-81
lines changed
14 files changed +206
-81
lines changed Original file line number Diff line number Diff line change 18
18
- fix #62 timeseriesdb plugins crash when ` update ` is given ` None ` as a value
19
19
- fix #54 pytest > 3 for testing
20
20
### Changed
21
+ - plugin groups can now be maintained under an explicit ` groups ` section in the plugin config (#44 )
21
22
- move from ` facsimile ` to ` ctl ` for package / release management
22
23
- parse_interval now can handle multiunit strings such as 1m30s
23
24
### Deprecated
Original file line number Diff line number Diff line change @@ -5,17 +5,18 @@ probes:
5
5
output :
6
6
- zmq_vodka
7
7
8
- public_dns :
9
- hosts :
10
- - host : 8.8.8.8
11
- name : Google
12
- color : red
13
- - host : 4.2.2.1
14
- name : Level(3)
15
- color : blue
16
- - host : 208.67.222.222
17
- name : OpenDNS
18
- color : orange
8
+ groups :
9
+ - name : public_dns
10
+ hosts :
11
+ - host : 8.8.8.8
12
+ name : Google
13
+ color : red
14
+ - host : 4.2.2.1
15
+ name : Level(3)
16
+ color : blue
17
+ - host : 208.67.222.222
18
+ name : OpenDNS
19
+ color : orange
19
20
20
21
plugins :
21
22
- name : std_fping
Original file line number Diff line number Diff line change 4
4
output :
5
5
- zmq_vodka
6
6
7
- public_dns :
8
- hosts :
9
- - host : 1.1.1.1
7
+ groups :
8
+ - name : public_dns
9
+ hosts :
10
+ - host : 1.1.1.1
10
11
11
12
plugins :
12
13
- name : std_fping
Original file line number Diff line number Diff line change 4
4
output :
5
5
- zmq_vodka
6
6
7
- public_dns :
8
- hosts :
9
- - host : 8.8.8.8
7
+ groups :
8
+ - name : public_dns
9
+ hosts :
10
+ - host : 8.8.8.8
10
11
11
12
plugins :
12
13
- name : std_fping
Original file line number Diff line number Diff line change @@ -4,17 +4,18 @@ probes:
4
4
output :
5
5
- graphite_avg
6
6
7
- public_dns :
8
- hosts :
9
- - host : 8.8.8.8
10
- name : Google
11
- color : red
12
- - host : 4.2.2.1
13
- name : Level3
14
- color : blue
15
- - host : 208.67.222.222
16
- name : OpenDNS
17
- color : orange
7
+ groups :
8
+ - name : public_dns
9
+ hosts :
10
+ - host : 8.8.8.8
11
+ name : Google
12
+ color : red
13
+ - host : 4.2.2.1
14
+ name : Level3
15
+ color : blue
16
+ - host : 208.67.222.222
17
+ name : OpenDNS
18
+ color : orange
18
19
19
20
plugins :
20
21
- name : std_fping
Original file line number Diff line number Diff line change @@ -4,17 +4,18 @@ probes:
4
4
output :
5
5
- rrd_avg
6
6
7
- public_dns :
8
- hosts :
9
- - host : 8.8.8.8
10
- name : Google
11
- color : red
12
- - host : 4.2.2.1
13
- name : Level(3)
14
- color : blue
15
- - host : 208.67.222.222
16
- name : OpenDNS
17
- color : orange
7
+ groups :
8
+ - name : public_dns
9
+ hosts :
10
+ - host : 8.8.8.8
11
+ name : Google
12
+ color : red
13
+ - host : 4.2.2.1
14
+ name : Level(3)
15
+ color : blue
16
+ - host : 208.67.222.222
17
+ name : OpenDNS
18
+ color : orange
18
19
19
20
plugins :
20
21
- name : std_fping
Original file line number Diff line number Diff line change @@ -5,17 +5,18 @@ probes:
5
5
output :
6
6
- vodka
7
7
8
- public_dns :
9
- hosts :
10
- - host : 8.8.8.8
11
- name : Google
12
- color : red
13
- - host : 4.2.2.1
14
- name : Level(3)
15
- color : blue
16
- - host : 208.67.222.222
17
- name : OpenDNS
18
- color : orange
8
+ groups :
9
+ - name : public_dns
10
+ hosts :
11
+ - host : 8.8.8.8
12
+ name : Google
13
+ color : red
14
+ - host : 4.2.2.1
15
+ name : Level(3)
16
+ color : blue
17
+ - host : 208.67.222.222
18
+ name : OpenDNS
19
+ color : orange
19
20
20
21
plugins :
21
22
- name : std_fping
Original file line number Diff line number Diff line change @@ -4,17 +4,18 @@ probes:
4
4
output :
5
5
- whisper_avg
6
6
7
- public_dns :
8
- hosts :
9
- - host : 8.8.8.8
10
- name : Google
11
- color : red
12
- - host : 4.2.2.1
13
- name : Level(3)
14
- color : blue
15
- - host : 208.67.222.222
16
- name : OpenDNS
17
- color : orange
7
+ groups :
8
+ - name : public_dns
9
+ hosts :
10
+ - host : 8.8.8.8
11
+ name : Google
12
+ color : red
13
+ - host : 4.2.2.1
14
+ name : Level(3)
15
+ color : blue
16
+ - host : 208.67.222.222
17
+ name : OpenDNS
18
+ color : orange
18
19
19
20
plugins :
20
21
- name : std_fping
Original file line number Diff line number Diff line change 3
3
4
4
import vaping
5
5
from vaping .config import parse_interval
6
+ from vaping import plugin
6
7
7
8
8
9
def test_parse_interval ():
@@ -31,3 +32,67 @@ def test_probe_plugin_name(config_dir):
31
32
with pytest .raises (ValueError ) as excinfo :
32
33
vaping .daemon .Vaping (config_dir = config_dir )
33
34
assert "probes may not share names with plugins" in str (excinfo .value )
35
+
36
+
37
+ def test_plugin_legacy_groups ():
38
+
39
+ """
40
+ test legacy plugin groups
41
+ TODO: remove with vaping 2.0
42
+ """
43
+
44
+ probe = plugin .get_probe ({
45
+ "type" : "fping" ,
46
+ "name" : "probe_b" ,
47
+ "interval" : "3s" ,
48
+ "dns" : {
49
+ "hosts" : [{
50
+ "host" : "1.1.1.1" ,
51
+ "name" : "Cloudflare"
52
+ }]
53
+ }
54
+ }, {})
55
+
56
+ expected = {
57
+ "dns" : {
58
+ "hosts" : [{
59
+ "host" : "1.1.1.1" ,
60
+ "name" : "Cloudflare"
61
+ }]
62
+ }
63
+ }
64
+
65
+ assert probe .groups == expected
66
+
67
+ def test_plugin_groups ():
68
+
69
+ """
70
+ test plugin groups as per #44 implementation
71
+ """
72
+
73
+ probe = plugin .get_probe ({
74
+ "type" : "fping" ,
75
+ "name" : "probe_c" ,
76
+ "interval" : "3s" ,
77
+ "groups" : [{
78
+ "name" : "dns" ,
79
+ "hosts" : [{
80
+ "host" : "1.1.1.1" ,
81
+ "name" : "Cloudflare"
82
+ }]
83
+ }]
84
+ }, {})
85
+
86
+
87
+ expected = {
88
+ "dns" : {
89
+ "name" : "dns" ,
90
+ "hosts" : [{
91
+ "host" : "1.1.1.1" ,
92
+ "name" : "Cloudflare"
93
+ }]
94
+ }
95
+ }
96
+
97
+ assert probe .groups == expected
98
+
Original file line number Diff line number Diff line change @@ -12,6 +12,9 @@ def test_init(this_dir):
12
12
13
13
14
14
def test_probe_to_graphsrv ():
15
+
16
+ # vodka setup with single group plugin
17
+
15
18
probe = plugin .get_probe ({
16
19
"type" : "fping_mtr" ,
17
20
"name" : "probe_a" ,
@@ -24,6 +27,10 @@ def test_probe_to_graphsrv():
24
27
25
28
assert group ["targets" ] == {"1.1.1.1" :{"host" :"1.1.1.1" }}
26
29
30
+ # vodka setup with legacy plugin groups (before implementation
31
+ # of #44)
32
+ # TODO: remove with vaping 2.0
33
+
27
34
probe = plugin .get_probe ({
28
35
"type" : "fping" ,
29
36
"name" : "probe_b" ,
@@ -39,3 +46,23 @@ def test_probe_to_graphsrv():
39
46
group = graphsrv .group .groups .get ("probe_b" ).get ("dns" )
40
47
41
48
assert group ["targets" ] == {"1.1.1.1" :{"host" :"1.1.1.1" , "name" :"Cloudflare" }}
49
+
50
+ # vodka setup with plugin group implementation as
51
+ # per #44
52
+
53
+ probe = plugin .get_probe ({
54
+ "type" : "fping" ,
55
+ "name" : "probe_c" ,
56
+ "interval" : "3s" ,
57
+ "groups" : [{
58
+ "name" : "dns" ,
59
+ "hosts" : [{
60
+ "host" : "1.1.1.1" ,
61
+ "name" : "Cloudflare"
62
+ }]
63
+ }]
64
+ }, {})
65
+ probe_to_graphsrv (probe )
66
+ group = graphsrv .group .groups .get ("probe_c" ).get ("dns" )
67
+
68
+ assert group ["targets" ] == {"1.1.1.1" :{"host" :"1.1.1.1" , "name" :"Cloudflare" }}
Original file line number Diff line number Diff line change
1
+ import collections
2
+ import os
1
3
import abc
2
4
import copy
3
5
import datetime
4
6
import logging
5
7
import munge
6
- import os
7
8
8
9
from future .utils import with_metaclass
9
10
from vaping .config import parse_interval
@@ -28,6 +29,32 @@ class PluginBase(vaping.io.Thread):
28
29
Calls `self.on_start()` and `self.on_stop()` before and after running in
29
30
case any connections need to be created or cleaned up.
30
31
"""
32
+
33
+ @property
34
+ def groups (self ):
35
+
36
+ """
37
+ `dict` - group configurations keyed by name
38
+ """
39
+
40
+ group_config = {}
41
+
42
+ # legacy way of threating any dict as a potential
43
+ # group config (pre #44 implementation)
44
+ # supported until vaping 2.0
45
+
46
+ for k ,v in list (self .config .items ()):
47
+ if isinstance (v , collections .Mapping ):
48
+ group_config [k ] = v
49
+
50
+ # explicit groups object (#44 implementation)
51
+
52
+ for _group_config in self .config .get ("groups" ,[]):
53
+ group_config [_group_config ["name" ]] = _group_config
54
+
55
+ return group_config
56
+
57
+
31
58
def init (self ):
32
59
"""
33
60
called after the plugin is initialized, plugin may define this for any
Original file line number Diff line number Diff line change @@ -37,10 +37,8 @@ def init(self):
37
37
if 'command' not in self .config :
38
38
raise ValueError ('command is required' )
39
39
40
- for k , v in list (self .config .items ()):
41
- # dict means it's a group - FIXME explicit groups
42
- if isinstance (v , collections .Mapping ):
43
- self .hosts = v ['hosts' ]
40
+ for name , group_config in list (self .groups .items ()):
41
+ self .hosts .extend (group_config .get ("hosts" ,[]))
44
42
45
43
self .command = self .config ['command' ]
46
44
Original file line number Diff line number Diff line change @@ -160,10 +160,9 @@ class FPing(FPingBase):
160
160
161
161
def init (self ):
162
162
self .hosts = []
163
- for key , value in list (self .config .items ()):
164
- # dict means it's a group
165
- if isinstance (value , collections .Mapping ):
166
- self .hosts .extend (value ['hosts' ])
163
+
164
+ for name , group_config in list (self .groups .items ()):
165
+ self .hosts .extend (group_config .get ("hosts" ,[]))
167
166
168
167
def probe (self ):
169
168
msg = self .new_message ()
You can’t perform that action at this time.
0 commit comments