A go client for the Grafana API
For the moment, the client only covers the Grafana API in the version 5. There is no guarantee that the client is compatible with previous or latest Grafana version.
This project uses the following version rules:
X.Y.Z
Where :
- X is the major version of Grafana supported by this project
- Y is the major version of this client. Be careful with this rule, you can have some breaking changes between two Y number. (even if usually it won't happen)
- Z is the minor version of this client. It will be increased when there are some bug fixes.
Grafana Version | Support Branch |
---|---|
>= 5.0, < 6.0 | master |
Here is an overview of what is done and what is going to be done
currently not well tested
- Alerting
- Admin
- Annotations
- Authentication (key API)
- Dashboard ( not yet fully implemented, need to specify the dashboard struct)
- Dashboard Versions
- Dashboard Permissions
- Data Source
- Folder
- Folder Permissions
- Folder/dashboard search
- Organisation
- Current Org
- Manipulate Org as admin
- Playlist
- Snapshot
- User
- Current User
- Manipulate User as admin
- Team
If you use dep as dependency manager, you fire the following command:
dep ensure -add github.com/nexucis/grafana-go-client
If you are using go mod instead, you can perform the following command:
go get github.com/nexucis/grafana-go-client
package main
import (
"github.com/golang/glog"
"github.com/nexucis/grafana-go-client/grafanahttp"
"github.com/nexucis/grafana-go-client/api"
)
func main() {
rest, err := grafanahttp.NewWithURL("http://admin:admin@localhost:3000")
if err != nil {
glog.Fatal(err)
}
client := api.NewWithClient(rest)
user,err := client.CurrentUser().Get()
// do something with the information get from the api
}
Any contribution or suggestion would be really appreciated. Feel free to use the Issue section or to send a pull request.
All following tools are running by circleci, so in order to help you to improve your code and make easier your life, here it is how you can launch the tools with the correct parameter.
You can run the unit test using make :
make test
This command only run the unit test which basically only the test in the http package. All test written in the package /api/v1 needs grafana. See Run integration test section.
If you want to launch the unit test, you need to have a local grafana instance which must be accessible through the url http://localhost:3000. A simply way to launch it, is to start the corresponding container :
docker run -d --name=grafana -p 3000:3000 grafana/grafana:5.4.3
Once Grafana is up, you can run the following command :
make integration-test
This library is distributed under the Apache 2.0 license