Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 10 additions & 10 deletions internal/hwgroup/hwgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions internal/hwgroup/hwgroup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@ 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)
}
}

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"

Expand Down