Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
4a121ee
fixing
mirshahriar Mar 20, 2018
3be6c40
fixed
mirshahriar Mar 20, 2018
f2f7e32
fixed
mirshahriar Mar 20, 2018
4012241
[ci skip]
mirshahriar Mar 20, 2018
a16d28c
[ci skip]
mirshahriar Mar 20, 2018
07c02a0
[skip ci]
mirshahriar Mar 21, 2018
5500402
[ci skip]
mirshahriar Mar 21, 2018
96e0e15
fixed [ci skip]
mirshahriar Mar 21, 2018
f8ce576
[skip ci]
mirshahriar Mar 21, 2018
3c2e4dd
fixed [skip ci]
mirshahriar Mar 21, 2018
0c838a8
[ci skip]
mirshahriar Mar 21, 2018
08d31b9
[ci skip]
mirshahriar Mar 21, 2018
751e250
fixed [ci skip]
mirshahriar Mar 21, 2018
12fab47
[ci skip]
mirshahriar Mar 21, 2018
fe578fd
[ci skip]
mirshahriar Mar 21, 2018
76aab5e
[skip ci]
mirshahriar Mar 21, 2018
b827039
fixed
mirshahriar Mar 21, 2018
e7e2c3d
fixed
mirshahriar Mar 21, 2018
7e8a6e3
added-all
mirshahriar Mar 21, 2018
395ddb3
fixed [ci skip]
mirshahriar Mar 21, 2018
bfa48a5
fixed [ci skip]
mirshahriar Mar 21, 2018
ef71e3d
Merge branch 'master'
mirshahriar Mar 22, 2018
52ae701
gen docs
mirshahriar Mar 22, 2018
5ebf30d
fixed
mirshahriar Mar 22, 2018
56acd4f
done e2e test [skip ci]
mirshahriar Mar 22, 2018
ee62c40
fixed [ci skip]
mirshahriar Mar 23, 2018
d196de5
[ci skip]
mirshahriar Mar 23, 2018
7747210
Added e2e test for notifier [ci skip]
mirshahriar Mar 23, 2018
c16defb
fix check_ca_cert [ci skip]
mirshahriar Mar 23, 2018
af728b8
Merge branch 'master' into client
tamalsaha Mar 23, 2018
3e364b2
fixed [ci skip]
mirshahriar Mar 23, 2018
270a8bc
fixed [ci skip]
mirshahriar Mar 23, 2018
fa7418f
Merge branch 'client' of github.com:appscode/searchlight into client
mirshahriar Mar 23, 2018
aa40c93
Merge branch 'client' of github.com:appscode/searchlight into httpserver
mirshahriar Mar 23, 2018
677098b
fixed
mirshahriar Mar 23, 2018
db27b92
fixed
mirshahriar Mar 23, 2018
bcb89c9
fixed
mirshahriar Mar 23, 2018
a092cbe
Merge branch 'httpserver' of github.com:appscode/searchlight into htt…
tamalsaha Mar 23, 2018
38dce9f
fixed
mirshahriar Mar 27, 2018
4397352
fixed
mirshahriar Mar 27, 2018
9c19aa6
fixed
mirshahriar Mar 27, 2018
09ed498
Delete junit.xml
tamalsaha Mar 27, 2018
57bb2a2
Update .gitignore
tamalsaha Mar 27, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ apiserver.local.config/
hack/dev/testconfig/searchlight/pki/
hack/dev/notifier/MAILGUN_API_KEY
coverage.txt
test/e2e/junit.xml
2 changes: 1 addition & 1 deletion glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 8 additions & 16 deletions pkg/icinga/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ type Config struct {
}

type Client struct {
config Config
pathPrefix string
config Config
}

type APIRequest struct {
Expand Down Expand Up @@ -54,34 +53,27 @@ func (c *Client) SetEndpoint(endpoint string) *Client {
return c
}

func (c *Client) Objects() *Client {
c.pathPrefix = "/objects"
return c
}

func (c *Client) Hosts(hostName string) *APIRequest {
return c.newRequest("/hosts/" + hostName)
return c.newRequest("/objects/hosts/" + hostName)
}

func (c *Client) HostGroups(hostName string) *APIRequest {
return c.newRequest("/hostgroups/" + hostName)
return c.newRequest("/objects/hostgroups/" + hostName)
}

func (c *Client) Service(hostName string) *APIRequest {
return c.newRequest("/services/" + hostName)
return c.newRequest("/objects/services/" + hostName)
}

func (c *Client) Actions(action string) *APIRequest {
c.pathPrefix = ""
return c.newRequest("/actions/" + action)
func (c *Client) Notifications(hostName string) *APIRequest {
return c.newRequest("/objects/notifications/" + hostName)
}

func (c *Client) Notifications(hostName string) *APIRequest {
return c.newRequest("/notifications/" + hostName)
func (c *Client) Actions(action string) *APIRequest {
return c.newRequest("/actions/" + action)
}

func (c *Client) Check() *APIRequest {
c.pathPrefix = ""
return c.newRequest("")
}

Expand Down
22 changes: 11 additions & 11 deletions pkg/icinga/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (h *commonHost) reconcileIcingaHost(kh IcingaHost) error {
return errors.Wrap(err, "Failed to Marshal IcingaObject")
}

resp := h.IcingaClient.Objects().Hosts(host).Create([]string{}, string(jsonStr)).Do()
resp := h.IcingaClient.Hosts(host).Create([]string{}, string(jsonStr)).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, string(resp.ResponseBody))
}
Expand All @@ -49,7 +49,7 @@ func (h *commonHost) reconcileIcingaHost(kh IcingaHost) error {
return errors.Errorf("Failed to create Icinga Host. Status: %d", resp.Status)
}

resp = h.IcingaClient.Objects().Hosts(host).Update([]string{}, string(jsonStr)).Do()
resp = h.IcingaClient.Hosts(host).Update([]string{}, string(jsonStr)).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to update Icinga Host")
}
Expand All @@ -71,12 +71,12 @@ func (h *commonHost) deleteIcingaHost(kh IcingaHost) error {

in := fmt.Sprintf(`{"filter": "match(\"%s\",host.name)"}`, host)
var respService ResponseObject
if _, err := h.IcingaClient.Objects().Service("").Update([]string{}, in).Do().Into(&respService); err != nil {
if _, err := h.IcingaClient.Service("").Update([]string{}, in).Do().Into(&respService); err != nil {
return errors.Wrap(err, "can't get Icinga service")
}

if len(respService.Results) == 0 {
resp := h.IcingaClient.Objects().Hosts("").Delete([]string{}, in).Params(param).Do()
resp := h.IcingaClient.Hosts("").Delete([]string{}, in).Params(param).Do()
if resp.Err != nil {
return errors.Wrap(err, "can't delete Icinga host")
}
Expand All @@ -94,7 +94,7 @@ func (h *commonHost) ForceDeleteIcingaHost(kh IcingaHost) error {
}

in := fmt.Sprintf(`{"filter": "match(\"%s\",host.name)"}`, host)
resp := h.IcingaClient.Objects().Hosts("").Delete([]string{}, in).Params(param).Do()
resp := h.IcingaClient.Hosts("").Delete([]string{}, in).Params(param).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to delete IcingaHost")
}
Expand All @@ -118,7 +118,7 @@ func (h *commonHost) createIcingaService(svc string, kh IcingaHost, attrs map[st
if err != nil {
return errors.WithStack(err)
}
resp := h.IcingaClient.Objects().Service(host).Create([]string{svc}, string(jsonStr)).Do()
resp := h.IcingaClient.Service(host).Create([]string{svc}, string(jsonStr)).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to create Icinga Service")
}
Expand All @@ -145,7 +145,7 @@ func (h *commonHost) updateIcingaService(svc string, kh IcingaHost, attrs map[st
if err != nil {
return errors.WithStack(err)
}
resp := h.IcingaClient.Objects().Service(host).Update([]string{svc}, string(jsonStr)).Do()
resp := h.IcingaClient.Service(host).Update([]string{svc}, string(jsonStr)).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to update Icinga Service")
}
Expand All @@ -161,7 +161,7 @@ func (h *commonHost) deleteIcingaService(svc string, kh IcingaHost) error {
}
in := h.IcingaServiceSearchQuery(svc, kh)

resp := h.IcingaClient.Objects().Service("").Delete([]string{}, in).Params(param).Do()
resp := h.IcingaClient.Service("").Delete([]string{}, in).Params(param).Do()
if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to delete Icinga Service")
}
Expand All @@ -176,7 +176,7 @@ func (h *commonHost) checkIcingaService(svc string, kh IcingaHost) (bool, error)
in := h.IcingaServiceSearchQuery(svc, kh)
var respService ResponseObject

if _, err := h.IcingaClient.Objects().Service("").Get([]string{}, in).Do().Into(&respService); err != nil {
if _, err := h.IcingaClient.Service("").Get([]string{}, in).Do().Into(&respService); err != nil {
return true, errors.Wrap(err, "can't check icinga service")
}
return len(respService.Results) > 0, nil
Expand Down Expand Up @@ -214,7 +214,7 @@ func (h *commonHost) reconcileIcingaNotification(alert api.Alert, kh IcingaHost)

var resp *APIResponse

resp = h.IcingaClient.Objects().Notifications(host).Create([]string{alert.GetName(), alert.GetName()}, string(jsonStr)).Do()
resp = h.IcingaClient.Notifications(host).Create([]string{alert.GetName(), alert.GetName()}, string(jsonStr)).Do()

if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to create Icinga Notification")
Expand All @@ -227,7 +227,7 @@ func (h *commonHost) reconcileIcingaNotification(alert api.Alert, kh IcingaHost)
return errors.Errorf("Failed to create Icinga notification. Status: %d", resp.Status)
}

resp = h.IcingaClient.Objects().Notifications(host).Update([]string{alert.GetName(), alert.GetName()}, string(jsonStr)).Do()
resp = h.IcingaClient.Notifications(host).Update([]string{alert.GetName(), alert.GetName()}, string(jsonStr)).Do()

if resp.Err != nil {
return errors.Wrap(resp.Err, "Failed to update Icinga Notification")
Expand Down
3 changes: 1 addition & 2 deletions pkg/icinga/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ func (c *Client) newRequest(path string) *APIRequest {
}
client := &http.Client{Transport: tr}

c.pathPrefix = c.pathPrefix + path
return &APIRequest{
uri: c.config.Endpoint + c.pathPrefix,
uri: c.config.Endpoint + path,
client: client,
userName: c.config.BasicAuth.Username,
password: c.config.BasicAuth.Password,
Expand Down
42 changes: 31 additions & 11 deletions plugins/notifier/sms.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,47 @@ import (
api "github.com/appscode/searchlight/apis/monitoring/v1alpha1"
)

type SMS struct {
AlertName string
NotificationType string
ServiceState string
Author string
Comment string
Hostname string
}

func (n *notifier) RenderSMS(receiver api.Receiver) string {
opts := n.options
var msg string
m := &SMS{
AlertName: opts.alertName,
NotificationType: opts.notificationType,
ServiceState: receiver.State,
Author: opts.author,
Comment: opts.comment,
Hostname: opts.hostname,
}

switch api.AlertType(opts.notificationType) {
return m.Render()
}

func (m *SMS) Render() string {
var msg string
switch api.AlertType(m.NotificationType) {
case api.NotificationAcknowledgement:
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.\nThis issue is acked.", opts.alertName, opts.hostname, receiver.State)
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.\nThis issue is acked.", m.AlertName, m.Hostname, m.ServiceState)
case api.NotificationRecovery:
msg = fmt.Sprintf("Service [%s] for [%s] was in \"%s\" state.\nThis issue is recovered.", opts.alertName, opts.hostname, receiver.State)
msg = fmt.Sprintf("Service [%s] for [%s] was in \"%s\" state.\nThis issue is recovered.", m.AlertName, m.Hostname, m.ServiceState)
case api.NotificationProblem:
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.\nCheck this issue in Icingaweb.", opts.alertName, opts.hostname, receiver.State)
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.\nCheck this issue in Icingaweb.", m.AlertName, m.Hostname, m.ServiceState)
default:
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.", opts.alertName, opts.hostname, receiver.State)
msg = fmt.Sprintf("Service [%s] for [%s] is in \"%s\" state.", m.AlertName, m.Hostname, m.ServiceState)
}
if opts.comment != "" {
if opts.author != "" {
msg = msg + " " + fmt.Sprintf(`%s says "%s".`, opts.author, opts.comment)
if m.Comment != "" {
if m.Author != "" {
msg = msg + " " + fmt.Sprintf(`%s says "%s".`, m.Author, m.Comment)
} else {
msg = msg + " " + fmt.Sprintf(`Comment: "%s".`, opts.comment)
msg = msg + " " + fmt.Sprintf(`Comment: "%s".`, m.Comment)
}
}

return msg
}
10 changes: 5 additions & 5 deletions test/e2e/cluster_alert_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e2e_test
package e2e

import (
"strconv"
Expand Down Expand Up @@ -35,15 +35,15 @@ var _ = Describe("ClusterAlert", func() {
Expect(err).NotTo(HaveOccurred())

By("Check icinga services")
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta, alert.Spec).
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta).
Should(HaveIcingaObject(icingaServiceState))

By("Delete clusteralert")
err = f.DeleteClusterAlert(alert.ObjectMeta)
Expect(err).NotTo(HaveOccurred())

By("Wait for icinga services to be deleted")
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta, alert.Spec).
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta).
Should(HaveIcingaObject(IcingaServiceState{}))
}

Expand Down Expand Up @@ -107,15 +107,15 @@ var _ = Describe("ClusterAlert", func() {
Expect(err).NotTo(HaveOccurred())

By("Check icinga services")
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta, alert.Spec).
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta).
Should(HaveIcingaObject(icingaServiceState))

By("Delete clusteralert")
err = f.DeleteClusterAlert(alert.ObjectMeta)
Expect(err).NotTo(HaveOccurred())

By("Wait for icinga services to be deleted")
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta, alert.Spec).
f.EventuallyClusterAlertIcingaService(alert.ObjectMeta).
Should(HaveIcingaObject(IcingaServiceState{}))
}

Expand Down
13 changes: 6 additions & 7 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package e2e_test
package e2e

import (
"flag"
Expand All @@ -12,7 +12,6 @@ import (
cs "github.com/appscode/searchlight/client/clientset/versioned"
"github.com/appscode/searchlight/pkg/icinga"
"github.com/appscode/searchlight/pkg/operator"
"github.com/appscode/searchlight/test/e2e"
"github.com/appscode/searchlight/test/e2e/framework"
. "github.com/appscode/searchlight/test/e2e/matcher"
. "github.com/onsi/ginkgo"
Expand Down Expand Up @@ -69,7 +68,7 @@ var _ = BeforeSuite(func() {
// Framework
root = framework.New(kubeClient, apiExtKubeClient, extClient, nil, provider, storageClass)

e2e.PrintSeparately("Using namespace " + root.Namespace())
framework.PrintSeparately("Using namespace " + root.Namespace())

// Create namespace
err = root.CreateNamespace()
Expand Down Expand Up @@ -108,8 +107,8 @@ var _ = BeforeSuite(func() {
CACert: nil,
}

cfg.BasicAuth.Username = e2e.ICINGA_API_USER
cfg.BasicAuth.Password = e2e.ICINGA_API_PASSWORD
cfg.BasicAuth.Username = ICINGA_API_USER
cfg.BasicAuth.Password = ICINGA_API_PASSWORD

// Icinga Client
icingaClient := icinga.NewClient(*cfg)
Expand All @@ -120,7 +119,7 @@ var _ = BeforeSuite(func() {
Expect(err).NotTo(HaveOccurred())
fmt.Println()
fmt.Println("Icingaweb2: ", fmt.Sprintf("http://%v/", icingawebEndpoint))
fmt.Println("Login password: ", e2e.ICINGA_WEB_UI_PASSWORD)
fmt.Println("Login password: ", ICINGA_WEB_UI_PASSWORD)
fmt.Println()

// Controller
Expand All @@ -140,5 +139,5 @@ var _ = AfterSuite(func() {
root.CleanClusterAlert()
err := root.DeleteNamespace()
Expect(err).NotTo(HaveOccurred())
e2e.PrintSeparately("Deleted namespace")
framework.PrintSeparately("Deleted namespace")
})
Loading