cancel
Showing results for 
Search instead for 
Did you mean: 
Create Post
Level 8

HTTP Headers in Alert Actions - POST/Get URL

Jump to solution

I'm attempting to write an alert action that POSTs data to a URL (Cisco Spark Bot message).  Cisco requires you include HTTP Headers with your authentication token.  Without having to resort to run a powershell script, is there any way with the Native POST action to include additional HTTP headers?

Updating most  modern REST services would require this (the auth token is generally something you include in the header).

Labels (2)
1 Solution

I can see a couple of other reasons you'd want to manipulate headers as well, like a REST API that requires a particular content-type or otherwise it barfs, spews XML when you least desire it or other general missfeatureism. Proxy directives, caching control, user-agent and other headers are also candidates for specific settings.  I've been nagging the platform team for a REST/POST action for a couple of years, and will renew the push.  You can also add it to the feature request list in THWACK and I'll up-vote it.

In the meantime, Powershell is the way to go, especially because you could standardize many of the elements you need and pass way fewer elements, way easier, than a wonky URI shoehorned into an alert field.  For example, you'd have one script with your authentication, access tokes and everything else, and could even restrict access to that file for security so that only admins and Orion could see/execute it.  That way you're not putting authentication details in every alert that's calling the script.

Hope that helps.

View solution in original post

17 Replies
Level 7

Anyone  able to lend a hand? Sending HTTP POSTs to a Shim server to then format and authenticate with our incident/ticket platform but the HTTP POST the shim server receives is completely empty. Shim server is written in python using Flask,uWSGI and Nginx. The HTTP header Content-Length is 4 which indicates there is something in the body. Yet it's completely empty even though I'm dumping the raw request.

Is this an issue on SolarWinds end or my shim server. It works perfectly with some of our other monitoring platforms.

0 Kudos
Community Manager
Community Manager

I'm not an expert on the Cisco Spark interface, but I did just test it out with a little bit of PowerShell goodness.  So, the simple answer is that this is possible, and not too difficult.

# Script Variables
$User        = "this is your bot's email @ sparkbot.io"
$AccessToken = "put the bot's access token here"


# Create a Dictionary Object for the Header information
$Headers = @{ Authorization = "Bearer $AccessToken" }

# A few URI's that I got from the Cisco Dev pages - there are more.
$PeopleUri = "https://api.ciscospark.com/v1/people?email=$User"
$RoomsUri  = "https://api.ciscospark.com/v1/rooms?email=$User"

# Query for users
# - Use headers for authentication
# - Make a request using the "GET" method)
$Results = Invoke-RestMethod -Uri $PeopleUri -Method Get -Headers $Headers
$Results.Items

# Create something
# - Use same headers for authentication
# - Craft the "body" of the message
# - Convert that "body" to Json
# - Make a request using the "POST" method
$ContentType = "application/json"
$RoomContent = @{ title = "Test Room" } | ConvertTo-Json
$Results = Invoke-RestMethod -Uri $RoomsUri -Headers $Header -ContentType $ContentType -Method Post -Body $RoomContent

$Results.Items

"Shoot for the stars to reach the moon"

Shouldn't have to resort to Powershell when all solarwinds needs to do is add a Headers option, everything else is already there, but I like your script example here!

The issue we have currently is there is a proxy involved, which requires authentication.  This means naturally it doesn't work with Solarwinds running the powershell command unless I embed a username/password in the script...nasty.

Hi,

Having a problem on sending an http post request from solarwinds to request tracker.

Request tracker is a ticketing tool which we use for a job order. So, we want to integrate

it with Solarwinds to create a ticket whenever there's an active alert.

The connection between the two servers are established but can't generate a ticket in

RT. Another problem is we can't see where's the problem or what is the cause.

Could you please help.

Thank you in advance

pastedImage_0.png

0 Kudos

you have commas missing from between the arguments at he very least

0 Kudos

already tried putting a comma(s) but still unlucky.

the post body doesn't show up.

the code might wrong.

Richard Letts, if you have some simple code that works on solarwinds and post to a 3rd party which

an REST API environment like on what i used (Request Tracker), could you please provide me one.

Thank you in advance.

0 Kudos

1. get it working from the command line using curl

2. get it working in solarwinds

right now you're trying to troubleshoot something using  a black-box approach; that might work for computer science student projects but fails in the real world.

Once you have input that creates a ticket  you may need to up the debug logging on the alert manager and look at the logfiles when the action triggers.

The questions in the standard litany can be paraphrased when it comes to the use of computers:

  • What did you do? What actual commands or tests did you run? Where precisely did you run them? What was your exact configuration?
  • What did the computer actually do? What were the exact test results, complete log contents, and exact error messages that were issued?
  • What did you expect the computer to do? What did you expect the computer to do instead? What were you aiming to achieve and what makes you think that you aren't actually achieving it?

Is Solarwinds work using JSON or using XML?

Advise appreciated.

Thank you.

0 Kudos

Is this supposed to be JSON in the body?  If so, the container should be surrounded with curly braces ( '{' & '}' ) not brackets ( '[' & ']' ).  I don't know RT, but that might help.

"Shoot for the stars to reach the moon"
0 Kudos

Thank you for the response KMSigma but I already tried curly braces and still no problem shown but still doesn't create a post (ticket on the web server of Request Tracker).

0 Kudos

Worth a try.  Without knowing more about how the REST API works for that product, I can't really provide too much more insight.

"Shoot for the stars to reach the moon"
0 Kudos

Hi KMSigma,

  REST - Request Tracker Wiki this is our guide on creation a ticket on Request Tracker. Could you please take a look for a little bit on how our 3rd party works.

  What API does Solarwinds used?

  Your help is very much appreciated.

Thank you.

0 Kudos

I can see a couple of other reasons you'd want to manipulate headers as well, like a REST API that requires a particular content-type or otherwise it barfs, spews XML when you least desire it or other general missfeatureism. Proxy directives, caching control, user-agent and other headers are also candidates for specific settings.  I've been nagging the platform team for a REST/POST action for a couple of years, and will renew the push.  You can also add it to the feature request list in THWACK and I'll up-vote it.

In the meantime, Powershell is the way to go, especially because you could standardize many of the elements you need and pass way fewer elements, way easier, than a wonky URI shoehorned into an alert field.  For example, you'd have one script with your authentication, access tokes and everything else, and could even restrict access to that file for security so that only admins and Orion could see/execute it.  That way you're not putting authentication details in every alert that's calling the script.

Hope that helps.

View solution in original post

Hi Patrick, Any progress on this FR as we have a similar requirement where in we need to automate using REST API Integration with a services provider and not able to connect via Proxy and also Authentication ....

I agree on the need for Header manipulation, thanks for the detail. 

Level 18

Let me dig into this. Also flagging jbiggleyDezKMSigmapatrick.hubbard​ & cobrien​ because they KNOW THINGS.

Leon Adato | Head Geek
------
"Measure what is measurable,
and make measurable what is not so." - Gallileo

I've never tried this and it is on the periphery of my skills, but if you stored the auth token as a custom property you should be able to use the POST method and simple add the variable for the custom property into the URL.  That feels like a bit of a hack way to do it though.

You might be better off doing it via PowerShell.