Skip to content

Commit

Permalink
Merge pull request #224 from tomhughes/ex-fans
Browse files Browse the repository at this point in the history
Collect fan status information for EX series switches
  • Loading branch information
czerwonk authored Aug 13, 2023
2 parents d8afe52 + 1487e71 commit 08fdbbc
Show file tree
Hide file tree
Showing 2 changed files with 204 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/features/environment/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const prefix string = "junos_environment_"
var (
temperaturesDesc *prometheus.Desc
powerSupplyDesc *prometheus.Desc
fanStatusDesc *prometheus.Desc
fanAirflowDesc *prometheus.Desc
pemDesc *prometheus.Desc
fanDesc *prometheus.Desc
dcVoltageDesc *prometheus.Desc
Expand All @@ -30,6 +32,8 @@ func init() {
l := []string{"target", "re_name", "item"}
temperaturesDesc = prometheus.NewDesc(prefix+"item_temp", "Temperature of the air flowing past", l, nil)
powerSupplyDesc = prometheus.NewDesc(prefix+"power_up", "Status of power supplies (1 OK, 2 Testing, 3 Failed, 4 Absent, 5 Present)", append(l, "status"), nil)
fanStatusDesc = prometheus.NewDesc(prefix+"fan_up", "Status of fans (1 OK, 2 Testing, 3 Failed, 4 Absent, 5 Present)", append(l, "status"), nil)
fanAirflowDesc = prometheus.NewDesc(prefix+"fan_airflow_up", "Status of fan airflows (1 OK, 2 Testing, 3 Failed, 4 Absent, 5 Present)", append(l, "status"), nil)

pemDesc = prometheus.NewDesc(prefix+"pem_state", "State of PEM module. 1 - Online, 2 - Present, 3 - Empty", append(l, "state"), nil)
dcVoltageDesc = prometheus.NewDesc(prefix+"pem_voltage", "PEM voltage value", l, nil)
Expand Down Expand Up @@ -113,6 +117,13 @@ func (c *environmentCollector) environmentItems(client collector.Client, ch chan
if strings.Contains(item.Name, "Power Supply") || strings.Contains(item.Name, "PEM") {
l = append(l, item.Name, item.Status)
ch <- prometheus.MustNewConstMetric(powerSupplyDesc, prometheus.GaugeValue, float64(statusValues[item.Status]), l...)
} else if strings.Contains(item.Name, "Fan") {
l = append(l, item.Name, item.Status)
if strings.Contains(item.Name, "Airflow") {
ch <- prometheus.MustNewConstMetric(fanAirflowDesc, prometheus.GaugeValue, float64(statusValues[item.Status]), l...)
} else {
ch <- prometheus.MustNewConstMetric(fanStatusDesc, prometheus.GaugeValue, float64(statusValues[item.Status]), l...)
}
} else if item.Temperature != nil {
l = append(l, item.Name)
ch <- prometheus.MustNewConstMetric(temperaturesDesc, prometheus.GaugeValue, item.Temperature.Value, l...)
Expand Down
193 changes: 193 additions & 0 deletions pkg/features/environment/rpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,3 +428,196 @@ func TestParseMultiREOutputSRX(t *testing.T) {
assert.Equal(t, "Power Supply 1", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")
}

func TestParseNoMultiREOutputEX(t *testing.T) {
body := `<rpc-reply xmlns:junos="http://xml.juniper.net/junos/21XXX/junos">
<environment-information xmlns="http://xml.juniper.net/junos/21XXX/junos-chassis">
<environment-item>
<name>FPC 0 Power Supply 0</name>
<class>Power</class>
<status>OK</status>
</environment-item>
<environment-item>
<name>FPC 0 Power Supply 1</name>
<class>Power</class>
<status>OK</status>
</environment-item>
<environment-item>
<name>FPC 1 Power Supply 0</name>
<class>Power</class>
<status>OK</status>
</environment-item>
<environment-item>
<name>FPC 1 Power Supply 1</name>
<class>Power</class>
<status>OK</status>
</environment-item>
<environment-item>
<name>FPC 0 CPU</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="65">65 degrees C / 149 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 NW-PFE</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="48">48 degrees C / 118 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 SE-PFE</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="49">49 degrees C / 120 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 PHY-2/3</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="48">48 degrees C / 118 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 MGMT PHY</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="47">47 degrees C / 116 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 PHY-4/5</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="50">50 degrees C / 122 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 CPU</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="65">65 degrees C / 149 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 NW-PFE</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="46">46 degrees C / 114 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 SE-PFE</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="48">48 degrees C / 118 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 PHY-2/3</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="48">48 degrees C / 118 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 MGMT PHY</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="46">46 degrees C / 114 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 1 PHY-4/5</name>
<class>Temp</class>
<status>OK</status>
<temperature junos:celsius="47">47 degrees C / 116 degrees F</temperature>
</environment-item>
<environment-item>
<name>FPC 0 Fan 0</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>FPC 0 Fan 0 Airflow</name>
<class>Fans</class>
<status>OK</status>
<comment>Airflow Out (AFO)</comment>
</environment-item>
<environment-item>
<name>FPC 0 Fan 1</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>FPC 0 Fan 1 Airflow</name>
<class>Fans</class>
<status>OK</status>
<comment>Airflow Out (AFO)</comment>
</environment-item>
<environment-item>
<name>FPC 1 Fan 0</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>FPC 1 Fan 0 Airflow</name>
<class>Fans</class>
<status>OK</status>
<comment>Airflow Out (AFO)</comment>
</environment-item>
<environment-item>
<name>FPC 1 Fan 1</name>
<class>Fans</class>
<status>OK</status>
<comment>Spinning at normal speed</comment>
</environment-item>
<environment-item>
<name>FPC 1 Fan 1 Airflow</name>
<class>Fans</class>
<status>OK</status>
<comment>Airflow Out (AFO)</comment>
</environment-item>
</environment-information>
<cli>
<banner>{master:0}</banner>
</cli>
</rpc-reply>`

rpc := multiEngineResult{}
err := parseXML([]byte(body), &rpc)

if err != nil {
t.Fatal(err)
}

assert.NotEmpty(t, rpc.Results.RoutingEngines[0].EnvironmentInformation)

assert.Equal(t, "N/A", rpc.Results.RoutingEngines[0].Name, "re-name")

f := rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[0]

assert.Equal(t, "FPC 0 Power Supply 0", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")

f = rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[3]

assert.Equal(t, "FPC 1 Power Supply 1", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")

f = rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[4]

assert.Equal(t, "FPC 0 CPU", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")
assert.Equal(t, float64(65), f.Temperature.Value, "temperature")

f = rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[15]

assert.Equal(t, "FPC 1 PHY-4/5", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")
assert.Equal(t, float64(47), f.Temperature.Value, "temperature")

f = rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[16]

assert.Equal(t, "FPC 0 Fan 0", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")

f = rpc.Results.RoutingEngines[0].EnvironmentInformation.Items[23]

assert.Equal(t, "FPC 1 Fan 1 Airflow", f.Name, "name")
assert.Equal(t, "OK", f.Status, "status")
}

0 comments on commit 08fdbbc

Please sign in to comment.