Add scraping of software component information

This commit is contained in:
fluepke 2020-12-04 21:19:08 +01:00
parent fce525cad9
commit 11b3dc38d3
No known key found for this signature in database
GPG key ID: 37E30BD2FBE7746A
2 changed files with 40 additions and 0 deletions

View file

@ -183,6 +183,22 @@ type LedData struct {
Led string `json:"led"`
}
type StationAboutResponse struct {
Error string `json:"error"`
Message string `json:"message"`
Data *StationAboutData `json:"data"`
}
type StationAboutData struct {
Software []*SoftwareInfo `json:"cosp"`
}
type SoftwareInfo struct {
Name string `json:"name"`
Version string `json:"version"`
License string `json:"license"`
}
func NewVodafoneStation(stationUrl, password string) *VodafoneStation {
cookieJar, err := cookiejar.New(nil)
parsedUrl, err := url.Parse(stationUrl)
@ -284,6 +300,15 @@ func (v *VodafoneStation) GetLedSetting() (*LedSettingResponse, error) {
return ledSettingResponse, json.Unmarshal(responseBody, ledSettingResponse)
}
func (v *VodafoneStation) GetStationAbout() (*StationAboutResponse, error) {
responseBody, err := v.doRequest("GET", v.URL+"/api/v1/sta_about?_="+strconv.FormatInt(makeTimestamp(), 10), "")
if err != nil {
return nil, err
}
stationAboutResponse := &StationAboutResponse{}
return stationAboutResponse, json.Unmarshal(responseBody, stationAboutResponse)
}
func makeTimestamp() int64 {
return time.Now().UnixNano() / int64(time.Millisecond)
}

View file

@ -67,6 +67,8 @@ var (
statusLedEnabledDesc *prometheus.Desc
softwareVersionInfoDesc *prometheus.Desc
logoutSuccessDesc *prometheus.Desc
logoutMessageDesc *prometheus.Desc
)
@ -131,6 +133,8 @@ func init() {
statusLedEnabledDesc = prometheus.NewDesc(prefix+"status_led_enabled_bool", "Status LEDs", nil, nil)
softwareVersionInfoDesc = prometheus.NewDesc(prefix+"software_component_info", "Information about software components", []string{"name", "version", "licsense"}, nil)
logoutSuccessDesc = prometheus.NewDesc(prefix+"logout_success_bool", "1 if the logout was successfull", nil, nil)
logoutMessageDesc = prometheus.NewDesc(prefix+"logout_message_info", "Logout message returned by the web interface", []string{"message"}, nil)
}
@ -191,6 +195,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- statusLedEnabledDesc
ch <- softwareVersionInfoDesc
ch <- logoutSuccessDesc
ch <- logoutMessageDesc
}
@ -310,6 +316,15 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(statusLedEnabledDesc, prometheus.GaugeValue, bool2float64(ledSettingResponse.Data.Led == "true"))
}
stationAboutResponse, err := c.Station.GetStationAbout()
if err != nil {
log.With("error", err.Error()).Error("Failed to get station about information")
} else if stationAboutResponse.Data != nil {
for _, softwareInfo := range stationAboutResponse.Data.Software {
ch <- prometheus.MustNewConstMetric(softwareVersionInfoDesc, prometheus.GaugeValue, 1, softwareInfo.Name, softwareInfo.Version, softwareInfo.License)
}
}
logoutresponse, err := c.Station.Logout()
if logoutresponse != nil {
ch <- prometheus.MustNewConstMetric(logoutMessageDesc, prometheus.GaugeValue, 1, logoutresponse.Message)