Skip to content

Commit

Permalink
Closes #1016 : force macro replacement as string
Browse files Browse the repository at this point in the history
  • Loading branch information
mohierf committed Apr 18, 2018
1 parent bc36ee0 commit 9f408cd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion alignak/macroresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def resolve_simple_macros_in_string(self, c_line, data, macromodulations, timepe

# We resolved all we can, now replace the macros in the command call
for macro in macros:
c_line = c_line.replace('$' + macro + '$', macros[macro]['val'])
c_line = c_line.replace('$' + macro + '$', "%s" % (macros[macro]['val']))

# A $$ means we want a $, it's not a macro!
# We replace $$ by a big dirty thing to be sure to not misinterpret it
Expand Down
4 changes: 2 additions & 2 deletions alignak/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ def update_retention(self, forced=False):
brok = make_monitoring_log('INFO', 'RETENTION SAVE: %s' % self.name)
if self.pushed_conf.monitoring_log_broks:
self.add(brok)
logger.info('Retention data saved: %.2f', time.time() - _t0)
logger.info('Retention data saved: %.2f seconds', time.time() - _t0)

def retention_load(self):
"""Call hook point 'load_retention'.
Expand All @@ -1331,7 +1331,7 @@ def retention_load(self):
brok = make_monitoring_log('INFO', 'RETENTION LOAD: %s' % self.name)
if self.pushed_conf.monitoring_log_broks:
self.add(brok)
logger.info('Retention data loaded: %.2f', time.time() - _t0)
logger.info('Retention data loaded: %.2f seconds', time.time() - _t0)

def get_retention_data(self): # pylint: disable=R0912,too-many-statements
"""Get all host and service data in order to store it after
Expand Down
11 changes: 11 additions & 0 deletions test/test_macroresolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,9 @@ def test_host_custom_macros(self):
assert hst.customs is not []
assert '_CUSTOM1' in hst.customs
assert '_CUSTOM2' in hst.customs
# Force declare an integer customs variable
hst.customs['_CUSTOM3'] = 10
print(hst.customs)
data = [hst]

# Parse custom macro to get host custom variables based upon a fixed value
Expand All @@ -731,6 +734,14 @@ def test_host_custom_macros(self):
com = mr.resolve_command(cc, data, self._scheduler.macromodulations, self._scheduler.timeperiods)
assert 'plugins/nothing test_macro_host' == com

# Parse custom macro to get host custom variables based upon another macro
# host has a custom variable defined as _custom2 = $HOSTNAME$
dummy_call = "special_macro!$_HOSTCUSTOM3$"
cc = CommandCall({"commands": self._arbiter.conf.commands, "call": dummy_call})
com = mr.resolve_command(cc, data, self._scheduler.macromodulations, self._scheduler.timeperiods)
print("Command: %s" % com)
assert 'plugins/nothing 10' == com

def test_service_custom_macros(self):
"""
Test on-demand macros with custom variables for services
Expand Down

0 comments on commit 9f408cd

Please sign in to comment.