~soren/surveilr/client

« back to all changes in this revision

Viewing changes to surveilr/api/server.py

  • Committer: Tarmac
  • Author(s): Soren Hansen
  • Date: 2011-12-12 10:57:49 UTC
  • mfrom: (13.1.5 plugins)
  • Revision ID: tarmac-20111212105749-rfu6wudnfr3x0ets
PluginĀ serviceĀ support

Show diffs side-by-side

added added

removed removed

Lines of Context:
110
110
        Returns information for the given service"""
111
111
        try:
112
112
            service = models.Service.get(id)
113
 
            return Response({'id': service.key})
 
113
 
 
114
            plugins = [p['url'] for p in getattr(service, 'plugins', [])]
 
115
 
 
116
            return Response(json.dumps({'id': service.key,
 
117
                                        'plugins': plugins}))
114
118
        except riakalchemy.NoSuchObjectError:
115
119
            return HTTPNotFound()
116
120
 
121
125
        models.Service.get(id).delete()
122
126
        return Response('')
123
127
 
 
128
    def update(self, req, id):
 
129
        data = json.loads(req.body)
 
130
 
 
131
        service = models.Service.get(id)
 
132
 
 
133
        # Plugins
 
134
        plugin_states = dict((p['url'], p['saved_state'])
 
135
                                 for p in getattr(service, 'plugins', []))
 
136
 
 
137
        service.plugins = [{'url': url,
 
138
                           'saved_state': plugin_states.get(url, None)}
 
139
                               for url in data['plugins']]
 
140
        service.save()
 
141
        return Response('')
 
142
 
124
143
 
125
144
class MetricController(object):
126
145
    """Routes style controller for actions related to log entries"""
133
152
        service = models.Service.get(service_name)
134
153
        data['service'] = [service]
135
154
        data['timestamp'] = utils.truncate(time.time(), 60)
136
 
        models.LogEntry(**data).save()
 
155
        log_entry = models.LogEntry(**data)
 
156
        log_entry.save()
 
157
        eventlet.spawn_n(utils.enhance_data_point, log_entry)
137
158
        return Response('')
138
159
 
139
160
    def index(self, req, service_name):