diff --git a/README.md b/README.md index 4fd55bf..476ff6c 100644 --- a/README.md +++ b/README.md @@ -64,19 +64,19 @@ check_hwgroup --community public --snmp-version 2c --port 1161 --host poseidon2- ```bash check_hwgroup --community public --snmp-version 2c --port 1161 --host poseidon2-3266.internal --warning 1 --critical 1 --contact 1 -[OK] - Poseidon2 3266 SNMP Supervisor v3.8.4 - Contact name: Binary 1, AlarmState: normal, AlarmSetup: active if on|'Binary 1'=0;1;1 +[OK] - Poseidon2 3266 SNMP Supervisor v3.8.4 - Contact name: Binary 1, SensorState: 0, AlarmSetup: active if on|'Binary 1'=0;1;1 ``` ```bash check_hwgroup --community public --snmp-version 1 --port 161 --host damocles-mini.internal --warning 1 --critical 1 --contact 1 -[OK] - Damocles MINI SNMP Supervisor v1.0.11 - Contact name: Input 1, AlarmState: normal, AlarmSetup: inactive|'Input 1'=0;1;1 +[OK] - Damocles MINI SNMP Supervisor v1.0.11 - Contact name: Input 1, SensorState: 0, AlarmSetup: inactive|'Input 1'=0;1;1 ``` How the plugin maps the returned contact states: -- `0`: normal -- `1`: activated +- `0`: 0 +- `1`: 1 - `everything else`: unknown How the plugin maps the returned contact setup: diff --git a/internal/hwgroup/hwgroup.go b/internal/hwgroup/hwgroup.go index 7bd647b..6f864d4 100644 --- a/internal/hwgroup/hwgroup.go +++ b/internal/hwgroup/hwgroup.go @@ -57,10 +57,10 @@ type SensorResult struct { // ContactOutputFields is added to the SensorResult when Contact or Output is requested, // so that we can add the extra information type ContactOutputFields struct { - Value float64 // col 2: current state (0/1) - Name string // col 3: user-defined label - AlarmSetup int // col 4: alarm config index (contact) / type index (output) - AlarmState int // col 5: alarm state index (contact) / mode index (output) + Value float64 // col 2: current state (0/1) + Name string // col 3: user-defined label + AlarmSetup int // col 4: alarm config index (contact) / type index (output) + SensorState int // col 5: sensor state index (contact) / mode index (output) } // ContactString returns a string representation of the state @@ -70,11 +70,11 @@ func (cf *ContactOutputFields) ContactString() string { // From vendor docs: // Current sensor state 0 = normal, 1 = Alarm activated but not send - switch cf.AlarmState { + switch cf.SensorState { case 0: - state = "normal" + state = "0" case 1: - state = "activated" + state = "1" default: state = unknownState } @@ -95,7 +95,7 @@ func (cf *ContactOutputFields) ContactString() string { setup = unknownState } - return fmt.Sprintf("Contact name: %s, AlarmState: %s, AlarmSetup: %s", cf.Name, state, setup) + return fmt.Sprintf("Contact name: %s, SensorState: %s, AlarmSetup: %s", cf.Name, state, setup) } // OutputString returns a string representation of the state @@ -107,7 +107,7 @@ func (cf *ContactOutputFields) OutputString() string { // 0: X/Y = On / Off (Relay output) // 1: X/Y = "On (+10V)" / "Off (-10V)" (RTS output) // 2: X/Y = "On (+10V)" / "Off (0V)" (DTR output) - switch cf.AlarmState { + switch cf.SensorState { case 0: state = "On / Off (Relay output)" case 1: @@ -446,7 +446,7 @@ func (c *Client) getContactOutputFields(table string, devNum int, id uint) (Cont fields.Value = currentState fields.Name = userLabel fields.AlarmSetup = alarmConfig - fields.AlarmState = alarmState + fields.SensorState = alarmState return fields, nil } diff --git a/internal/hwgroup/hwgroup_test.go b/internal/hwgroup/hwgroup_test.go index 530b225..68006d8 100644 --- a/internal/hwgroup/hwgroup_test.go +++ b/internal/hwgroup/hwgroup_test.go @@ -65,9 +65,9 @@ func TestIsSupportedDevice(t *testing.T) { } func TestContactOutputFields_ContactString(t *testing.T) { - cf := ContactOutputFields{Name: "Unit", AlarmState: 0, AlarmSetup: 0} + cf := ContactOutputFields{Name: "Unit", SensorState: 0, AlarmSetup: 0} - expected := "Contact name: Unit, AlarmState: normal, AlarmSetup: active if on" + expected := "Contact name: Unit, SensorState: 0, AlarmSetup: active if on" if actual := cf.ContactString(); actual != expected { t.Errorf("actual: %v, expected: %v", actual, expected) @@ -75,7 +75,7 @@ func TestContactOutputFields_ContactString(t *testing.T) { } func TestContactOutputFields_OutputString(t *testing.T) { - cf := ContactOutputFields{Name: "Unit", AlarmState: 2, AlarmSetup: 3} + cf := ContactOutputFields{Name: "Unit", SensorState: 2, AlarmSetup: 3} expected := "Output name: Unit, Type: On (+10V) / Off (0V) (DTR output), Mode: On if value higher than Trigger"