Esempio n. 1
0
func TestHipchat(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildHipchatNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildHipchatNotifier(check, map[string]string{"token": "abcdef123456", "room": "12345"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*hipchatNotifier)

	var params url.Values
	var theurl string

	sendHere := func(url, token string, body url.Values) error {
		theurl = url
		params = body
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, theurl, "https://api.hipchat.com/v1/rooms/message?auth_token=abcdef123456")
	assert.True(t, strings.Index(params["message"][0], "localhost: swap is greater than than 20%") > -1)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "localhost: swap has recovered.") > -1)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "[sidekiq] does not exist.") > -1)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["message"][0], "[sidekiq] now running with PID 0") > -1)
}
Esempio n. 2
0
func TestCampfire(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildCampfireNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildCampfireNotifier(check, map[string]string{"team": "contribsys", "token": "abcdef123456", "room": "12345"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*campfireNotifier)

	var params map[string]string
	var theurl string

	sendHere := func(url, token string, body map[string]map[string]string) error {
		theurl = url
		params = body["message"]
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, theurl, "https://contribsys.campfirenow.com/room/12345/speak.json")
	assert.True(t, strings.Index(params["body"], "localhost: swap is greater than than 20%") > -1)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "localhost: swap has recovered.") > -1)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "[sidekiq] does not exist.") > -1)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.trigger(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["body"], "[sidekiq] now running with PID 0") > -1)
}
Esempio n. 3
0
func TestSlack(t *testing.T) {
	util.LogInfo = true
	t.Parallel()

	check := inspeqtor.NewHost()
	action, err := buildSlackNotifier(check, map[string]string{})
	assert.Nil(t, action)
	assert.NotNil(t, err)

	action, err = buildSlackNotifier(check, map[string]string{"team": "contribsys", "url": "https://acmecorp.slack.com/services/hooks/incoming-webhook?token=xxx/xxx/xxx", "icon_emoji": "beer"})
	assert.Nil(t, err)
	assert.NotNil(t, action)
	sn := action.(*slackNotifier)

	var params url.Values
	var theurl string

	sendHere := func(url string, values url.Values) error {
		theurl = url
		params = values
		return nil
	}

	alert := swapEvent(check, inspeqtor.RuleFailed)
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.Equal(t, "https://acmecorp.slack.com/services/hooks/incoming-webhook?token=xxx/xxx/xxx", theurl)
	assert.True(t, strings.Index(params["payload"][0], "localhost: swap is greater than than 20%") > 0)

	alert = swapEvent(check, inspeqtor.RuleRecovered)
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "localhost: swap has recovered.") > 0)

	svc := inspeqtor.NewService("sidekiq")
	alert = &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "[sidekiq] does not exist.") > 0)

	alert = &inspeqtor.Event{Type: inspeqtor.ProcessExists, Eventable: svc, Rule: nil}
	err = sn.triggerSlack(alert, sendHere)
	assert.Nil(t, err)
	assert.True(t, strings.Index(params["payload"][0], "[sidekiq] now running with PID 0") > 0)
}
Esempio n. 4
0
// Verify the email templates are packaged correctly in Pro
func TestEmail(t *testing.T) {
	svc := inspeqtor.NewService("sidekiq")
	action, err := inspeqtor.Notifiers["email"](svc, map[string]string{
		"username":    "******",
		"password":    "******",
		"smtp_server": "smtp.example.com",
		"to_email":    "*****@*****.**",
	})
	assert.Nil(t, err)
	emailer := action.(*inspeqtor.EmailNotifier)
	alert := &inspeqtor.Event{Type: inspeqtor.ProcessDoesNotExist, Eventable: svc, Rule: nil}
	err = emailer.TriggerEmail(alert, func(e *inspeqtor.EmailNotifier, doc bytes.Buffer) error {
		content := string(doc.Bytes())
		assert.True(t, strings.Index(content, "can't locate") > 0, "email does not contain expected content")
		assert.True(t, strings.Index(content, "the sidekiq service") > 0, "email does not contain expected content")
		return nil
	})
}