diff --git a/libra/statsd/drivers/base.py b/libra/statsd/drivers/base.py index 8daede0f..15dd0262 100644 --- a/libra/statsd/drivers/base.py +++ b/libra/statsd/drivers/base.py @@ -12,7 +12,8 @@ # License for the specific language governing permissions and limitations known_drivers = { - 'dummy': 'libra.statsd.drivers.dummy.driver.DummyDriver' + 'dummy': 'libra.statsd.drivers.dummy.driver.DummyDriver', + 'datadog': 'libra.statsd.driver.dummy.driver.DatadogDriver' } diff --git a/libra/statsd/drivers/datadog/__init__.py b/libra/statsd/drivers/datadog/__init__.py new file mode 100644 index 00000000..92bd912f --- /dev/null +++ b/libra/statsd/drivers/datadog/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# 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. diff --git a/libra/statsd/drivers/datadog/driver.py b/libra/statsd/drivers/datadog/driver.py new file mode 100644 index 00000000..3d84431a --- /dev/null +++ b/libra/statsd/drivers/datadog/driver.py @@ -0,0 +1,27 @@ +# Copyright 2013 Hewlett-Packard Development Company, L.P. +# +# 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 + +from libra.statsd.drivers.base import AlertDriver +from dogapi import dog_http_api as api + + +class DatadogDriver(AlertDriver): + def send_alert(self, message): + api.api_key = self.args.datadog_apikey + api.application_key = self.args.datadog_appkey + title = 'Load balancer failure' + text = 'Load balancer failed with message {0} {1}'.format( + message, self.args.datadog_message_tail + ) + tags = self.args.datadog_tags.split() + api.event_with_response(title, text, tags=tags, alert_type='error') diff --git a/libra/statsd/main.py b/libra/statsd/main.py index 36d4e85c..336e5726 100644 --- a/libra/statsd/main.py +++ b/libra/statsd/main.py @@ -59,6 +59,21 @@ def main(): '--api_server', action='append', metavar='HOST:PORT', default=[], help='a list of API servers to connect to' ) + # Datadog plugin options + options.parser.add_argument( + '--datadog_api_key', help='API key for datadog alerting' + ) + options.parser.add_argument( + '--datadog_app_key', help='Application key for datadog alerting' + ) + options.parser.add_argument( + '--datadog_message_tail', + help='Text to add at the end of a Datadog alert' + ) + options.parser.add_argument( + '--datadog_tags', + help='A space separated list of tags for Datadog alerts' + ) args = options.run()