Exemple #1
0
func CmdImport(c *cli.Context) {
	var file string
	var err error
	if file = c.String("file"); file == "" {
		fmt.Println("file flag missing")
		cli.ShowAppHelp(c)
		return
	}

	data, err := ioutil.ReadFile(file)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	importer := api.ImportCreate()
	kibanaData, err := api.Parse(data)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	err = importer.All(api.Create(c.String("uri")), kibanaData)

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println("Import successful...")
}
Exemple #2
0
func CmdExport(c *cli.Context) {
	export := api.ExportCreate()
	json, err := export.All(api.Create(c.String("uri")))

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	var file string
	if file = c.String("file"); file == "" {
		fmt.Println(json)
		return
	}

	os.Remove(file)
	logFile, err := os.OpenFile(file, os.O_RDWR|os.O_CREATE, 0666)
	if err != nil {
		fmt.Println(err.Error())
		return
	}

	logFile.WriteString(json)
	fmt.Println("Export successful...")
}
Exemple #3
0
func CmdDelete(c *cli.Context) {
	delete := api.DeleteCreate()
	err := delete.All(api.Create(c.String("uri")))

	if err != nil {
		fmt.Println(err.Error())
		return
	}

	fmt.Println("Delete successful...")
}
Exemple #4
0
func TestExportAll(t *testing.T) {
	export := api.ExportCreate()
	json, err := export.All(api.Create(api.DefaultKibanaUri))

	if err != nil {
		t.Error(err)
	}

	if len(json) <= 0 {
		t.Error("Expected a non-zero result")
	}
}
Exemple #5
0
func TestSearch(t *testing.T) {
	api := api.Create(api.DefaultKibanaUri)
	data, err := api.Search("dashboard")

	if err != nil {
		t.Error(err)
	}

	if data == nil {
		t.Error("Expected a non-zero result")
	}
}
Exemple #6
0
func TestGet(t *testing.T) {
	api := api.Create(api.DefaultKibanaUri)
	dashboards, err := api.Search("dashboard")
	visualizations, err := api.Search("visualization")

	items := append(dashboards, visualizations...)
	data, err := api.Get(items)
	if err != nil {
		t.Error(err)
	}

	if data["docs"] == nil {
		t.Error("Expected a non-zero result")
	}
}
Exemple #7
0
func TestDelete(t *testing.T) {
	var data []byte
	var err error
	if data, err = GetTestData(); err != nil {
		t.Error(err)
	}

	kibanaData, err := api.Parse(data)

	var id *uuid.UUID
	if id, err = uuid.NewV4(); err != nil {
		t.Error(err)
	}

	kibanaData.Searches[0]["_id"] = id.String()

	kApi := api.Create(api.DefaultKibanaUri)
	kApi.Create(kibanaData.Searches[0])

	response, err := kApi.Delete(api.KibanaItem{
		Type: kibanaData.Searches[0]["_type"].(string),
		Id:   kibanaData.Searches[0]["_id"].(string),
	})

	if err != nil {
		t.Error(err)
	}

	if response == nil {
		t.Error("Expected non-nil response")
	}

	if !response["found"].(bool) {
		t.Error("Expected item to be found.")
	}
}