Skip to content

Commit

Permalink
Merge pull request #46825 from AAbouZaid/kapacitor_enhancements
Browse files Browse the repository at this point in the history
Follow up Kapacitor module enhancements.
  • Loading branch information
Mike Place committed Apr 16, 2018
2 parents 3a22f72 + 4d96de6 commit 5852993
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
23 changes: 18 additions & 5 deletions salt/modules/kapacitor.py
Expand Up @@ -6,15 +6,21 @@
parameters or as configuration settings in /etc/salt/minion on the relevant
minions::
kapacitor.unsafe_ssl: 'false'
kapacitor.protocol: 'http'
kapacitor.host: 'localhost'
kapacitor.port: 9092
.. versionadded:: 2016.11.0
Also protocol and SSL settings could be configured::
kapacitor.unsafe_ssl: 'false'
kapacitor.protocol: 'http'
.. versionadded:: Fluorine
This data can also be passed into pillar. Options passed into opts will
overwrite options passed into pillar.
.. versionadded:: 2016.11.0
'''
# Import Python libs
from __future__ import absolute_import, print_function, unicode_literals
Expand All @@ -25,6 +31,10 @@
import salt.utils.json
import salt.utils.path
from salt.utils.decorators import memoize
import logging as logger

# Setup the logger
log = logger.getLogger(__name__)


def __virtual__():
Expand Down Expand Up @@ -142,8 +152,7 @@ def define_task(name,
.. versionadded:: Fluorine
database
Which database to fetch data from. Defaults to None, which will use the
default database in InfluxDB.
Which database to fetch data from.
retention_policy
Which retention policy to fetch data from. Defaults to 'default'.
Expand All @@ -154,6 +163,10 @@ def define_task(name,
salt '*' kapacitor.define_task cpu salt://kapacitor/cpu.tick database=telegraf
'''
if not database and not dbrps:
log.error("Providing database name or dbrps is mandatory.")
return False

if version() < '0.13':
cmd = 'kapacitor define -name {0}'.format(name)
else:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/modules/test_kapacitor.py
Expand Up @@ -53,9 +53,9 @@ def test_get_task_not_found(self):
def test_define_task(self):
cmd_mock = Mock(return_value={'retcode': 0})
with patch.dict(kapacitor.__salt__, {'cmd.run_all': cmd_mock}):
kapacitor.define_task('taskname', '/tmp/script.tick')
kapacitor.define_task('taskname', '/tmp/script.tick', dbrps=['db.rp'])
cmd_mock.assert_called_once_with('kapacitor define taskname '
'-tick /tmp/script.tick -type stream', env=self.__class__.env)
'-tick /tmp/script.tick -type stream -dbrp db.rp', env=self.__class__.env)

def test_enable_task(self):
cmd_mock = Mock(return_value={'retcode': 0})
Expand Down

0 comments on commit 5852993

Please sign in to comment.