Check alarm status node: added tenant and ruleChainName to the log to make a log useful in multi-tenant deployments

This commit is contained in:
Sergey Matvienko 2024-03-26 09:04:37 +01:00
parent 2efd411a36
commit add2bea56a
2 changed files with 4 additions and 2 deletions

View File

@ -80,9 +80,9 @@ public class TbCheckAlarmStatusNode implements TbNode {
}, ctx.getDbCallbackExecutor());
} catch (Exception e) {
if (e instanceof IllegalArgumentException || e instanceof NullPointerException) {
log.debug("Failed to parse alarm: [{}] error [{}]", msg.getData(), e.getMessage());
log.debug("[{}][{}] Failed to parse alarm: [{}] error [{}]", ctx.getTenantId(), ctx.getRuleChainName(), msg.getData(), e.getMessage());
} else {
log.error("Failed to parse alarm: [{}]", msg.getData(), e);
log.error("[{}][{}] Failed to parse alarm: [{}]", ctx.getTenantId(), ctx.getRuleChainName(), msg.getData(), e);
}
throw new TbNodeException(e);
}

View File

@ -41,6 +41,7 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@ -163,6 +164,7 @@ class TbCheckAlarmStatusNodeTest {
void givenUnparseableAlarm_whenOnMsg_then_Failure() {
String msgData = "{\"Number\":1113718,\"id\":8.1}";
TbMsg msg = getTbMsg(msgData);
willReturn("Default Rule Chain").given(ctx).getRuleChainName();
assertThatThrownBy(() -> node.onMsg(ctx, msg))
.as("onMsg")