Skip to content

Commit 3181744

Browse files
author
Viljar Bauman
committed
fixed bug where watcher was not activated in logstash, added option to type password after execution of script
1 parent 85081fe commit 3181744

File tree

5 files changed

+24
-3
lines changed

5 files changed

+24
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ Python 3 + PIP
2121
```bash
2222
git clone https://github.com/bigbank-as/watchback.git
2323
cd watchback
24-
pip3 install requirements.txt
24+
pip3 install -r requirements.txt
2525
./watchback.py --help
2626
```
2727

2828
## Usage
29+
*For --es_pass argument use - (hypen) if you want to password asked during script execution (prevents password storing in bash/used command history).*
2930

3031
```
3132
$ ./watchback.py --es-ca Corporate_Root_CA.crt \
130 Bytes
Binary file not shown.
3.42 KB
Binary file not shown.

lib/watcherimporter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ def update_elastic(self, watcher_id, watcher_definition):
4444
else:
4545
self.logger.info('Updated watcher %s, it is now version #%d', watcher_id, result.get('_version', 1))
4646

47+
try:
48+
result = self.elastic.xpack.watcher.activate_watch(id=watcher_id)
49+
except RequestError as e:
50+
self.logger.exception('Unable to activate Elasticsearch watcher %s: %s', watcher_id, str(e))
51+
return
52+
4753
def watcher_needs_updating(self, watcher_id, watcher_definition):
4854

4955
"""

watchback.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import sys
55
import argparse
6+
import textwrap
67
from elasticsearch import Elasticsearch
78
from ssl import create_default_context
89
from lib.watcherimporter import WatcherImporter
@@ -40,6 +41,8 @@ def _setup_cli_args():
4041
--watcher-dir=/home/bruce/vigilante/watchlist
4142
4243
""")
44+
45+
4346
parser.add_argument('--watcher-dir', metavar='dirpath', default='watchers',
4447
help='Directory containing watch definitions')
4548
parser.add_argument('--dry-run', default=False, action='store_true',
@@ -48,9 +51,14 @@ def _setup_cli_args():
4851
help='A X509 trusted CA file to use for Elasticsearch HTTPS connections')
4952
parser.add_argument('--es-host', metavar='host', required=True, action='append',
5053
help='Elasticsearch API hostname(s)')
51-
parser.add_argument('--es-user', metavar='user', help='Username for Elasticsearch authentication', nargs='?',
54+
parser.add_argument('--es-user', metavar='user', help='Username for Elasticsearch authentication.', nargs='?',
5255
default=None)
53-
parser.add_argument('--es-pass', metavar='pass', help='Password for Elasticsearch authentication', nargs='?',
56+
parser.add_argument('--es-pass', metavar='pass',
57+
help='''
58+
Password for Elasticsearch authentication.
59+
Use - (hypen) for asking password during script execution.
60+
''',
61+
nargs='?',
5462
default=None)
5563
parser.add_argument('--es-insecure',
5664
help='''
@@ -64,10 +72,16 @@ def _setup_cli_args():
6472
return parser.parse_args()
6573

6674

75+
76+
6777
def main():
6878
args = _setup_cli_args()
6979
logger = _logger_factory()
7080

81+
if args.es_pass == "-":
82+
es_pass = input("Enter your Elasticsearch password or leave empty if you don't use password: ")
83+
args.es_pass = es_pass
84+
7185
if args.es_insecure:
7286
logger.critical('I\'m sorry Dave, I\'m afraid I can\'t do that. ' +
7387
'I just prevented you from shooting your own foot with a ' +

0 commit comments

Comments
 (0)