Skip to content

Commit

Permalink
Merge pull request #3 from caseyr232/master
Browse files Browse the repository at this point in the history
Fix CreateHost funtion to working with Icinga2 - Groups is required i…
  • Loading branch information
lrsmith authored Nov 20, 2017
2 parents 7b46d42 + 5bfaa30 commit 2db1559
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion iapi/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ func (server *Server) GetHost(hostname string) ([]HostStruct, error) {
}

// CreateHost ...
func (server *Server) CreateHost(hostname, address, checkCommand string, variables map[string]string, templates []string) ([]HostStruct, error) {
func (server *Server) CreateHost(hostname, address, checkCommand string, variables map[string]string, templates []string, groups []string) ([]HostStruct, error) {

var newAttrs HostAttrs
newAttrs.Address = address
newAttrs.CheckCommand = "hostalive"
newAttrs.Vars = variables
newAttrs.Templates = templates
newAttrs.Groups = groups

var newHost HostStruct
newHost.Name = hostname
Expand Down
9 changes: 6 additions & 3 deletions iapi/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ func TestCreateSimpleHost(t *testing.T) {
hostname := "go-icinga2-api-1"
IPAddress := "127.0.0.2"
CheckCommand := "CheckItRealGood"
_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, nil, nil)
Group := []string{"linux-servers"}
_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, nil, nil, Group)

if err != nil {
t.Error(err)
Expand All @@ -39,12 +40,13 @@ func TestCreateHostWithVariables(t *testing.T) {
hostname := "go-icinga2-api-2"
IPAddress := "127.0.0.3"
CheckCommand := "CheckItRealGood"
Group := []string{"linux-servers"}
variables := make(map[string]string)

variables["vars.os"] = "Linux"
variables["vars.creator"] = "Terraform"

_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, variables, nil)
_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, variables, nil, Group)
if err != nil {
t.Error(err)
}
Expand All @@ -60,9 +62,10 @@ func TestCreateHostWithTemplates(t *testing.T) {
hostname := "go-icinga2-api-2"
IPAddress := "127.0.0.3"
CheckCommand := "CheckItRealGood"
Group := []string{"linux-servers"}
templates := []string{"template1", "template2"}

_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, nil, templates)
_, err := Icinga2_Server.CreateHost(hostname, IPAddress, CheckCommand, nil, templates, Group)
if err != nil {
t.Error(err)
}
Expand Down
3 changes: 2 additions & 1 deletion iapi/services_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ func TestCreateHostAndService(t *testing.T) {
hostname := "c1-test-1"
servicename := "ssh"
check_command := "ssh"
Group := []string{"linux-servers"}

_, _ = Icinga2_Server.CreateHost(hostname, "127.0.0.1", "hostalive", nil, nil)
_, _ = Icinga2_Server.CreateHost(hostname, "127.0.0.1", "hostalive", nil, nil, Group)

_, err := Icinga2_Server.CreateService(servicename, hostname, check_command)

Expand Down

0 comments on commit 2db1559

Please sign in to comment.