Skip to content

Commit

Permalink
Merge pull request #524 from sentrysoftware/feature/issue-523-hwnetwo…
Browse files Browse the repository at this point in the history
…rkup-metric-not-reported-for-connectors-with-link-state-as-warn-or-alarm

Issue #523: hw.network.up metric not reported for WARN or ALARM states
  • Loading branch information
NassimBtk authored Dec 18, 2024
2 parents 34a3132 + 6271201 commit 55e55ba
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ public enum LinkStatus implements IState {
"failed",
UNPLUGGED,
"unplugged",
UNPLUGGED,
"warn",
UNPLUGGED,
"alarm",
UNPLUGGED
);

/**
* Interpret the specified state value:
* <ul>
* <li>{0, ok, plugged} as Plugged</li>
* <li>{1, degraded, failed, 2, unplugged} as Unplugged</li>
* <li>{1, degraded, failed, 2, unplugged, warn, alarm} as Unplugged</li>
* </ul>
* @param state String to be interpreted
* @return {@link Optional} of {@link LinkStatus}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.sentrysoftware.metricshub.engine.common.helpers.state;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;

class LinkStatusTest {

@Test
void testInterpret() {
// {0, ok, plugged} as Plugged
final String[] pluggedStates = new String[] { "PLUGGED", "OK", "plugged", "ok", "0" };
for (String state : pluggedStates) {
assertEquals(
LinkStatus.PLUGGED,
LinkStatus.interpret(state).get(),
"Unexpected plugged state: %s".formatted(state)
);
}

// {1, degraded, failed, 2, unplugged, warn, alarm} as Unplugged
final String[] unpluggedStates = new String[] {
"UNPLUGGED",
"DEGRADED",
"FAILED",
"WARN",
"ALARM",
"unplugged",
"degraded",
"failed",
"unplugged",
"warn",
"alarm",
"1",
"2"
};
for (String state : unpluggedStates) {
assertEquals(
LinkStatus.UNPLUGGED,
LinkStatus.interpret(state).get(),
"Unexpected unplugged state: %s".formatted(state)
);
}
}
}

0 comments on commit 55e55ba

Please sign in to comment.