示例#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...")
}
示例#2
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.")
	}
}
示例#3
0
func TestParse(t *testing.T) {

	data, err := GetTestData()
	if err != nil {
		t.Error(err)
	}

	kibanaData, err := api.Parse(data)
	if err != nil {
		t.Error(err)
	}

	if len(kibanaData.Searches) <= 0 {
		t.Errorf("Expected a search count greater than 0, got %v.", len(kibanaData.Searches))
	}

	if len(kibanaData.Visualizations) <= 0 {
		t.Errorf("Expected a visualizations count greater than 0, got %v.", len(kibanaData.Visualizations))
	}

	if len(kibanaData.Dashboards) <= 0 {
		t.Errorf("Expected a dashboard count greater than 0, got %v.", len(kibanaData.Dashboards))
	}
}