add WanStatus

This commit is contained in:
MaxPeal 2022-06-20 05:09:30 +02:00 committed by Ruben Jenster
parent cd742fe7b6
commit 5285dddf4b
2 changed files with 74 additions and 0 deletions

View file

@ -146,6 +146,17 @@ type StationStatusData struct {
IpPrefixClass string `json:"IpPrefixClass"` IpPrefixClass string `json:"IpPrefixClass"`
} }
type WanStatusData struct {
Ipv4 string `json:"ipv4"`
Mac string `json:"mac_address"`
Duration string `json:"duration"`
DurationIpv6 string `json:"durationIpv6"`
Expires string `json:"expires"`
Ipv4Dns string `json:"ipv4_dns"`
IPAddressV6 []string `json:"IPAddress_v6"`
DNSTblRT []string `json:"DNSTblRT"`
}
type CallLog struct { type CallLog struct {
Lines map[string]*PhoneNumberCallLog Lines map[string]*PhoneNumberCallLog
Line0 *PhoneNumberCallLog `json:"0"` Line0 *PhoneNumberCallLog `json:"0"`
@ -189,6 +200,12 @@ type StationAboutResponse struct {
Data *StationAboutData `json:"data"` Data *StationAboutData `json:"data"`
} }
type WanStatusResponse struct {
Error string `json:"error"`
Message string `json:"message"`
Data *WanStatusData `json:"data"`
}
type StationAboutData struct { type StationAboutData struct {
Software []*SoftwareInfo `json:"cosp"` Software []*SoftwareInfo `json:"cosp"`
} }
@ -321,6 +338,15 @@ func (v *VodafoneStation) GetLedSetting() (*LedSettingResponse, error) {
return ledSettingResponse, json.Unmarshal(responseBody, ledSettingResponse) return ledSettingResponse, json.Unmarshal(responseBody, ledSettingResponse)
} }
func (v *VodafoneStation) GetWanStatus() (*WanStatusResponse, error) {
responseBody, err := v.doRequest("GET", v.URL+"/api/v1/wan?_="+strconv.FormatInt(makeTimestamp(), 10), "")
if err != nil {
return nil, err
}
WanStatusResponse := &WanStatusResponse{}
return WanStatusResponse, json.Unmarshal(responseBody, WanStatusResponse)
}
func (v *VodafoneStation) GetStationAbout() (*StationAboutResponse, error) { func (v *VodafoneStation) GetStationAbout() (*StationAboutResponse, error) {
responseBody, err := v.doRequest("GET", v.URL+"/api/v1/sta_about?_="+strconv.FormatInt(makeTimestamp(), 10), "") responseBody, err := v.doRequest("GET", v.URL+"/api/v1/sta_about?_="+strconv.FormatInt(makeTimestamp(), 10), "")
if err != nil { if err != nil {

View file

@ -63,6 +63,15 @@ var (
ipAddressRTDesc *prometheus.Desc ipAddressRTDesc *prometheus.Desc
ipPrefixClassDesc *prometheus.Desc ipPrefixClassDesc *prometheus.Desc
Ipv4Desc *prometheus.Desc
MacDesc *prometheus.Desc
DurationDesc *prometheus.Desc
DurationIpv6Desc *prometheus.Desc
ExpiresDesc *prometheus.Desc
Ipv4DnsDesc *prometheus.Desc
IPAddressV6Desc *prometheus.Desc
DNSTblRTDesc *prometheus.Desc
callEndTimeDesc *prometheus.Desc callEndTimeDesc *prometheus.Desc
callStartTimeDesc *prometheus.Desc callStartTimeDesc *prometheus.Desc
@ -132,6 +141,15 @@ func init() {
ipAddressRTDesc = prometheus.NewDesc(prefix+"ip_address_rt_info", "IP address RT", []string{"ip"}, nil) ipAddressRTDesc = prometheus.NewDesc(prefix+"ip_address_rt_info", "IP address RT", []string{"ip"}, nil)
ipPrefixClassDesc = prometheus.NewDesc(prefix+"ip_prefix_class_info", "IP prefix class info", []string{"prefix_class"}, nil) ipPrefixClassDesc = prometheus.NewDesc(prefix+"ip_prefix_class_info", "IP prefix class info", []string{"prefix_class"}, nil)
Ipv4Desc = prometheus.NewDesc(prefix+"wan_ip4_info", "WAN IPv4 info", []string{"wan_ip4"}, nil)
MacDesc = prometheus.NewDesc(prefix+"wan_mac_address_info", "WAN MAC address", []string{"wan_mac_address"}, nil)
DurationDesc = prometheus.NewDesc(prefix+"wan_duration_seconds", "WAN Duration in seconds", nil, nil)
DurationIpv6Desc = prometheus.NewDesc(prefix+"wan_ip6_duration_seconds", "WAN IPv6 Duration in seconds", nil, nil)
ExpiresDesc = prometheus.NewDesc(prefix+"wan_expires_seconds", "WAN Expires in seconds", nil, nil)
Ipv4DnsDesc = prometheus.NewDesc(prefix+"wan_ipv4_dns_info", "WAN IPv4 DNS server", []string{"wan_ipv4_dns"}, nil)
IPAddressV6Desc = prometheus.NewDesc(prefix+"wan_ip6_info", "WAN IPv6 info", []string{"wan_ip6"}, nil)
DNSTblRTDesc = prometheus.NewDesc(prefix+"wan_ipv6_dns_info", "WAN IPv6 DNS server", []string{"wan_ipv6_dns"}, nil)
callEndTimeDesc = prometheus.NewDesc(prefix+"call_end_time_epoch", "Call endtime as unix epoch", []string{"port", "id", "external_number", "direction", "type"}, nil) 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) callStartTimeDesc = prometheus.NewDesc(prefix+"call_start_time_epoch", "Call starttime as unix epoch", []string{"port", "id", "external_number", "direction", "type"}, nil)
@ -197,6 +215,15 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- ipAddressRTDesc ch <- ipAddressRTDesc
ch <- ipPrefixClassDesc ch <- ipPrefixClassDesc
ch <- Ipv4Desc
ch <- MacDesc
ch <- DurationDesc
ch <- DurationIpv6Desc
ch <- ExpiresDesc
ch <- Ipv4DnsDesc
ch <- IPAddressV6Desc
ch <- DNSTblRTDesc
ch <- callEndTimeDesc ch <- callEndTimeDesc
ch <- callStartTimeDesc ch <- callStartTimeDesc
@ -303,6 +330,27 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(ipPrefixClassDesc, prometheus.GaugeValue, 1, stationStatusResponse.Data.IpPrefixClass) ch <- prometheus.MustNewConstMetric(ipPrefixClassDesc, prometheus.GaugeValue, 1, stationStatusResponse.Data.IpPrefixClass)
} }
wanStatusResponse, err := c.Station.GetWanStatus()
if err != nil {
log.With("error", err.Error()).Error("Failed to get wan status")
} else if wanStatusResponse.Data != nil {
ch <- prometheus.MustNewConstMetric(Ipv4Desc, prometheus.GaugeValue, 1, wanStatusResponse.Data.Ipv4)
ch <- prometheus.MustNewConstMetric(MacDesc, prometheus.GaugeValue, 1, wanStatusResponse.Data.Mac)
ch <- prometheus.MustNewConstMetric(DurationDesc, prometheus.GaugeValue, parse2float(wanStatusResponse.Data.Duration))
ch <- prometheus.MustNewConstMetric(DurationIpv6Desc, prometheus.GaugeValue, parse2float(wanStatusResponse.Data.DurationIpv6))
ch <- prometheus.MustNewConstMetric(ExpiresDesc, prometheus.GaugeValue, parse2float(wanStatusResponse.Data.Expires))
ch <- prometheus.MustNewConstMetric(Ipv4DnsDesc, prometheus.GaugeValue, 1, wanStatusResponse.Data.Ipv4Dns)
// ch <- prometheus.MustNewConstMetric(IPAddressV6Desc, prometheus.GaugeValue, 1, wanStatusResponse.Data.IPAddressV6)
for _, IPAddressV6 := range wanStatusResponse.Data.IPAddressV6 {
ch <- prometheus.MustNewConstMetric(IPAddressV6Desc, prometheus.GaugeValue, 1, IPAddressV6)
}
// ch <- prometheus.MustNewConstMetric(DNSTblRTDesc, prometheus.GaugeValue, 1, wanStatusResponse.Data.DNSTblRT)
for _, DNSTblRT := range wanStatusResponse.Data.DNSTblRT {
ch <- prometheus.MustNewConstMetric(DNSTblRTDesc, prometheus.GaugeValue, 1, DNSTblRT)
}
}
callLog, err := c.Station.GetCallLog() callLog, err := c.Station.GetCallLog()
if err != nil { if err != nil {
log.With("error", err.Error()).Error("Failed to get call log") log.With("error", err.Error()).Error("Failed to get call log")