Skip to content
This repository has been archived by the owner on Oct 29, 2020. It is now read-only.

Commit

Permalink
Merge pull request #46 from timonwalkley/feature/issue-99
Browse files Browse the repository at this point in the history
Add runbook url to infrastructure alert condition
  • Loading branch information
paultyng committed Mar 25, 2019
2 parents 1ef982e + b2ac40d commit 6cad480
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions api/alert_infra_conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,63 @@ func TestCreateAlertInfraConditionWithIntegrationProvider(t *testing.T) {
}
}

func TestCreateAlertInfraConditionWithRunbookURL(t *testing.T) {
c := newTestAPIInfraClient(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
w.Write([]byte(`
{
"data":{
"type":"infra_metric",
"name":"Disk Space Condition",
"runbook_url": "https://example.com/runbook.md",
"enabled":true,
"policy_id":123,
"id":12345,
"event_type":"StorageSample",
"select_value":"diskFreePercent",
"comparison":"below",
"warning_threshold":{
"value":30,
"duration_minutes":2,
"time_function":"any"
}
}
}
`))
}))

infraAlertConditionWarning := &AlertInfraThreshold{
Value: 30,
Duration: 100,
Function: "any",
}

infraAlertCondition := AlertInfraCondition{
PolicyID: 123,
Name: "Disk Space Condition",
RunbookURL: "https://example.com/runbook.md",
Enabled: true,
Warning: infraAlertConditionWarning,
Comparison: "below",
Event: "StorageSample",
Select: "diskFreePercent",
}

infraAlertConditionResp, err := c.CreateAlertInfraCondition(infraAlertCondition)
if err != nil {
t.Log(err)
t.Fatal("CreateAlertInfraConditionWithRunbookURL error")
}
if infraAlertConditionResp == nil {
t.Log(err)
t.Fatal("CreateAlertInfraConditionWihtRunbookURL error")
}
if infraAlertConditionResp.RunbookURL != "https://example.com/runbook.md" {
t.Fatal("Runbook URL was not parsed correctly")
}
}

func TestDeleteAlertInfraCondition(t *testing.T) {
policyID := 123
conditionID := 12345
Expand Down
1 change: 1 addition & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ type AlertInfraCondition struct {
PolicyID int `json:"policy_id,omitempty"`
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
RunbookURL string `json:"runbook_url,omitempty"`
Type string `json:"type,omitempty"`
Comparison string `json:"comparison,omitempty"`
CreatedAt int `json:"created_at_epoch_millis,omitempty"`
Expand Down

0 comments on commit 6cad480

Please sign in to comment.