Skip to content

Commit

Permalink
Merge pull request #1 from MaxPeal/add_WanStatus
Browse files Browse the repository at this point in the history
Add wan status
  • Loading branch information
MaxPeal authored Jun 20, 2022
2 parents dbcf9b2 + 4c049c9 commit 6e32d26
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 2 deletions.
26 changes: 26 additions & 0 deletions collector/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,17 @@ type StationStatusData struct {
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 {
Lines map[string]*PhoneNumberCallLog
Line0 *PhoneNumberCallLog `json:"0"`
Expand Down Expand Up @@ -209,6 +220,12 @@ type StationAboutResponse struct {
Data *StationAboutData `json:"data"`
}

type WanStatusResponse struct {
Error string `json:"error"`
Message string `json:"message"`
Data *WanStatusData `json:"data"`
}

type StationAboutData struct {
Software []*SoftwareInfo `json:"cosp"`
}
Expand Down Expand Up @@ -341,6 +358,15 @@ func (v *VodafoneStation) GetLedSetting() (*LedSettingResponse, error) {
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) {
responseBody, err := v.doRequest("GET", v.URL+"/api/v1/sta_about?_="+strconv.FormatInt(makeTimestamp(), 10), "")
if err != nil {
Expand Down
49 changes: 49 additions & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ var (
ipAddressRTDesc *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
callStartTimeDesc *prometheus.Desc

Expand Down Expand Up @@ -147,6 +156,15 @@ func init() {
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)

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)
callStartTimeDesc = prometheus.NewDesc(prefix+"call_start_time_epoch", "Call starttime as unix epoch", []string{"port", "id", "external_number", "direction", "type"}, nil)

Expand Down Expand Up @@ -219,6 +237,16 @@ func (c *Collector) Describe(ch chan<- *prometheus.Desc) {
ch <- ipAddressRTDesc
ch <- ipPrefixClassDesc

ch <- Ipv4Desc
ch <- MacDesc
ch <- DurationDesc
ch <- DurationIpv6Desc
ch <- ExpiresDesc
ch <- Ipv4DnsDesc
ch <- IPAddressV6Desc
ch <- DNSTblRTDesc


ch <- callEndTimeDesc
ch <- callStartTimeDesc

Expand Down Expand Up @@ -333,6 +361,27 @@ func (c *Collector) Collect(ch chan<- prometheus.Metric) {
}
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()
// if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import (
"reflect"
)

const version = "0.1.0"
const version = "0.2.2"

var (
showVersion = flag.Bool("version", false, "Print version and exit")
showMetrics = flag.Bool("show-metrics", false, "Show available metrics and exit")
listenAddress = flag.String("web.listen-address", "[::]:9420", "Address to listen on")
metricsPath = flag.String("web.telemetry-path", "/metrics", "Path under which to expose metrics")
logLevel = flag.String("log.level", "info", "Logging level")
logLevel = flag.String("log.level", "info", "Logging level, default info, debug|info|warn|error")
vodafoneStationUrl = flag.String("vodafone.station-url", "http://192.168.0.1", "Vodafone station URL. For bridge mode this is 192.168.100.1 (note: Configure a route if using bridge mode)")
vodafoneStationPassword = flag.String("vodafone.station-password", "How is the default password calculated? mhmm", "Password for logging into the Vodafone station")
)
Expand Down

0 comments on commit 6e32d26

Please sign in to comment.