package main

import (
	"encoding/json"
	"fmt"
	"log"

	"github.com/ceph/go-ceph/rados"
)



func makeMonQuery(cephConn *cephConnection, query map[string]string) []byte {
	monJson, err := json.Marshal(query)
	if err != nil {
		log.Fatalf("Can't marshal json mon query. Error: %v", err)
	}

	monRawAnswer, _, err := cephConn.conn.MonCommand(monJson)
	if err != nil {
		log.Fatalf("Failed exec monCommand. Error: %v", err)
	}
	return monRawAnswer
}


func main() {
	var connect cephConnection
	var err error
	var monRawAnswer []byte

	fmt.Println("Creating connection object")
	connect.conn,err = rados.NewConn()
	if err != nil {
		log.Fatal("Cannot create Connection object\n")
	}
	connect.conn.ReadConfigFile("/etc/ceph/ceph.conf")
	connect.conn.Connect()
	defer connect.conn.Shutdown()

	monRawAnswer = makeMonQuery(&connect, map[string]string{"prefix": "osd dump", "format": "json"})

	fmt.Println(monRawAnswer)

	// poolnames,err := connect.conn.ListPools()
	// if err != nil {
	// 	log.Fatal("Cannot list pools")
	// }

	// for i,j := range poolnames {
	// 	fmt.Printf("%d %s\n",i,j)
}

