diff --git a/monitoring.go b/monitoring.go new file mode 100644 index 0000000..d0d2555 --- /dev/null +++ b/monitoring.go @@ -0,0 +1,16 @@ +package gonextcloud + +import ( + "github.com/partitio/gonextcloud/types" + "net/http" +) + +func (c *Client) Monitoring() (*types.Monitoring, error) { + res, err := c.baseRequest(routes.monitor, "", "", nil, http.MethodGet) + if err != nil { + return nil, err + } + var m types.MonitoringResponse + res.JSON(&m) + return &m.Ocs.Data, nil +} diff --git a/routes.go b/routes.go index d008449..66068b8 100644 --- a/routes.go +++ b/routes.go @@ -8,16 +8,18 @@ type Routes struct { users *url.URL groups *url.URL apps *url.URL + monitor *url.URL } const badRequest = 998 var ( - apiPath = &url.URL{Path: "/ocs/v1.php/cloud"} + apiPath = &url.URL{Path: "/ocs/v1.php"} routes = Routes{ - capabilities: &url.URL{Path: apiPath.Path + "/capabilities"}, - users: &url.URL{Path: apiPath.Path + "/users"}, - groups: &url.URL{Path: apiPath.Path + "/groups"}, - apps: &url.URL{Path: apiPath.Path + "/apps"}, + capabilities: &url.URL{Path: apiPath.Path + "/cloud/capabilities"}, + users: &url.URL{Path: apiPath.Path + "/cloud/users"}, + groups: &url.URL{Path: apiPath.Path + "/cloud/groups"}, + apps: &url.URL{Path: apiPath.Path + "/cloud/apps"}, + monitor: &url.URL{Path: apiPath.Path + "/apps/serverinfo/api/v1/info"}, } ) diff --git a/types/monitoring.go b/types/monitoring.go new file mode 100644 index 0000000..51cf346 --- /dev/null +++ b/types/monitoring.go @@ -0,0 +1,65 @@ +package types + +type System struct { + Version string `json:"version"` + Theme string `json:"theme"` + EnableAvatars string `json:"enable_avatars"` + EnablePreviews string `json:"enable_previews"` + MemcacheLocal string `json:"memcache.local"` + MemcacheDistributed string `json:"memcache.distributed"` + FilelockingEnabled string `json:"filelocking.enabled"` + MemcacheLocking string `json:"memcache.locking"` + Debug string `json:"debug"` + Freespace int64 `json:"freespace"` + Cpuload []float32 `json:"cpuload"` + MemTotal int `json:"mem_total"` + MemFree int `json:"mem_free"` + SwapTotal int `json:"swap_total"` + SwapFree int `json:"swap_free"` +} + +type Monitoring struct { + Nextcloud struct { + System System `json:"system"` + Storage Storage `json:"storage"` + Shares struct { + NumShares int `json:"num_shares"` + NumSharesUser int `json:"num_shares_user"` + NumSharesGroups int `json:"num_shares_groups"` + NumSharesLink int `json:"num_shares_link"` + NumSharesLinkNoPassword int `json:"num_shares_link_no_password"` + NumFedSharesSent int `json:"num_fed_shares_sent"` + NumFedSharesReceived int `json:"num_fed_shares_received"` + } `json:"shares"` + } `json:"nextcloud"` + Server struct { + Webserver string `json:"webserver"` + Php struct { + Version string `json:"version"` + MemoryLimit int `json:"memory_limit"` + MaxExecutionTime int `json:"max_execution_time"` + UploadMaxFilesize int `json:"upload_max_filesize"` + } `json:"php"` + Database struct { + Type string `json:"type"` + Version string `json:"version"` + Size int `json:"size"` + } `json:"database"` + } `json:"server"` + ActiveUsers ActiveUsers `json:"activeUsers"` +} + +type ActiveUsers struct { + Last5Minutes int `json:"last5minutes"` + Last1Hour int `json:"last1hour"` + Last24Hours int `json:"last24hours"` +} + +type Storage struct { + NumUsers int `json:"num_users"` + NumFiles int `json:"num_files"` + NumStorages int `json:"num_storages"` + NumStoragesLocal int `json:"num_storages_local"` + NumStoragesHome int `json:"num_storages_home"` + NumStoragesOther int `json:"num_storages_other"` +} diff --git a/types/responses.go b/types/responses.go index 0ad85a6..93b0a2b 100644 --- a/types/responses.go +++ b/types/responses.go @@ -87,3 +87,14 @@ type CapabilitiesResponse struct { } `json:"data"` } `json:"ocs"` } + +type MonitoringResponse struct { + Ocs struct { + Meta struct { + Status string `json:"status"` + Statuscode int `json:"statuscode"` + Message string `json:"message"` + } `json:"meta"` + Data Monitoring `json:"data"` + } `json:"ocs"` +}