Esempio n. 1
0
func runSettings(c *Cluster, cmd *Command, args []string) error {
	settings, err := c.Stretch.GetSettings()

	if err != nil {
		return err
	}

	t := termtable.NewTable(&termtable.TableOptions{Padding: 1, MaxColWidth: 90, Header: []string{"SETTING NAME", "VALUE"}})

	t.AddRow([]string{"PERSISTENT SETTINGS", ""})

	for key, value := range settings.Persistent {
		t.AddRow([]string{key, value})
	}

	t.AddRow([]string{"", ""})

	t.AddRow([]string{"TRANSIENT SETTINGS", ""})

	for key, value := range settings.Transient {
		t.AddRow([]string{key, value})
	}

	fmt.Println(t.Render())

	return nil
}
Esempio n. 2
0
File: health.go Progetto: vrosnet/es
func renderIndexHealth(health stretch.ClusterHealth) error {
	t := termtable.NewTable(&termtable.TableOptions{
		Padding: 1,
		Header: []string{
			"INDEX",
			"STATUS",
			"SHARDS",
			"REPLICAS",
			"ACT. PRIM. SHARDS",
			"ACTIVE SHARDS",
			"RELOCATING",
			"INITIALIZING",
			"UNASSIGNED",
		},
	})

	for indexName, indexHealth := range health.Indices {
		t.AddRow([]string{
			indexName,
			indexHealth.Status,
			strconv.Itoa(indexHealth.NumberOfShards),
			strconv.Itoa(indexHealth.NumberOfReplicas),
			strconv.Itoa(indexHealth.ActivePrimaryShards),
			strconv.Itoa(indexHealth.ActiveShards),
			strconv.Itoa(indexHealth.RelocatingShards),
			strconv.Itoa(indexHealth.InitializingShards),
			strconv.Itoa(indexHealth.UnassignedShards),
		})
	}

	fmt.Println(t.Render())

	return nil
}
Esempio n. 3
0
File: nodes.go Progetto: vrosnet/es
func runNodes(c *Cluster, cmd *Command, args []string) error {
	nodes, err := c.Stretch.GetNodes()

	if err != nil {
		return err
	}

	t := termtable.NewTable(&termtable.TableOptions{Padding: 1, Header: []string{"NAME", "HOSTNAME", "VERSION", "HTTP ADDRESS", "ATTRIBUTES"}})

	for _, node := range nodes.Nodes {
		t.AddRow([]string{node.Name, node.Hostname + node.Host, node.Version, node.HTTPAddress, fmt.Sprintf("%v", node.Attributes)})
	}

	fmt.Println(t.Render())
	return nil
}
Esempio n. 4
0
File: health.go Progetto: vrosnet/es
func renderClusterHealth(health stretch.ClusterHealth) error {
	t := termtable.NewTable(&termtable.TableOptions{
		Padding: 1,
		Header:  []string{"CLUSTER HEALTH", ""},
	})

	t.AddRow([]string{"Name", health.ClusterName})
	t.AddRow([]string{"Status", health.Status})
	t.AddRow([]string{"Timed Out", strconv.FormatBool(health.TimedOut)})
	t.AddRow([]string{"Number of Nodes", strconv.Itoa(health.NumberOfNodes)})
	t.AddRow([]string{"Number of Data Nodes", strconv.Itoa(health.NumberOfDataNodes)})
	t.AddRow([]string{"Active Primary Shards", strconv.Itoa(health.ActivePrimaryShards)})
	t.AddRow([]string{"Active Shards", strconv.Itoa(health.ActiveShards)})
	t.AddRow([]string{"Relocating Shards", strconv.Itoa(health.RelocatingShards)})
	t.AddRow([]string{"Initializing Shards", strconv.Itoa(health.InitializingShards)})
	t.AddRow([]string{"Unassigned Shards", strconv.Itoa(health.UnassignedShards)})
	fmt.Println(t.Render())

	return nil
}
Esempio n. 5
0
func main() {
	// establish connection to our socket, for both reads and writes
	conn, err := net.Dial("unix", "/var/lib/nagios/rw/nagios.qh")
	if err != nil {
		panic(err.Error())
	}
	defer conn.Close()

	// suss out what command we actually wish to run
	if len(os.Args) == 0 {
		send_command(conn, "help")
	}

	switch os.Args[1] {
	case "help", "status", "check", "acknowledge", "unacknowledge", "disable_notifications", "enable_notifications", "downtime", "problems", "muted", "stats":
		send_command(conn, strings.Join(os.Args[1:], " "))
	case "ack":
		send_command(conn, "acknowledge"+" "+strings.Join(os.Args[2:], " "))
	case "unack":
		send_command(conn, "unacknowledge"+" "+strings.Join(os.Args[2:], " "))
	case "mute":
		send_command(conn, "disable_notifications"+" "+strings.Join(os.Args[2:], " "))
	case "unmute":
		send_command(conn, "enable_notifications"+" "+strings.Join(os.Args[2:], " "))
	default:
		send_command(conn, "help")
	}

	output := read_results(conn)
	lines := strings.Split(output, "\n")
	table_it, err := regexp.MatchString(";", output)

	if len(lines[1:]) > 0 && table_it {
		sort.Sort(sort.StringSlice(lines))

		t := termtable.NewTable(&termtable.TableOptions{Padding: 1, Header: []string{"Service", "Status", "Details"}, MaxColWidth: 72})

		for _, line := range lines[1:] {
			parts := [3]string{"", "", ""}
			split := strings.Split(line, ";")

			for i := 0; i < 3; i++ {
				var part string

				if i == 2 {
					part = strings.Join(split[2:], "")
				} else {
					part = split[i]
				}

				parts[i] = part

				if parts[i] == "" {
					parts[i] = "wat"
				}
			}

			row := []string{parts[0], parts[1], parts[2]}
			t.AddRow(row)
		}

		fmt.Println(t.Render())
	} else {
		fmt.Println(strings.Join(lines[0:len(lines)-1], "\n"))
	}
}