Commit fc1465f4 authored by Robert Jacob's avatar Robert Jacob

Decode xml.

parent 45f40414
package main
import (
"encoding/xml"
"fmt"
"log"
"net/http"
"net/url"
"github.com/prometheus/client_golang/prometheus"
"github.com/xperimental/nextcloud-exporter/serverinfo"
)
type nextcloudCollector struct {
......@@ -84,5 +86,10 @@ func (c *nextcloudCollector) collectNextcloud(ch chan<- prometheus.Metric) error
return fmt.Errorf("unexpected status code: %d", res.StatusCode)
}
var status serverinfo.ServerInfo
if err := xml.NewDecoder(res.Body).Decode(&status); err != nil {
return err
}
return nil
}
package serverinfo
import "encoding/xml"
// ServerInfo contains the complete data received from the server.
type ServerInfo struct {
Meta Meta `xml:"meta"`
......@@ -29,19 +31,54 @@ type Nextcloud struct {
// System contains nextcloud configuration and system information.
type System struct {
Version string `xml:"version"`
Theme string `xml:"theme"`
EnableAvatars bool `xml:"enable_avatars"`
EnablePreviews bool `xml:"enable_previews"`
MemcacheLocal string `xml:"memcache.local"`
MemcacheDistributed string `xml:"memcache.distributed"`
MemcacheLocking string `xml:"memcache.locking"`
FilelockingEnabled bool `xml:"filelocking.enabled"`
Debug bool `xml:"debug"`
FreeSpace int `xml:"freespace"`
CPULoad []float64 `xml:"cpuload"`
MemoryTotal int `xml:"mem_total"`
MemoryFree int `xml:"mem_free"`
Version string `xml:"version"`
Theme string `xml:"theme"`
EnableAvatars bool `xml:"enable_avatars"`
EnablePreviews bool `xml:"enable_previews"`
MemcacheLocal string `xml:"memcache.local"`
MemcacheDistributed string `xml:"memcache.distributed"`
MemcacheLocking string `xml:"memcache.locking"`
FilelockingEnabled bool `xml:"filelocking.enabled"`
Debug bool `xml:"debug"`
FreeSpace int `xml:"freespace"`
// <cpuload>
MemoryTotal int `xml:"mem_total"`
MemoryFree int `xml:"mem_free"`
}
const boolYes = "yes"
func (s *System) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var raw struct {
Version string `xml:"version"`
Theme string `xml:"theme"`
EnableAvatars string `xml:"enable_avatars"`
EnablePreviews string `xml:"enable_previews"`
MemcacheLocal string `xml:"memcache.local"`
MemcacheDistributed string `xml:"memcache.distributed"`
MemcacheLocking string `xml:"memcache.locking"`
FilelockingEnabled string `xml:"filelocking.enabled"`
Debug string `xml:"debug"`
FreeSpace int `xml:"freespace"`
MemoryTotal int `xml:"mem_total"`
MemoryFree int `xml:"mem_free"`
}
if err := d.DecodeElement(&raw, &start); err != nil {
return err
}
s.Version = raw.Version
s.Theme = raw.Theme
s.EnableAvatars = raw.EnableAvatars == boolYes
s.EnablePreviews = raw.EnablePreviews == boolYes
s.MemcacheLocal = raw.MemcacheLocal
s.MemcacheDistributed = raw.MemcacheDistributed
s.MemcacheLocking = raw.MemcacheLocking
s.FilelockingEnabled = raw.FilelockingEnabled == boolYes
s.Debug = raw.Debug == boolYes
s.FreeSpace = raw.FreeSpace
s.MemoryTotal = raw.MemoryTotal
s.MemoryFree = raw.MemoryFree
return nil
}
// Storage contains information about the nextcloud storage system.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment