コード例 #1
0
ファイル: client.go プロジェクト: JonathanPorta/uchiwa
// GetClient retrieves client history from specified DC
func GetClient(id string, dc string) (map[string]interface{}, error) {
	api, err := findDcFromString(&dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	// lock Results structure while we gather client info
	mutex.Lock()
	defer mutex.Unlock()

	c, err := findClientInClients(&id, &dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	h, err := api.GetClientHistory(id)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	buildClientHistory(&id, &h, &dc)

	// add client history to client map for easy frontend consumption
	c["history"] = h

	return c, nil
}
コード例 #2
0
ファイル: client.go プロジェクト: stack72/uchiwa
// GetClient retrieves client history from specified DC
func (u *Uchiwa) GetClient(id string, dc string) (map[string]interface{}, error) {
	api, err := getAPI(u.Datacenters, dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	// lock results while we gather client info
	u.Mu.Lock()
	defer u.Mu.Unlock()

	c, err := u.findClientInClients(&id, &dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	h, err := api.GetClientHistory(id)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	u.buildClientHistory(&id, &h, &dc)

	// add client history to client map for easy frontend consumption
	c["history"] = h

	return c, nil
}
コード例 #3
0
ファイル: stash.go プロジェクト: stack72/uchiwa
// DeleteStash send a DELETE request to the /stashes/*path* endpoint in order to delete a stash
func (u *Uchiwa) DeleteStash(data stash) error {
	api, err := getAPI(u.Datacenters, data.Dc)
	if err != nil {
		logger.Warning(err)
		return err
	}

	err = api.DeleteStash(data.Path)
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #4
0
ファイル: stash.go プロジェクト: stack72/uchiwa
// PostStash send a POST request to the /stashes endpoint in order to create a stash
func (u *Uchiwa) PostStash(data stash) error {
	api, err := getAPI(u.Datacenters, data.Dc)
	if err != nil {
		logger.Warning(err)
		return err
	}

	_, err = api.CreateStash(data)
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #5
0
ファイル: client.go プロジェクト: stack72/uchiwa
// DeleteClient send a DELETE request to the /clients/*client* endpoint in order to delete a client
func (u *Uchiwa) DeleteClient(id string, dc string) error {
	api, err := getAPI(u.Datacenters, dc)
	if err != nil {
		logger.Warning(err)
		return err
	}

	err = api.DeleteClient(id)
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #6
0
ファイル: aggregate.go プロジェクト: stack72/uchiwa
// GetAggregate retrieves a list of issued timestamps from a specified DC
func (u *Uchiwa) GetAggregate(check string, dc string) (*[]interface{}, error) {
	api, err := getAPI(u.Datacenters, dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	aggregate, err := api.GetAggregate(check, 1)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	return &aggregate, nil
}
コード例 #7
0
ファイル: aggregate.go プロジェクト: stack72/uchiwa
// GetAggregateByIssued retrieves aggregate check info from a specified DC
func (u *Uchiwa) GetAggregateByIssued(check string, issued string, dc string) (*map[string]interface{}, error) {
	api, err := getAPI(u.Datacenters, dc)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	aggregate, err := api.GetAggregateIssued(check, issued, true, true)
	if err != nil {
		logger.Warning(err)
		return nil, err
	}

	return &aggregate, nil
}
コード例 #8
0
ファイル: client.go プロジェクト: JonathanPorta/uchiwa
// DeleteClient send a DELETE request to the /clients/*client* endpoint in order to delete a client
func DeleteClient(id string, dc string) error {
	api, err := findDcFromString(&dc)
	if err != nil {
		logger.Warning(err)
		return err
	}

	err = api.DeleteClient(id)
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #9
0
ファイル: events.go プロジェクト: stack72/uchiwa
// ResolveEvent send a POST request to the /resolve endpoint in order to resolve an event
func (d *Daemon) ResolveEvent(data interface{}) error {
	api, m, err := FindDcFromInterface(data, d.Datacenters)
	_, err = api.ResolveEvent(m["payload"])
	if err != nil {
		logger.Warning(err)
		return err
	}
	return nil
}
コード例 #10
0
ファイル: stashes.go プロジェクト: JonathanPorta/uchiwa
// CreateStash send a POST request to the /stashes endpoint in order to create a stash
func CreateStash(data interface{}) error {

	api, m, err := findDcFromInterface(data)

	_, err = api.CreateStash(m["payload"])
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #11
0
ファイル: status.go プロジェクト: JonathanPorta/uchiwa
func getTransportStatus(info map[string]interface{}) string {
	transport, ok := info["transport"].(map[string]interface{})
	if !ok {
		transport, ok := info["rabbitmq"].(map[string]interface{})
		if !ok {
			logger.Warning("Could not assert info's transport interface")
			return "unknown"
		}
		return fmt.Sprintf("%t", transport["connected"])
	}
	return fmt.Sprintf("%t", transport["connected"])
}
コード例 #12
0
ファイル: events.go プロジェクト: JonathanPorta/uchiwa
// ResolveEvent send a POST request to the /resolve endpoint in order to resolve an event
func ResolveEvent(data interface{}) error {

	api, m, err := findDcFromInterface(data)

	_, err = api.ResolveEvent(m["payload"])
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #13
0
ファイル: stashes.go プロジェクト: JonathanPorta/uchiwa
// DeleteStash send a DELETE request to the /stashes/*path* endpoint in order to delete a stash
func DeleteStash(data interface{}) error {
	api, m, err := findDcFromInterface(data)

	p, ok := m["payload"].(map[string]interface{})
	if !ok {
		logger.Warningf("Could not assert data interface %+v", data)
		return errors.New("Could not assert data interface")
	}

	err = api.DeleteStash(p["path"].(string))
	if err != nil {
		logger.Warning(err)
		return err
	}

	return nil
}
コード例 #14
0
ファイル: dc.go プロジェクト: JonathanPorta/uchiwa
// Build retrieves all endpoints for every API
func Build(dcSlice *[]sensu.Sensu) {

	for _, api := range *dcSlice {
		errorString := "Connection error. Is Sensu API running?"

		// fetch sensu data from the API
		stashes, err := api.GetStashes()
		if err != nil {
			Health.Sensu[api.Name] = map[string]string{"output": errorString}
			logger.Warning(err)
			continue
		}
		checks, err := api.GetChecks()
		if err != nil {
			Health.Sensu[api.Name] = map[string]string{"output": errorString}
			logger.Warning(err)
			continue
		}
		clients, err := api.GetClients()
		if err != nil {
			Health.Sensu[api.Name] = map[string]string{"output": errorString}
			logger.Warning(err)
			continue
		}
		events, err := api.GetEvents()
		if err != nil {
			Health.Sensu[api.Name] = map[string]string{"output": errorString}
			logger.Warning(err)
			continue
		}
		info, err := api.Info()
		if err != nil {
			Health.Sensu[api.Name] = map[string]string{"output": errorString}
			logger.Warning(err)
			continue
		}

		Health.Sensu[api.Name] = map[string]string{"output": "ok"}

		// add fetched data to results interface
		for _, v := range stashes {
			setDc(v, api.Name)
			tmpResults.Stashes = append(tmpResults.Stashes, v)
		}
		for _, v := range checks {
			setDc(v, api.Name)
			tmpResults.Checks = append(tmpResults.Checks, v)
		}
		for _, v := range clients {
			setDc(v, api.Name)
			tmpResults.Clients = append(tmpResults.Clients, v)
		}
		for _, v := range events {
			setDc(v, api.Name)
			tmpResults.Events = append(tmpResults.Events, v)
		}

		// build dc status
		d := Status(info, api.Name)
		d["checks"] = fmt.Sprintf("%d", len(checks))
		d["clients"] = fmt.Sprintf("%d", len(clients))
		d["events"] = fmt.Sprintf("%d", len(events))
		d["stashes"] = fmt.Sprintf("%d", len(stashes))
		tmpResults.Dc = append(tmpResults.Dc, d)
	}

	BuildEvents()
	BuildClients()
	BuildSubscriptions()

	mutex.Lock()
	defer mutex.Unlock()
	*Results = *tmpResults
}
コード例 #15
0
ファイル: daemon.go プロジェクト: pclata/uchiwa
// getData retrieves all endpoints for every datacenter
func (d *Daemon) fetchData() {
	d.Data.Health.Sensu = make(map[string]structs.SensuHealth, len(*d.Datacenters))

	for _, datacenter := range *d.Datacenters {
		// set default health status
		d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: datacenterErrorString}
		d.Data.Health.Uchiwa = "ok"

		// fetch sensu data from the datacenter
		stashes, err := datacenter.GetStashes()
		if err != nil {
			logger.Warning(err)
			continue
		}
		checks, err := datacenter.GetChecks()
		if err != nil {
			logger.Warning(err)
			continue
		}
		clients, err := datacenter.GetClients()
		if err != nil {
			logger.Warning(err)
			continue
		}
		events, err := datacenter.GetEvents()
		if err != nil {
			logger.Warning(err)
			continue
		}
		info, err := datacenter.Info()
		if err != nil {
			logger.Warning(err)
			continue
		}
		aggregates, err := datacenter.GetAggregates()
		if err != nil {
			logger.Warning(err)
			continue
		}
		results, err := datacenter.Results()
		if err == nil {
			for _, v := range *results {
				setDc(v, datacenter.Name)
				d.Data.Results = append(d.Data.Results, v)
			}
		}

		d.Data.Health.Sensu[datacenter.Name] = structs.SensuHealth{Output: "ok"}

		// add fetched data into d.Data interface
		for _, v := range stashes {
			setDc(v, datacenter.Name)
			d.Data.Stashes = append(d.Data.Stashes, v)
		}
		for _, v := range checks {
			setDc(v, datacenter.Name)
			d.Data.Checks = append(d.Data.Checks, v)
		}
		for _, v := range clients {
			setDc(v, datacenter.Name)
			d.Data.Clients = append(d.Data.Clients, v)
		}
		for _, v := range events {
			setDc(v, datacenter.Name)
			d.Data.Events = append(d.Data.Events, v)
		}
		for _, v := range aggregates {
			setDc(v, datacenter.Name)
			d.Data.Aggregates = append(d.Data.Aggregates, v)
		}

		// build datacenter
		dc := d.buildDatacenter(&datacenter.Name, info)
		dc.Stats["aggregates"] = len(aggregates)
		dc.Stats["checks"] = len(checks)
		dc.Stats["clients"] = len(clients)
		dc.Stats["events"] = len(events)
		dc.Stats["stashes"] = len(stashes)
		d.Data.Dc = append(d.Data.Dc, dc)
	}
}