FIX opnsense_server_ha_state metric
I've forgot to implement the main part calling state() on metric
This commit is contained in:
parent
98f832ec3b
commit
bea721a275
3 changed files with 121 additions and 29 deletions
|
@ -104,7 +104,12 @@ You can setup env through `.env` file or environment variables with defined as d
|
|||
|
||||
## Changelog
|
||||
|
||||
### Version 0.5.0 (UNRELEASED)
|
||||
### Version 0.5.1 (2023-09-01)
|
||||
|
||||
- FIX `opnsense_server_ha_state` calls were not
|
||||
implemented
|
||||
|
||||
### Version 0.5.0 (2023-09-01)
|
||||
|
||||
- add role label in metrics
|
||||
- all to configure supervised interfaces using `--opnsense-interfaces`
|
||||
|
|
|
@ -91,6 +91,12 @@ class OPNSensePrometheusExporter:
|
|||
backup_ha_state.labels(
|
||||
instance=self.exporter_instance, **self.backup.labels
|
||||
).state(backup_sate.value)
|
||||
opnsense_server_ha_state.labels(
|
||||
instance=self.exporter_instance, **self.main.labels
|
||||
).state(main_state.value)
|
||||
opnsense_server_ha_state.labels(
|
||||
instance=self.exporter_instance, **self.backup.labels
|
||||
).state(backup_sate.value)
|
||||
active_opnsense = None
|
||||
if main_state == OPNSenseHAState.ACTIVE:
|
||||
active_opnsense = self.main
|
||||
|
|
|
@ -125,11 +125,16 @@ def test_process_requests():
|
|||
|
||||
main_ha_state_mock = FakePromEnum()
|
||||
backup_ha_state_mock = FakePromEnum()
|
||||
opnsense_server_ha_state_mock = FakePromEnum()
|
||||
opnsense_active_server_traffic_rate_mock = FakePromGauge()
|
||||
|
||||
with mock.patch("opnsense_exporter.server.main_ha_state", new=main_ha_state_mock):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.backup_ha_state", new=backup_ha_state_mock
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_server_ha_state",
|
||||
new=opnsense_server_ha_state_mock,
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_active_server_traffic_rate",
|
||||
|
@ -141,6 +146,20 @@ def test_process_requests():
|
|||
"wan",
|
||||
).process_requests()
|
||||
|
||||
assert opnsense_server_ha_state_mock.count_state_calls == 2
|
||||
assert opnsense_server_ha_state_mock._labels_calls == [
|
||||
{
|
||||
"instance": "",
|
||||
"host": MAIN_HOST,
|
||||
"role": "main",
|
||||
},
|
||||
{
|
||||
"instance": "",
|
||||
"host": BACKUP_HOST,
|
||||
"role": "backup",
|
||||
},
|
||||
]
|
||||
assert opnsense_server_ha_state_mock._state_calls == ["active", "hot_standby"]
|
||||
assert main_ha_state_mock._state == "active"
|
||||
assert main_ha_state_mock.count_state_calls == 1, main_ha_state_mock._state_calls
|
||||
assert main_ha_state_mock._labels == {
|
||||
|
@ -197,11 +216,16 @@ def test_process_requests_backup_active():
|
|||
|
||||
main_ha_state_mock = FakePromEnum()
|
||||
backup_ha_state_mock = FakePromEnum()
|
||||
opnsense_server_ha_state_mock = FakePromEnum()
|
||||
opnsense_active_server_traffic_rate_mock = FakePromGauge()
|
||||
|
||||
with mock.patch("opnsense_exporter.server.main_ha_state", new=main_ha_state_mock):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.backup_ha_state", new=backup_ha_state_mock
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_server_ha_state",
|
||||
new=opnsense_server_ha_state_mock,
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_active_server_traffic_rate",
|
||||
|
@ -212,6 +236,21 @@ def test_process_requests_backup_active():
|
|||
OPNSenseAPI(OPNSenseRole.BACKUP, BACKUP_HOST, LOGIN, PASSWORD),
|
||||
"wan",
|
||||
).process_requests()
|
||||
|
||||
assert opnsense_server_ha_state_mock.count_state_calls == 2
|
||||
assert opnsense_server_ha_state_mock._labels_calls == [
|
||||
{
|
||||
"instance": "",
|
||||
"host": MAIN_HOST,
|
||||
"role": "main",
|
||||
},
|
||||
{
|
||||
"instance": "",
|
||||
"host": BACKUP_HOST,
|
||||
"role": "backup",
|
||||
},
|
||||
]
|
||||
assert opnsense_server_ha_state_mock._state_calls == ["maintenancemode", "active"]
|
||||
assert main_ha_state_mock._state == "maintenancemode"
|
||||
assert main_ha_state_mock.count_state_calls == 1
|
||||
assert main_ha_state_mock._labels == {
|
||||
|
@ -269,11 +308,16 @@ def test_process_no_active():
|
|||
|
||||
main_ha_state_mock = FakePromEnum()
|
||||
backup_ha_state_mock = FakePromEnum()
|
||||
opnsense_server_ha_state_mock = FakePromEnum()
|
||||
opnsense_active_server_traffic_rate_mock = FakePromGauge()
|
||||
|
||||
with mock.patch("opnsense_exporter.server.main_ha_state", new=main_ha_state_mock):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.backup_ha_state", new=backup_ha_state_mock
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_server_ha_state",
|
||||
new=opnsense_server_ha_state_mock,
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_active_server_traffic_rate",
|
||||
|
@ -285,6 +329,23 @@ def test_process_no_active():
|
|||
"wan",
|
||||
).process_requests()
|
||||
|
||||
assert opnsense_server_ha_state_mock.count_state_calls == 2
|
||||
assert opnsense_server_ha_state_mock._labels_calls == [
|
||||
{
|
||||
"instance": "",
|
||||
"host": MAIN_HOST,
|
||||
"role": "main",
|
||||
},
|
||||
{
|
||||
"instance": "",
|
||||
"host": BACKUP_HOST,
|
||||
"role": "backup",
|
||||
},
|
||||
]
|
||||
assert opnsense_server_ha_state_mock._state_calls == [
|
||||
"maintenancemode",
|
||||
"unavailable",
|
||||
]
|
||||
assert main_ha_state_mock._state == "maintenancemode"
|
||||
assert main_ha_state_mock.count_state_calls == 1
|
||||
assert main_ha_state_mock._labels == {
|
||||
|
@ -325,11 +386,16 @@ def test_process_with_falsy_value():
|
|||
|
||||
main_ha_state_mock = FakePromEnum()
|
||||
backup_ha_state_mock = FakePromEnum()
|
||||
opnsense_server_ha_state_mock = FakePromEnum()
|
||||
opnsense_active_server_traffic_rate_mock = FakePromGauge()
|
||||
|
||||
with mock.patch("opnsense_exporter.server.main_ha_state", new=main_ha_state_mock):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.backup_ha_state", new=backup_ha_state_mock
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_server_ha_state",
|
||||
new=opnsense_server_ha_state_mock,
|
||||
):
|
||||
with mock.patch(
|
||||
"opnsense_exporter.server.opnsense_active_server_traffic_rate",
|
||||
|
@ -340,6 +406,21 @@ def test_process_with_falsy_value():
|
|||
OPNSenseAPI(OPNSenseRole.BACKUP, BACKUP_HOST, LOGIN, PASSWORD),
|
||||
"wan",
|
||||
).process_requests()
|
||||
|
||||
assert opnsense_server_ha_state_mock.count_state_calls == 2
|
||||
assert opnsense_server_ha_state_mock._labels_calls == [
|
||||
{
|
||||
"instance": "",
|
||||
"host": MAIN_HOST,
|
||||
"role": "main",
|
||||
},
|
||||
{
|
||||
"instance": "",
|
||||
"host": BACKUP_HOST,
|
||||
"role": "backup",
|
||||
},
|
||||
]
|
||||
assert opnsense_server_ha_state_mock._state_calls == ["active", "hot_standby"]
|
||||
assert main_ha_state_mock._state == "active"
|
||||
assert main_ha_state_mock.count_state_calls == 1
|
||||
assert main_ha_state_mock._labels == {
|
||||
|
|
Loading…
Reference in a new issue