statping/handlers/export.go

50 lines
1.3 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package handlers
2018-06-23 05:59:29 +00:00
import (
2020-02-25 17:39:38 +00:00
"encoding/json"
2020-03-09 18:17:55 +00:00
"github.com/statping/statping/types/checkins"
"github.com/statping/statping/types/core"
"github.com/statping/statping/types/groups"
"github.com/statping/statping/types/messages"
"github.com/statping/statping/types/services"
"github.com/statping/statping/types/users"
2018-06-23 05:59:29 +00:00
)
2018-10-07 04:48:33 +00:00
// ExportChartsJs renders the charts for the index page
2018-11-25 03:56:09 +00:00
type ExportData struct {
2020-03-12 10:00:20 +00:00
Core *core.Core `json:"core"`
Services []services.Service `json:"services"`
Messages []*messages.Message `json:"messages"`
Checkins []*checkins.Checkin `json:"checkins"`
Users []*users.User `json:"users"`
Groups []*groups.Group `json:"groups"`
Notifiers []core.AllNotifiers `json:"notifiers"`
2018-11-25 03:56:09 +00:00
}
2019-01-09 04:20:43 +00:00
// ExportSettings will export a JSON file containing all of the settings below:
// - Core
// - Notifiers
// - Checkins
// - Users
// - Services
// - Groups
// - Messages
2020-02-25 17:39:38 +00:00
func ExportSettings() ([]byte, error) {
2020-03-12 10:00:20 +00:00
c, err := core.Select()
if err != nil {
return nil, err
}
2020-02-25 17:39:38 +00:00
data := ExportData{
2020-03-12 10:00:20 +00:00
Core: c,
2020-03-04 10:29:00 +00:00
//Notifiers: notifications.All(),
Checkins: checkins.All(),
Users: users.All(),
2020-03-12 10:00:20 +00:00
Services: services.AllInOrder(),
2020-03-04 10:29:00 +00:00
Groups: groups.All(),
Messages: messages.All(),
2020-02-25 17:39:38 +00:00
}
export, err := json.Marshal(data)
return export, err
}