Hi All,
There is a requirement to integrate API to trigger a sms alert. I am using whisper to send sms
Whispir Platform API
One member suggest me to use the following script to achieve this
package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
)
func main() {
username := "someuser"
password := "somepassword"
apiKey := "somekeyhere"
// build the URL
uri := fmt.Sprintf("api.whispir.com/messages, apiKey)
// build the request structure
rawBody := struct {
To string `json:"to"`
Subject string `json:"subject"`
Body string `json:"body"`
}{
To: "+1000000000",
Subject: "Test SMS Message",
Body: "This is the body of my test SMS message",
}
// convert that structure into a JSON request
body, err := json.Marshal(rawBody)
if err != nil {
log.Fatal(err)
}
// build the POST the request with the headers set appropriately
req, err := http.NewRequest("POST", uri, bytes.NewReader(body))
req.Header.Add("Content-Type", "application/vnd.whispir.message-v1+json")
req.Header.Add("Accept", "application/vnd.whispir.message-v1+json")
req.SetBasicAuth(username, password)
// submit the request
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatal(err)
}
// read the body of the results
content, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
// print the body of the results
fmt.Println(string(content))
}
My question is
What extension I should use to save this script. Is it .py ?
To the message can I include the node name and the ip address as follows ?
Body: "${N=SwisEntity;M=DisplayName} : ${N=SwisEntity;M=IP_Address} is Down",
SEND SMS using JSON
<span>HTTP 1.1 POST </span>api.whispir.com/messages<br />Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk<br />
Content-Type: application/vnd.whispir.message-v1+xml<br />Accept: application/vnd.whispir.message-v1+xml<br /><br /><span class="cp"><?xml version="1.0" encoding="UTF-8" standalone="yes"?></span><br /><span class="nt"><ns2:message</span> <span class="na">xmlns:ns2=</span><span class="s"><span>"</span><a class="jive-link-external-small" href="http://schemas.api.whispir.com" rel="nofollow">http://schemas.api.whispir.com</a><span>"</span></span><span class="nt">></span><br /> <span class="nt"><to></span>+1000000000<span class="nt"></to></span><br /> <span class="nt"><subject></span>Test SMS Message<span class="nt"></subject></span><br /> <span class="nt"><body></span>This is the body of my test SMS message<span class="nt"></body></span><br /><span class="nt"></ns2:message></span><br />
<span class="n">Content</span><span class="o">-</span><span class="n">Type</span><span class="o">:</span><span class="x"> </span><span class="n">application</span><span class="o">/</span><span class="n">vnd</span><span class="o">.</span><span class="n">whispir</span><span class="o">.</span><span class="n">message</span><span class="o">-</span><span class="n">v1</span><span class="o">+</span><span class="n">json</span><span class="x"><br /></span><span class="n">Accept</span><span class="o">:</span><span class="x"> </span><span class="n">application</span><span class="o">/</span><span class="n">vnd</span><span class="o">.</span><span class="n">whispir</span><span class="o">.</span><span class="n">message</span><span class="o">-</span><span class="n">v1</span><span class="o">+</span><span class="n">json</span><span class="x"><br /><br /></span><span class="p">{</span><span class="x"><br /> </span><span class="s">"to"</span><span class="x"> </span><span class="o">:</span><span class="x"> </span><span class="s">"+1000000000"</span><span class="p">,</span><span class="x"><br /> </span><span class="s">"subject"</span><span class="x"> </span><span class="o">:</span><span class="x"> </span><span class="s">"Test SMS Message"</span><span class="p">,</span><span class="x"><br /> </span><span class="s">"body"</span><span class="x"> </span><span class="o">:</span><span class="x"> </span><span class="s">"This is the body of my test SMS message"</span><span class="x"><br /></span><span class="p">}</span><span class="x"><br /></span>Response: 202 Accepted<br />Location: api.whispir.com/.../{id}<br /><br />