diff --git a/doc/source/webapi/v2/logs.rst b/doc/source/webapi/v2/logs.rst new file mode 100644 index 0000000..798c673 --- /dev/null +++ b/doc/source/webapi/v2/logs.rst @@ -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 \ No newline at end of file diff --git a/doc/source/webapi/v2/status.rst b/doc/source/webapi/v2/status.rst index 20eab7d..782d36e 100644 --- a/doc/source/webapi/v2/status.rst +++ b/doc/source/webapi/v2/status.rst @@ -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/ \ No newline at end of file diff --git a/surveil/api/controllers/v2/logs/__init__.py b/surveil/api/controllers/v2/logs/__init__.py new file mode 100644 index 0000000..80e52f1 --- /dev/null +++ b/surveil/api/controllers/v2/logs/__init__.py @@ -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 diff --git a/surveil/api/controllers/v2/logs/acknowledgements/__init__.py b/surveil/api/controllers/v2/logs/acknowledgements/__init__.py new file mode 100644 index 0000000..d9be54c --- /dev/null +++ b/surveil/api/controllers/v2/logs/acknowledgements/__init__.py @@ -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" \ No newline at end of file diff --git a/surveil/api/controllers/v2/logs/comments/__init__.py b/surveil/api/controllers/v2/logs/comments/__init__.py new file mode 100644 index 0000000..c168c09 --- /dev/null +++ b/surveil/api/controllers/v2/logs/comments/__init__.py @@ -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" \ No newline at end of file diff --git a/surveil/api/controllers/v2/logs/downtimes/__init__.py b/surveil/api/controllers/v2/logs/downtimes/__init__.py new file mode 100644 index 0000000..b66d47c --- /dev/null +++ b/surveil/api/controllers/v2/logs/downtimes/__init__.py @@ -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" \ No newline at end of file diff --git a/surveil/api/controllers/v2/logs/notifications/__init__.py b/surveil/api/controllers/v2/logs/notifications/__init__.py new file mode 100644 index 0000000..8fa1555 --- /dev/null +++ b/surveil/api/controllers/v2/logs/notifications/__init__.py @@ -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" \ No newline at end of file diff --git a/surveil/api/controllers/v2/status/__init__.py b/surveil/api/controllers/v2/status/__init__.py index ed35c82..eb590b5 100644 --- a/surveil/api/controllers/v2/status/__init__.py +++ b/surveil/api/controllers/v2/status/__init__.py @@ -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() diff --git a/surveil/api/controllers/v2/status/hosts/__init__.py b/surveil/api/controllers/v2/status/hosts/__init__.py index 335e055..ceae6f6 100644 --- a/surveil/api/controllers/v2/status/hosts/__init__.py +++ b/surveil/api/controllers/v2/status/hosts/__init__.py @@ -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 diff --git a/surveil/api/controllers/v2/status/hosts/config/__init__.py b/surveil/api/controllers/v2/status/hosts/config/__init__.py new file mode 100644 index 0000000..44bdc75 --- /dev/null +++ b/surveil/api/controllers/v2/status/hosts/config/__init__.py @@ -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" \ No newline at end of file diff --git a/surveil/api/controllers/v2/status/metrics/__init__.py b/surveil/api/controllers/v2/status/metrics/__init__.py new file mode 100644 index 0000000..6e4e32d --- /dev/null +++ b/surveil/api/controllers/v2/status/metrics/__init__.py @@ -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 \ No newline at end of file diff --git a/surveil/api/controllers/v2/v2.py b/surveil/api/controllers/v2/v2.py index 02c672c..e59f493 100644 --- a/surveil/api/controllers/v2/v2.py +++ b/surveil/api/controllers/v2/v2.py @@ -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()