This repository has been archived by the owner on Jun 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
273 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/vendor/*/ | ||
!/vendor/vendor.json | ||
|
||
/terraform-provider-uptime-robot | ||
/terraform-provider-uptimerobot | ||
|
||
*.tfvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"strings" | ||
) | ||
|
||
func uptimerobotAPICall( | ||
apiKey string, | ||
endpoint string, | ||
params string, | ||
) (map[string]interface{}, error) { | ||
url := "https://api.uptimerobot.com/v2/" + endpoint | ||
|
||
payload := strings.NewReader( | ||
fmt.Sprintf("api_key=%s&format=json&%s", apiKey, params), | ||
) | ||
|
||
req, _ := http.NewRequest("POST", url, payload) | ||
|
||
req.Header.Add("cache-control", "no-cache") | ||
req.Header.Add("content-type", "application/x-www-form-urlencoded") | ||
|
||
res, err := http.DefaultClient.Do(req) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
defer res.Body.Close() | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
fmt.Println(res) | ||
fmt.Println(string(body)) | ||
|
||
var result map[string]interface{} | ||
json.Unmarshal([]byte(body), &result) | ||
|
||
if result["stat"] != "ok" { | ||
message, _ := json.Marshal(result["error"]) | ||
return nil, errors.New("Got error from UptimeRobot: " + string(message)) | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
var alertContactTypes = map[string]int{ | ||
"sms": 1, | ||
"email": 2, | ||
"twitter-dm": 3, | ||
"boxcar": 4, | ||
"webhook": 5, | ||
"pushbullet": 6, | ||
"zapier": 7, | ||
"pushover": 8, | ||
"hipchat": 10, | ||
"slack": 11, | ||
} | ||
|
||
func resourceAlertContact() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceAlertContactCreate, | ||
Read: resourceAlertContactRead, | ||
Update: resourceAlertContactUpdate, | ||
Delete: resourceAlertContactDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"friendly_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
ValidateFunc: func(i interface{}, k string) (s []string, es []error) { | ||
v, ok := i.(string) | ||
if !ok { | ||
es = append(es, fmt.Errorf("expected type of %s to be string", k)) | ||
return | ||
} | ||
|
||
if _, ok := alertContactTypes[v]; !ok { | ||
es = append(es, fmt.Errorf("unknown type for %s", v)) | ||
return | ||
} | ||
|
||
return | ||
}, | ||
}, | ||
"value": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func resourceAlertContactCreate(d *schema.ResourceData, m interface{}) error { | ||
data := url.Values{} | ||
data.Add("friendly_name", d.Get("friendly_name").(string)) | ||
data.Add("type", fmt.Sprintf("%d", alertContactTypes[d.Get("type").(string)])) | ||
data.Add("value", d.Get("value").(string)) | ||
|
||
body, err := uptimerobotAPICall( | ||
m.(UptimeRobotConfig).apiKey, | ||
"newAlertContact", | ||
data.Encode(), | ||
) | ||
if err != nil { | ||
return err | ||
} | ||
alertcontact := body["alertcontact"].(map[string]interface{}) | ||
d.SetId(fmt.Sprintf("%d", int(alertcontact["id"].(float64)))) | ||
return nil | ||
} | ||
|
||
func resourceAlertContactRead(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceAlertContactUpdate(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceAlertContactDelete(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func resourceMonitor() *schema.Resource { | ||
return &schema.Resource{ | ||
Create: resourceMonitorCreate, | ||
Read: resourceMonitorRead, | ||
Update: resourceMonitorUpdate, | ||
Delete: resourceMonitorDelete, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"friendly_name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"url": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"sub_type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
// required for port monitoring | ||
}, | ||
"port": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
// required for port monitoring | ||
}, | ||
"keyword_type": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
// required for keyword monitoring | ||
}, | ||
"keyword_value": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
// required for keyword monitoring | ||
}, | ||
"interval": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"http_username": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"http_password": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
"alert_contacts": &schema.Schema{ | ||
// FIXME - array of id,threshold,recurrence | ||
Type: schema.TypeString, | ||
Optional: true, | ||
}, | ||
// TODO - mwindows | ||
// TODO - custom_http_headers | ||
// TODO - ignore_ssl_errors | ||
}, | ||
} | ||
} | ||
|
||
func resourceMonitorCreate(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceMonitorRead(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceMonitorUpdate(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} | ||
|
||
func resourceMonitorDelete(d *schema.ResourceData, m interface{}) error { | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters