Merge lp:~soren/surveilr/plugin-infrastructure into lp:surveilr

Proposed by Soren Hansen
Status: Merged
Approved by: Soren Hansen
Approved revision: 31
Merged at revision: 32
Proposed branch: lp:~soren/surveilr/plugin-infrastructure
Merge into: lp:surveilr
Diff against target: 133 lines (+118/-0)
3 files modified
surveilr/plugins/__init__.py (+19/-0)
surveilr/plugins/base.py (+41/-0)
surveilr/tests/test_plugins.py (+58/-0)
To merge this branch: bzr merge lp:~soren/surveilr/plugin-infrastructure
Reviewer Review Type Date Requested Status
Soren Hansen Pending
Review via email: mp+98114@code.launchpad.net

Commit message

Add basic plugin infrastructure.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'surveilr/plugins'
=== added file 'surveilr/plugins/__init__.py'
--- surveilr/plugins/__init__.py 1970-01-01 00:00:00 +0000
+++ surveilr/plugins/__init__.py 2012-03-18 22:34:17 +0000
@@ -0,0 +1,19 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
020
=== added file 'surveilr/plugins/base.py'
--- surveilr/plugins/base.py 1970-01-01 00:00:00 +0000
+++ surveilr/plugins/base.py 2012-03-18 22:34:17 +0000
@@ -0,0 +1,41 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19"""
20
21import json
22from webob import Response
23from webob.dec import wsgify
24
25
26class SurveilrPlugin(object):
27 def __init__(self, global_config):
28 pass
29
30 @wsgify
31 def __call__(self, req):
32 data = json.loads(req.body)
33 metric = {'timestamp': data['timestamp'],
34 'metrics': data['metrics']}
35 saved_state = data['saved_state']
36 new_saved_state, status = self.run(metric, saved_state)
37 return Response(json.dumps({'state': new_saved_state,
38 'status': status}))
39
40 def run(self, metric, saved_state):
41 return None, None # pragma: nocover
042
=== added file 'surveilr/tests/test_plugins.py'
--- surveilr/tests/test_plugins.py 1970-01-01 00:00:00 +0000
+++ surveilr/tests/test_plugins.py 2012-03-18 22:34:17 +0000
@@ -0,0 +1,58 @@
1"""
2 Surveilr - Log aggregation, analysis and visualisation
3
4 Copyright (C) 2011 Linux2Go
5
6 This program is free software: you can redistribute it and/or
7 modify it under the terms of the GNU Affero General Public License
8 as published by the Free Software Foundation, either version 3 of
9 the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Affero General Public License for more details.
15
16 You should have received a copy of the GNU Affero General Public
17 License along with this program. If not, see
18 <http://www.gnu.org/licenses/>.
19
20 Tests for configuration module
21"""
22
23import json
24from webob import Request
25
26from surveilr import tests
27from surveilr.plugins import base
28
29
30class PluginTests(tests.TestCase):
31 def test_base(self):
32 metrics = {'duration': 85000,
33 'response_size': 12435}
34 timestamp = 13217362355575
35 saved_state = {'what': 'ever',
36 'you': 'prefer'}
37
38 class TestPlugin(base.SurveilrPlugin):
39 def run(self2, metrics_in, saved_state_in):
40 self.assertEquals(metrics_in['metrics'], metrics)
41 self.assertEquals(metrics_in['timestamp'], timestamp)
42 self.assertEquals(saved_state_in, saved_state)
43 return 'New saved state', 'The status'
44
45 test_plugin = TestPlugin({})
46 req = Request.blank('',
47 method='POST',
48 POST=json.dumps({
49 'timestamp': timestamp,
50 'service_id': 'NUD2opa92uFD9JaFefXktCxzEUW',
51 'user_id': 'DYRKd63MjksWEy844DDfFkspwez',
52 'metrics': metrics,
53 'saved_state': saved_state}))
54
55 res = test_plugin(req)
56 res_obj = json.loads(res.body)
57 self.assertEquals(res_obj['status'], 'The status')
58 self.assertEquals(res_obj['state'], 'New saved state')

Subscribers

People subscribed via source and target branches

to all changes: