statping/core/export.go

84 lines
2.3 KiB
Go
Raw Normal View History

2018-12-04 05:57:11 +00:00
// Statping
2018-08-16 06:22:20 +00:00
// Copyright (C) 2018. Hunter Long and the project contributors
// Written by Hunter Long <info@socialeck.com> and the project contributors
//
2018-12-04 04:17:29 +00:00
// https://github.com/hunterlong/statping
2018-08-16 06:22:20 +00:00
//
// The licenses for most software and other practical works are designed
// to take away your freedom to share and change the works. By contrast,
// the GNU General Public License is intended to guarantee your freedom to
// share and change all versions of a program--to make sure it remains free
// software for all its users.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
2018-06-30 00:57:05 +00:00
package core
2018-06-23 05:59:29 +00:00
import (
"bytes"
2018-11-25 03:56:09 +00:00
"encoding/json"
2018-12-04 04:17:29 +00:00
"github.com/hunterlong/statping/source"
"github.com/hunterlong/statping/types"
"github.com/hunterlong/statping/utils"
2018-06-23 05:59:29 +00:00
"html/template"
)
2018-10-07 04:48:33 +00:00
// ExportChartsJs renders the charts for the index page
func ExportChartsJs() string {
render, err := source.JsBox.String("charts.js")
if err != nil {
utils.Log(4, err)
}
t := template.New("charts")
t.Funcs(template.FuncMap{
"safe": func(html string) template.HTML {
return template.HTML(html)
},
})
t.Parse(render)
var tpl bytes.Buffer
if err := t.Execute(&tpl, CoreApp.Services); err != nil {
2018-06-30 00:57:05 +00:00
utils.Log(3, err)
2018-06-23 05:59:29 +00:00
}
result := tpl.String()
return result
}
2018-11-25 03:56:09 +00:00
type ExportData struct {
Core *types.Core `json:"core"`
Services []types.ServiceInterface `json:"services"`
Messages []*Message `json:"messages"`
2018-11-25 03:56:09 +00:00
Checkins []*Checkin `json:"checkins"`
Users []*User `json:"users"`
2019-01-09 04:20:43 +00:00
Groups []*Group `json:"groups"`
2018-11-25 03:56:09 +00:00
Notifiers []types.AllNotifiers `json:"notifiers"`
}
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
2018-11-25 03:56:09 +00:00
func ExportSettings() ([]byte, error) {
users, err := SelectAllUsers()
messages, err := SelectMessages()
2018-11-25 03:56:09 +00:00
if err != nil {
return nil, err
}
data := ExportData{
Core: CoreApp.Core,
Notifiers: CoreApp.Notifications,
Checkins: AllCheckins(),
Users: users,
Services: CoreApp.Services,
2019-01-09 04:20:43 +00:00
Groups: SelectGroups(true, true),
Messages: messages,
2018-11-25 03:56:09 +00:00
}
export, err := json.Marshal(data)
return export, err
}