Closed harshaabba closed 6 years ago
@tdanner can chime in here, but I think the issue you're going to run into is the inability to change the content-type from key/value pairs when using the "GET or POST" alert action. To make changes to the headers you're going to have to use the "External Executable" alert action and build the POST request yourself.
I'm happy to prototype something if you tell me what language you prefer.
Thanks a lot mrxinu for the quick response. you can use whatever language prefer you and easier for you. do I need to execute a external script for this to achieve ? I really appreciate your help in this regard. Please let me know if you need more information. I have blank knowledge integrating API to solar winds. Thanks a lot for the support. I highly value it
Written in Go:
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("https://api.whispir.com/messages?apikey=%s", 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))
}
@mrxinu , Thanks a lot for the script. I highly value it. I have some clarification to make.
Body: "${N=SwisEntity;M=DisplayName} : ${N=SwisEntity;M=IP_Address} is Down",
Thanks again for the response. Can you please help me with this as well. Since I have fair knowledge scripting I highly value your response.
Thannks
Hey @harshaabba,
Would you mind creating a thread on the SolarWinds user forum so we can discuss it there? This isn't really the place for it and I think we might have a few iterations before it does quite what you want.
The area of the SolarWinds forum you want is here: https://thwack.solarwinds.com/community/labs/orion-sdk
Thanks in advance!
Hi All,
I need to trigger an SMS Alert once the priority node goes down. I have received a API from a vendor called 'Whispir'. There are two ways to achieve this
HTTP 1.1 POST https://api.whispir.com/messages?apikey=[your_key] Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk
Content-Type: application/vnd.whispir.message-v1+json Accept: application/vnd.whispir.message-v1+json
{ "to" : "+1000000000", "subject" : "Test SMS Message", "body" : "This is the body of my test SMS message" }
HTTP 1.1 POST https://api.whispir.com/messages?apikey=[your_key] Authorization: Basic am9obi5zbWl0aDpteXBhc3N3b3Jk
Content-Type: application/vnd.whispir.message-v1+xml Accept: application/vnd.whispir.message-v1+xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>