Skip to content

Commit c0edbc4

Browse files
Merge pull request jenningsloy318#43 from iceman91176/fix_physical_security
Fix intrusion sensor metric
2 parents 8d9e669 + e7c941b commit c0edbc4

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

collector/chassis_collector.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
ChassisPowerSupplyLabelNames = []string{"resource", "chassis_id", "power_supply", "power_supply_id"}
2121
ChassisNetworkAdapterLabelNames = []string{"resource", "chassis_id", "network_adapter", "network_adapter_id"}
2222
ChassisNetworkPortLabelNames = []string{"resource", "chassis_id", "network_adapter", "network_adapter_id", "network_port", "network_port_id", "network_port_type", "network_port_speed"}
23-
ChassisPhysicalSecurityLabelNames = []string{"resource", "chassis_id", "intrusion_sensor_number", "intrusion_sensor"}
23+
ChassisPhysicalSecurityLabelNames = []string{"resource", "chassis_id", "intrusion_sensor_number", "intrusion_sensor_rearm"}
2424

2525
chassisMetrics = map[string]chassisMetric{
2626
"chassis_health": {
@@ -167,10 +167,10 @@ var (
167167
nil,
168168
),
169169
},
170-
"chassis_physical_security_sensor_rearm_method": {
170+
"chassis_physical_security_sensor_state": {
171171
desc: prometheus.NewDesc(
172-
prometheus.BuildFQName(namespace, ChassisSubsystem, "physical_security_sensor_rearm_method"),
173-
"method that restores this physical security sensor to the normal state, 1()",
172+
prometheus.BuildFQName(namespace, ChassisSubsystem, "physical_security_sensor_state"),
173+
"indicates the known state of the physical security sensor, such as if it is hardware intrusion detected, 1(Normal),2(TamperingDetected),3(HardwareIntrusion)",
174174
ChassisPhysicalSecurityLabelNames,
175175
nil,
176176
),
@@ -323,12 +323,14 @@ func (c *ChassisCollector) Collect(ch chan<- prometheus.Metric) {
323323

324324
physicalSecurity := chassis.PhysicalSecurity
325325
if physicalSecurity != (redfish.PhysicalSecurity{}) {
326-
physicalSecurityIntrusionSensor := fmt.Sprintf("%s", physicalSecurity.IntrusionSensor)
326+
physicalSecurityIntrusionSensor := physicalSecurity.IntrusionSensor
327327
physicalSecurityIntrusionSensorNumber := fmt.Sprintf("%d", physicalSecurity.IntrusionSensorNumber)
328-
physicalSecurityIntrusionSensorReArmMethod := physicalSecurity.IntrusionSensorReArm
329-
if phySecReArmMethod, ok := parsePhySecReArmMethod(physicalSecurityIntrusionSensorReArmMethod); ok {
330-
ChassisPhysicalSecurityLabelValues := []string{"physical_security", chassisID, physicalSecurityIntrusionSensorNumber, physicalSecurityIntrusionSensor}
331-
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_physical_security_sensor_rearm_method"].desc, prometheus.GaugeValue, phySecReArmMethod, ChassisPhysicalSecurityLabelValues...)
328+
physicalSecurityIntrusionSensorReArmMethod := string(physicalSecurity.IntrusionSensorReArm)
329+
330+
if phySecIntrusionSensor, ok := parsePhySecIntrusionSensor(physicalSecurityIntrusionSensor); ok {
331+
ChassisPhysicalSecurityLabelValues := []string{"physical_security", chassisID, physicalSecurityIntrusionSensorNumber, physicalSecurityIntrusionSensorReArmMethod}
332+
ch <- prometheus.MustNewConstMetric(chassisMetrics["chassis_physical_security_sensor_state"].desc, prometheus.GaugeValue, phySecIntrusionSensor, ChassisPhysicalSecurityLabelValues...)
333+
332334
}
333335
}
334336
chassisLogContext.Info("collector scrape completed")

collector/redfish_collector.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,17 @@ func parsePhySecReArmMethod(method redfish.IntrusionSensorReArm) (float64, bool)
202202

203203
return float64(0), false
204204
}
205+
206+
func parsePhySecIntrusionSensor(method redfish.IntrusionSensor) (float64, bool) {
207+
if bytes.Equal([]byte(method), []byte("Normal")) {
208+
return float64(1), true
209+
}
210+
if bytes.Equal([]byte(method), []byte("TamperingDetected")) {
211+
return float64(2), true
212+
}
213+
if bytes.Equal([]byte(method), []byte("HardwareIntrusion")) {
214+
return float64(3), true
215+
}
216+
217+
return float64(0), false
218+
}

0 commit comments

Comments
 (0)