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
1=== added directory 'surveilr/plugins'
2=== added file 'surveilr/plugins/__init__.py'
3--- surveilr/plugins/__init__.py 1970-01-01 00:00:00 +0000
4+++ surveilr/plugins/__init__.py 2012-03-18 22:34:17 +0000
5@@ -0,0 +1,19 @@
6+"""
7+ Surveilr - Log aggregation, analysis and visualisation
8+
9+ Copyright (C) 2011 Linux2Go
10+
11+ This program is free software: you can redistribute it and/or
12+ modify it under the terms of the GNU Affero General Public License
13+ as published by the Free Software Foundation, either version 3 of
14+ the License, or (at your option) any later version.
15+
16+ This program is distributed in the hope that it will be useful,
17+ but WITHOUT ANY WARRANTY; without even the implied warranty of
18+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+ GNU Affero General Public License for more details.
20+
21+ You should have received a copy of the GNU Affero General Public
22+ License along with this program. If not, see
23+ <http://www.gnu.org/licenses/>.
24+"""
25
26=== added file 'surveilr/plugins/base.py'
27--- surveilr/plugins/base.py 1970-01-01 00:00:00 +0000
28+++ surveilr/plugins/base.py 2012-03-18 22:34:17 +0000
29@@ -0,0 +1,41 @@
30+"""
31+ Surveilr - Log aggregation, analysis and visualisation
32+
33+ Copyright (C) 2011 Linux2Go
34+
35+ This program is free software: you can redistribute it and/or
36+ modify it under the terms of the GNU Affero General Public License
37+ as published by the Free Software Foundation, either version 3 of
38+ the License, or (at your option) any later version.
39+
40+ This program is distributed in the hope that it will be useful,
41+ but WITHOUT ANY WARRANTY; without even the implied warranty of
42+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
43+ GNU Affero General Public License for more details.
44+
45+ You should have received a copy of the GNU Affero General Public
46+ License along with this program. If not, see
47+ <http://www.gnu.org/licenses/>.
48+"""
49+
50+import json
51+from webob import Response
52+from webob.dec import wsgify
53+
54+
55+class SurveilrPlugin(object):
56+ def __init__(self, global_config):
57+ pass
58+
59+ @wsgify
60+ def __call__(self, req):
61+ data = json.loads(req.body)
62+ metric = {'timestamp': data['timestamp'],
63+ 'metrics': data['metrics']}
64+ saved_state = data['saved_state']
65+ new_saved_state, status = self.run(metric, saved_state)
66+ return Response(json.dumps({'state': new_saved_state,
67+ 'status': status}))
68+
69+ def run(self, metric, saved_state):
70+ return None, None # pragma: nocover
71
72=== added file 'surveilr/tests/test_plugins.py'
73--- surveilr/tests/test_plugins.py 1970-01-01 00:00:00 +0000
74+++ surveilr/tests/test_plugins.py 2012-03-18 22:34:17 +0000
75@@ -0,0 +1,58 @@
76+"""
77+ Surveilr - Log aggregation, analysis and visualisation
78+
79+ Copyright (C) 2011 Linux2Go
80+
81+ This program is free software: you can redistribute it and/or
82+ modify it under the terms of the GNU Affero General Public License
83+ as published by the Free Software Foundation, either version 3 of
84+ the License, or (at your option) any later version.
85+
86+ This program is distributed in the hope that it will be useful,
87+ but WITHOUT ANY WARRANTY; without even the implied warranty of
88+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89+ GNU Affero General Public License for more details.
90+
91+ You should have received a copy of the GNU Affero General Public
92+ License along with this program. If not, see
93+ <http://www.gnu.org/licenses/>.
94+
95+ Tests for configuration module
96+"""
97+
98+import json
99+from webob import Request
100+
101+from surveilr import tests
102+from surveilr.plugins import base
103+
104+
105+class PluginTests(tests.TestCase):
106+ def test_base(self):
107+ metrics = {'duration': 85000,
108+ 'response_size': 12435}
109+ timestamp = 13217362355575
110+ saved_state = {'what': 'ever',
111+ 'you': 'prefer'}
112+
113+ class TestPlugin(base.SurveilrPlugin):
114+ def run(self2, metrics_in, saved_state_in):
115+ self.assertEquals(metrics_in['metrics'], metrics)
116+ self.assertEquals(metrics_in['timestamp'], timestamp)
117+ self.assertEquals(saved_state_in, saved_state)
118+ return 'New saved state', 'The status'
119+
120+ test_plugin = TestPlugin({})
121+ req = Request.blank('',
122+ method='POST',
123+ POST=json.dumps({
124+ 'timestamp': timestamp,
125+ 'service_id': 'NUD2opa92uFD9JaFefXktCxzEUW',
126+ 'user_id': 'DYRKd63MjksWEy844DDfFkspwez',
127+ 'metrics': metrics,
128+ 'saved_state': saved_state}))
129+
130+ res = test_plugin(req)
131+ res_obj = json.loads(res.body)
132+ self.assertEquals(res_obj['status'], 'The status')
133+ self.assertEquals(res_obj['state'], 'New saved state')

Subscribers

People subscribed via source and target branches

to all changes: