Add scraping of LED status setting
This commit is contained in:
parent
7f045f968c
commit
fce525cad9
2 changed files with 33 additions and 0 deletions
|
|
@ -172,6 +172,17 @@ type CallLogEntry struct {
|
|||
Type string `json:"type"`
|
||||
}
|
||||
|
||||
type LedSettingResponse struct {
|
||||
Error string `json:"error"`
|
||||
Message string `json:"message"`
|
||||
Data *LedData `json:"data"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type LedData struct {
|
||||
Led string `json:"led"`
|
||||
}
|
||||
|
||||
func NewVodafoneStation(stationUrl, password string) *VodafoneStation {
|
||||
cookieJar, err := cookiejar.New(nil)
|
||||
parsedUrl, err := url.Parse(stationUrl)
|
||||
|
|
@ -264,6 +275,15 @@ func (v *VodafoneStation) GetCallLog() (*CallLog, error) {
|
|||
return callLog, nil
|
||||
}
|
||||
|
||||
func (v *VodafoneStation) GetLedSetting() (*LedSettingResponse, error) {
|
||||
responseBody, err := v.doRequest("GET", v.URL+"/api/v1/set_led?_="+strconv.FormatInt(makeTimestamp(), 10), "")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ledSettingResponse := &LedSettingResponse{}
|
||||
return ledSettingResponse, json.Unmarshal(responseBody, ledSettingResponse)
|
||||
}
|
||||
|
||||
func makeTimestamp() int64 {
|
||||
return time.Now().UnixNano() / int64(time.Millisecond)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ var (
|
|||
callEndTimeDesc *prometheus.Desc
|
||||
callStartTimeDesc *prometheus.Desc
|
||||
|
||||
statusLedEnabledDesc *prometheus.Desc
|
||||
|
||||
logoutSuccessDesc *prometheus.Desc
|
||||
logoutMessageDesc *prometheus.Desc
|
||||
)
|
||||
|
|
@ -127,6 +129,8 @@ func init() {
|
|||
callEndTimeDesc = prometheus.NewDesc(prefix+"call_end_time_epoch", "Call endtime as unix epoch", []string{"port", "id", "external_number", "direction", "type"}, nil)
|
||||
callStartTimeDesc = prometheus.NewDesc(prefix+"call_start_time_epoch", "Call starttime as unix epoch", []string{"port", "id", "external_number", "direction", "type"}, nil)
|
||||
|
||||
statusLedEnabledDesc = prometheus.NewDesc(prefix+"status_led_enabled_bool", "Status LEDs", nil, 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)
|
||||
}
|
||||
|
|
@ -185,6 +189,8 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
|
|||
ch <- callEndTimeDesc
|
||||
ch <- callStartTimeDesc
|
||||
|
||||
ch <- statusLedEnabledDesc
|
||||
|
||||
ch <- logoutSuccessDesc
|
||||
ch <- logoutMessageDesc
|
||||
}
|
||||
|
|
@ -297,6 +303,13 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
|
|||
}
|
||||
}
|
||||
|
||||
ledSettingResponse, err := c.Station.GetLedSetting()
|
||||
if err != nil {
|
||||
log.With("error", err.Error()).Error("Failed to get LED setting")
|
||||
} else if ledSettingResponse.Data != nil {
|
||||
ch <- prometheus.MustNewConstMetric(statusLedEnabledDesc, prometheus.GaugeValue, bool2float64(ledSettingResponse.Data.Led == "true"))
|
||||
}
|
||||
|
||||
logoutresponse, err := c.Station.Logout()
|
||||
if logoutresponse != nil {
|
||||
ch <- prometheus.MustNewConstMetric(logoutMessageDesc, prometheus.GaugeValue, 1, logoutresponse.Message)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue