Skip to content

Commit 4de6560

Browse files
committed
move plugin groups to under groups key (#44)
1 parent dab0dc2 commit 4de6560

File tree

14 files changed

+206
-81
lines changed

14 files changed

+206
-81
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- fix #62 timeseriesdb plugins crash when `update` is given `None` as a value
1919
- fix #54 pytest > 3 for testing
2020
### Changed
21+
- plugin groups can now be maintained under an explicit `groups` section in the plugin config (#44)
2122
- move from `facsimile` to `ctl` for package / release management
2223
- parse_interval now can handle multiunit strings such as 1m30s
2324
### Deprecated

examples/distributed_dns/vaping/config.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ probes:
55
output:
66
- zmq_vodka
77

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
1920

2021
plugins:
2122
- name: std_fping

examples/distributed_shared_graph/vaping-1/config.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ probes:
44
output:
55
- zmq_vodka
66

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
1011

1112
plugins:
1213
- name: std_fping

examples/distributed_shared_graph/vaping-2/config.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ probes:
44
output:
55
- zmq_vodka
66

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
1011

1112
plugins:
1213
- name: std_fping

examples/graphite/config.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ probes:
44
output:
55
- graphite_avg
66

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
1819

1920
plugins:
2021
- name: std_fping

examples/rrdtool/config.yaml

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ probes:
44
output:
55
- rrd_avg
66

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
1819

1920
plugins:
2021
- name: std_fping

examples/standalone_dns/config.yml

+12-11
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ probes:
55
output:
66
- vodka
77

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
1920

2021
plugins:
2122
- name: std_fping

examples/whisper/config.yaml

+12-11
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ probes:
44
output:
55
- whisper_avg
66

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
1819

1920
plugins:
2021
- name: std_fping

tests/test_config.py

+65
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import vaping
55
from vaping.config import parse_interval
6+
from vaping import plugin
67

78

89
def test_parse_interval():
@@ -31,3 +32,67 @@ def test_probe_plugin_name(config_dir):
3132
with pytest.raises(ValueError) as excinfo:
3233
vaping.daemon.Vaping(config_dir=config_dir)
3334
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+

tests/test_vodka.py

+27
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ def test_init(this_dir):
1212

1313

1414
def test_probe_to_graphsrv():
15+
16+
# vodka setup with single group plugin
17+
1518
probe = plugin.get_probe({
1619
"type" : "fping_mtr",
1720
"name" : "probe_a",
@@ -24,6 +27,10 @@ def test_probe_to_graphsrv():
2427

2528
assert group["targets"] == {"1.1.1.1":{"host":"1.1.1.1"}}
2629

30+
# vodka setup with legacy plugin groups (before implementation
31+
# of #44)
32+
# TODO: remove with vaping 2.0
33+
2734
probe = plugin.get_probe({
2835
"type" : "fping",
2936
"name" : "probe_b",
@@ -39,3 +46,23 @@ def test_probe_to_graphsrv():
3946
group = graphsrv.group.groups.get("probe_b").get("dns")
4047

4148
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"}}

vaping/plugins/__init__.py

+28-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
import collections
2+
import os
13
import abc
24
import copy
35
import datetime
46
import logging
57
import munge
6-
import os
78

89
from future.utils import with_metaclass
910
from vaping.config import parse_interval
@@ -28,6 +29,32 @@ class PluginBase(vaping.io.Thread):
2829
Calls `self.on_start()` and `self.on_stop()` before and after running in
2930
case any connections need to be created or cleaned up.
3031
"""
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+
3158
def init(self):
3259
"""
3360
called after the plugin is initialized, plugin may define this for any

vaping/plugins/command.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,8 @@ def init(self):
3737
if 'command' not in self.config:
3838
raise ValueError('command is required')
3939

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",[]))
4442

4543
self.command = self.config['command']
4644

vaping/plugins/fping.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,9 @@ class FPing(FPingBase):
160160

161161
def init(self):
162162
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",[]))
167166

168167
def probe(self):
169168
msg = self.new_message()

0 commit comments

Comments
 (0)