{ "info": { "author": "Honza Kr\u00e1l", "author_email": "honza.kral@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Programming Language :: Python :: 3.3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy" ], "description": "Elasticsearch Watcher\n=====================\n\nThis is an addon to the official elasticsearch python client that adds\nfunctionality for the Watcher plugin. \n\nInstallation\n------------\n\nYou can install this addon using ``pip``::\n\n pip install elasticsearch-watcher\n\nUsage\n-----\n\nYou can use this client alone:\n\n.. code:: python\n\n from elasticsearch import Elasticsearch\n from elasticsearch_watcher import WatcherClient\n\n client = Elasticsearch()\n watcher = WatcherClient(client)\n\n watcher.get_watch(id=42)\n\nOr you can add the ``watcher`` namespace to the official client to mimic the\nbehaviors of other namespaces:\n\n.. code:: python\n\n WatcherClient.infect_client(client)\n\n client.watcher.get_watch(id=42)\n\nComplex example\n---------------\n\n.. code:: python\n\n from time import sleep\n from datetime import datetime\n from random import randint\n\n from elasticsearch import Elasticsearch\n from elasticsearch_watcher import WatcherClient\n\n # initialize the standard client as usual\n es = Elasticsearch()\n # add the .watcher namespace to it\n WatcherClient.infect_client(es)\n\n # clear the index fiorst\n es.indices.delete(\n index=['alerts', 'test', '.watches', '.watch_history*'], ignore=404)\n\n # get the watcher plugin version\n print('Using watcher', es.watcher.info()['version']['number'])\n\n # Register a new watch\n es.watcher.put_watch(\n id='error_500',\n body={\n # label the watch\n 'metadata': {'tags': ['errors']},\n\n # Run the watch every 10 seconds\n 'trigger': { 'schedule': { 'interval': '10s' } },\n \n # Search for at least 3 documents matching the condition\n 'condition': { 'script': { 'inline': 'ctx.payload.hits.total > 3' } },\n \n # Throttle the watch execution for 30 seconds\n 'throttle_period': '30s',\n \n # The search request to execute\n 'input': {\n 'search': {\n 'request': {\n 'indices': ['test'],\n 'body': {\n 'query': {\n 'filtered': {\n 'query': { 'match': { 'status': 500 } },\n 'filter': { 'range': { 'timestamp': { 'from': '{{ctx.trigger.scheduled_time}}||-5m', 'to': '{{ctx.trigger.triggered_time}}' } } }\n }\n },\n # Return statistics about different hosts\n 'aggregations': {\n 'hosts': { 'terms': { 'field': 'host' } }\n }\n }}}},\n \n # The actions to perform\n 'actions': {\n 'send_email': {\n 'transform': {\n # Transform the data for the template\n 'script': '''return [\n total: ctx.payload.hits.total,\n hosts: ctx.payload.aggregations.hosts.buckets.collect { [ host: it.key, errors: it.doc_count ] },\n errors: ctx.payload.hits.hits.collect { it._source } \n ];'''\n },\n 'email': {\n 'to': 'you@example.com',\n 'subject': '[ALERT] {{ctx.watch_id}}',\n 'attach_data': True,\n 'body': '''\n Received {{ctx.payload.total}} error documents in the last 5 minutes.\n\n Hosts:\n\n {{#ctx.payload.hosts}}* {{host}} ({{errors}})\n {{/ctx.payload.hosts}}'''.replace('\\n'+' '*24, '\\n').strip(),\n }\n },\n 'index_payload': {\n # Transform the data to be stored\n 'transform': { 'script': 'return [ watch_id: ctx.watch_id, payload: ctx.payload ]' },\n 'index': { 'index': 'alerts', 'doc_type': 'alert' }\n },\n 'ping_webhook': {\n 'webhook': {\n 'method': 'POST',\n 'host': 'localhost',\n 'port': 8000,\n 'path': '/',\n 'body': '{\"watch_id\" : \"{{ctx.watch_id}}\", \"payload\" : \"{{ctx.payload}}\"}'\n }\n }\n }\n }\n )\n\n # index documents to trigger the watch\n for _ in range(5):\n es.index(\n index='test',\n doc_type='d',\n body={\n 'timestamp': datetime.utcnow(),\n 'status': 500,\n 'host': '10.0.0.%d' % randint(1, 3)\n }\n )\n\n # wait a bit...\n for _ in range(30):\n sleep(1)\n print('.', sep='', end='', flush=True)\n print()\n\n # display information about watch execution\n print('=' * 80)\n s = es.search(\n index='.watch_history*',\n q='watch_id:error_500',\n sort='trigger_event.schedule.triggered_time:asc'\n )\n for hit in s['hits']['hits']:\n print('%s: %s' % (hit['_id'], hit['_source']['state']))\n\n # delete the watch\n es.watcher.delete_watch(id='error_500', force=True)\n\n\nLicense\n-------\n\nCopyright 2015 Elasticsearch\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/elastic/elasticsearch-watcher-py", "keywords": null, "license": "Apache License, Version 2.0", "maintainer": null, "maintainer_email": null, "name": "elasticsearch-watcher", "package_url": "https://pypi.org/project/elasticsearch-watcher/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/elasticsearch-watcher/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/elastic/elasticsearch-watcher-py" }, "release_url": "https://pypi.org/project/elasticsearch-watcher/0.4.0/", "requires_dist": null, "requires_python": null, "summary": "Python client for Elasticsearch Watcher", "version": "0.4.0" }, "last_serial": 1551843, "releases": { "0.4.0": [ { "comment_text": "", "digests": { "md5": "4669f503c6a3a0fb34b24b0c2a0ee321", "sha256": "d28259e3754436e2065f8bfab51560d56447d7c91664b2c27ce2486b399e1016" }, "downloads": -1, "filename": "elasticsearch_watcher-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4669f503c6a3a0fb34b24b0c2a0ee321", "packagetype": "bdist_wheel", "python_version": "3.3", "requires_python": null, "size": 7713, "upload_time": "2015-05-18T15:24:56", "url": "https://files.pythonhosted.org/packages/72/1c/aaec94953f19233eac7e906e3035c20e17bc53f5001d6de49ac2af253ada/elasticsearch_watcher-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cee0b25bdb9389272ed525cb067fa63c", "sha256": "92d643c6ea93cd3cf5f1ef62ab4ec720dff57c3d99c7c5698959872cc9cdd73e" }, "downloads": -1, "filename": "elasticsearch-watcher-0.4.0.tar.gz", "has_sig": false, "md5_digest": "cee0b25bdb9389272ed525cb067fa63c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4799, "upload_time": "2015-05-18T15:24:53", "url": "https://files.pythonhosted.org/packages/97/46/3823ca1b298c5780951754ff00e48229a85b1f1b0c4da5c089ac8292b68c/elasticsearch-watcher-0.4.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "4669f503c6a3a0fb34b24b0c2a0ee321", "sha256": "d28259e3754436e2065f8bfab51560d56447d7c91664b2c27ce2486b399e1016" }, "downloads": -1, "filename": "elasticsearch_watcher-0.4.0-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "4669f503c6a3a0fb34b24b0c2a0ee321", "packagetype": "bdist_wheel", "python_version": "3.3", "requires_python": null, "size": 7713, "upload_time": "2015-05-18T15:24:56", "url": "https://files.pythonhosted.org/packages/72/1c/aaec94953f19233eac7e906e3035c20e17bc53f5001d6de49ac2af253ada/elasticsearch_watcher-0.4.0-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "cee0b25bdb9389272ed525cb067fa63c", "sha256": "92d643c6ea93cd3cf5f1ef62ab4ec720dff57c3d99c7c5698959872cc9cdd73e" }, "downloads": -1, "filename": "elasticsearch-watcher-0.4.0.tar.gz", "has_sig": false, "md5_digest": "cee0b25bdb9389272ed525cb067fa63c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4799, "upload_time": "2015-05-18T15:24:53", "url": "https://files.pythonhosted.org/packages/97/46/3823ca1b298c5780951754ff00e48229a85b1f1b0c4da5c089ac8292b68c/elasticsearch-watcher-0.4.0.tar.gz" } ] }