Add: Api v2 layout
Change-Id: Ie7c83533075e4b329088a8f0cc8fff914cb5c2d3
This commit is contained in:
parent
839b5a48f7
commit
8bf1a7488e
36
doc/source/webapi/v2/logs.rst
Normal file
36
doc/source/webapi/v2/logs.rst
Normal file
@ -0,0 +1,36 @@
|
||||
.. docbookrestapi
|
||||
|
||||
====
|
||||
Logs
|
||||
====
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs:LogsController
|
||||
:webprefix: /v2/logs
|
||||
|
||||
|
||||
Acknowledgements
|
||||
================
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.acknowledgements:AcknowledgementsController
|
||||
:webprefix: /v2/logs/acknowledgements
|
||||
|
||||
|
||||
Comments
|
||||
========
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.comments:CommentsController
|
||||
:webprefix: /v2/logs/comments
|
||||
|
||||
|
||||
Downtimes
|
||||
=========
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.downtimes:DowntimesController
|
||||
:webprefix: /v2/logs/downtimes
|
||||
|
||||
|
||||
Notifications
|
||||
=============
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.notifications:NotificationsController
|
||||
:webprefix: /v2/logs/notifications
|
@ -14,5 +14,35 @@ Hosts
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.hosts:HostsController
|
||||
:webprefix: /v2/status/hosts
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.hosts:HostController
|
||||
:webprefix: /v2/status/hosts/
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.hosts.config:ConfigController
|
||||
:webprefix: /v2/status/hosts/(host_name)/config
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.metrics:MetricsController
|
||||
:webprefix: /v2/status/hosts/(host_name)/metrics
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs:LogsController
|
||||
:webprefix: /v2/status/hosts/(host_name)/events
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.acknowledgements:AcknowledgementsController
|
||||
:webprefix: /v2/status/hosts/(host_name)/events/acknowledgements
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.comments:CommentsController
|
||||
:webprefix: /v2/status/hosts/(host_name)/events/comments
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.downtimes:DowntimesController
|
||||
:webprefix: /v2/status/hosts/(host_name)/events/downtimes
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.logs.notifications:NotificationsController
|
||||
:webprefix: /v2/status/hosts/(host_name)/events/notifications
|
||||
|
||||
Metrics
|
||||
=======
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.metrics:MetricsController
|
||||
:webprefix: /v2/status/metrics
|
||||
|
||||
.. rest-controller:: surveil.api.controllers.v2.status.metrics:MetricController
|
||||
:webprefix: /v2/status/metrics/
|
42
surveil/api/controllers/v2/logs/__init__.py
Normal file
42
surveil/api/controllers/v2/logs/__init__.py
Normal file
@ -0,0 +1,42 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
from surveil.api.controllers.v2.logs import acknowledgements
|
||||
from surveil.api.controllers.v2.logs import comments
|
||||
from surveil.api.controllers.v2.logs import downtimes
|
||||
from surveil.api.controllers.v2.logs import notifications
|
||||
|
||||
|
||||
class LogsController(rest.RestController):
|
||||
acknowledgements = acknowledgements.AcknowledgementsController()
|
||||
comments = comments.CommentsController()
|
||||
downtimes = downtimes.DowntimesController()
|
||||
notifications = notifications.NotificationsController()
|
||||
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all events from a specific host."""
|
||||
host_name = pecan.request.context.get("host_name")
|
||||
if host_name is not None:
|
||||
return "All events for %s" % host_name
|
||||
return "ALLL Events"
|
||||
|
||||
# @pecan.expose()
|
||||
# def _lookup(self, host_name, *remainder):
|
||||
# return EventController(host_name), remainder
|
26
surveil/api/controllers/v2/logs/acknowledgements/__init__.py
Normal file
26
surveil/api/controllers/v2/logs/acknowledgements/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class AcknowledgementsController(rest.RestController):
|
||||
|
||||
# curl -X GET http://127.0.0.1:8080/v2/titilambert/myproject/builds/
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all acks from a specific host."""
|
||||
return "ALLL ACK"
|
26
surveil/api/controllers/v2/logs/comments/__init__.py
Normal file
26
surveil/api/controllers/v2/logs/comments/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class CommentsController(rest.RestController):
|
||||
|
||||
# curl -X GET http://127.0.0.1:8080/v2/titilambert/myproject/builds/
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all comments from a specific host."""
|
||||
return "ALLL Comments"
|
26
surveil/api/controllers/v2/logs/downtimes/__init__.py
Normal file
26
surveil/api/controllers/v2/logs/downtimes/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class DowntimesController(rest.RestController):
|
||||
|
||||
# curl -X GET http://127.0.0.1:8080/v2/titilambert/myproject/builds/
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all downtimes from a specific host."""
|
||||
return "ALLL DT"
|
26
surveil/api/controllers/v2/logs/notifications/__init__.py
Normal file
26
surveil/api/controllers/v2/logs/notifications/__init__.py
Normal file
@ -0,0 +1,26 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class NotificationsController(rest.RestController):
|
||||
|
||||
# curl -X GET http://127.0.0.1:8080/v2/titilambert/myproject/builds/
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all notifications from a specific host."""
|
||||
return "ALLL notifs"
|
@ -15,10 +15,11 @@
|
||||
from pecan import rest
|
||||
|
||||
from surveil.api.controllers.v2.status import hosts as v2_hosts
|
||||
from surveil.api.controllers.v2.status import metrics
|
||||
|
||||
|
||||
class StatusController(rest.RestController):
|
||||
# events = EventsController()
|
||||
hosts = v2_hosts.HostsController()
|
||||
# services = ServicesController()
|
||||
# metrics = MetricsController()
|
||||
metrics = metrics.MetricsController()
|
||||
|
@ -15,25 +15,40 @@
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
from surveil.api.controllers.v2 import logs
|
||||
from surveil.api.controllers.v2.status.hosts import config
|
||||
from surveil.api.controllers.v2.status import metrics
|
||||
|
||||
|
||||
class HostsController(rest.RestController):
|
||||
|
||||
# curl -X GET http://127.0.0.1:8080/v2/titilambert/myproject/builds/
|
||||
# @wsme_pecan.wsexpose([Host])
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all hosts with filters ???"""
|
||||
pass
|
||||
"""Returns all hosts."""
|
||||
return "ALLL HOSSSSSSSST"
|
||||
|
||||
@pecan.expose()
|
||||
def _lookup(self, host_id, *remainder):
|
||||
return HostController(host_id), remainder
|
||||
def _lookup(self, host_name, *remainder):
|
||||
return HostController(host_name), remainder
|
||||
|
||||
|
||||
class HostController(rest.RestController):
|
||||
# events = EventsController()
|
||||
# config = ConfigController()
|
||||
|
||||
# services = ServicesController()
|
||||
# metrics = MetricsController()
|
||||
# See init for controller creation. We need host_name to instanciate it
|
||||
# externalcommands = ExternalCommandsController()
|
||||
pass
|
||||
config = config.ConfigController()
|
||||
events = logs.LogsController()
|
||||
metrics = metrics.MetricsController()
|
||||
|
||||
def __init__(self, host_name):
|
||||
pecan.request.context['host_name'] = host_name
|
||||
self._id = host_name
|
||||
|
||||
@pecan.expose()
|
||||
def get(self):
|
||||
"""Returns a specific host."""
|
||||
|
||||
output = '{"host_name": "myhostname", "alias": %s}' % self._id
|
||||
|
||||
return output
|
||||
|
24
surveil/api/controllers/v2/status/hosts/config/__init__.py
Normal file
24
surveil/api/controllers/v2/status/hosts/config/__init__.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class ConfigController(rest.RestController):
|
||||
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns config from a specific host."""
|
||||
return "Dump CONFIG"
|
63
surveil/api/controllers/v2/status/metrics/__init__.py
Normal file
63
surveil/api/controllers/v2/status/metrics/__init__.py
Normal file
@ -0,0 +1,63 @@
|
||||
# Copyright 2014 - Savoir-Faire Linux inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import pecan
|
||||
from pecan import rest
|
||||
|
||||
|
||||
class MetricsController(rest.RestController):
|
||||
|
||||
@pecan.expose()
|
||||
def get_all(self):
|
||||
"""Returns all metrics."""
|
||||
host_name = pecan.request.context.get("host_name")
|
||||
if host_name is not None:
|
||||
return '{"host_name": "%s", "metrics" : "22"}' % host_name
|
||||
|
||||
return '{"host_name": "NOHOSTNAME", "metrics" : "22"}'
|
||||
|
||||
@pecan.expose()
|
||||
def _lookup(self, *args):
|
||||
props = {}
|
||||
leftovers = list(args)
|
||||
# print leftovers
|
||||
for attr in ["host_name", "service_description", "metric"]:
|
||||
value = pecan.request.context.get(attr)
|
||||
if value is not None:
|
||||
props[attr] = value
|
||||
else:
|
||||
if len(leftovers) > 0:
|
||||
props[attr] = leftovers[0]
|
||||
leftovers.pop(0)
|
||||
else:
|
||||
props[attr] = None
|
||||
|
||||
return MetricController(**props), leftovers
|
||||
|
||||
|
||||
class MetricController(rest.RestController):
|
||||
|
||||
def __init__(self, host_name, service_description=None, metric=None):
|
||||
self._id = host_name
|
||||
self.sd = service_description
|
||||
self.metric = metric
|
||||
|
||||
@pecan.expose()
|
||||
def get(self):
|
||||
"""Returns (specific) metrics."""
|
||||
|
||||
output = '{"hn": %s, "sd": %s, "metric":%s}' % (
|
||||
self._id, self.sd, self.metric)
|
||||
|
||||
return output
|
@ -16,6 +16,7 @@ from surveil.api.controllers.v2 import actions as v2_actions
|
||||
from surveil.api.controllers.v2 import admin as v2_admin
|
||||
from surveil.api.controllers.v2 import auth as v2_auth
|
||||
from surveil.api.controllers.v2 import config as v2_config
|
||||
from surveil.api.controllers.v2 import logs as v2_logs
|
||||
from surveil.api.controllers.v2 import status as v2_status
|
||||
|
||||
|
||||
@ -26,3 +27,4 @@ class V2Controller(object):
|
||||
status = v2_status.StatusController()
|
||||
surveil = v2_admin.AdminController()
|
||||
auth = v2_auth.AuthController()
|
||||
logs = v2_logs.LogsController()
|
||||
|
Loading…
x
Reference in New Issue
Block a user