Create alert or perfomacnce dashboard using curl command

Please paste the permalink to the page in question below:

Please share your question/describe your issue below. Include any screenshots that may help us understand your question:

Hey,

I would like to create alert or a performance dashboard based on a curl command.
Where can it be done & how ?

Regards,
Dudu

1 Like

Hi @Dudu_sla - As long as you have the correct permissons, you can use any of the API’s that are available.

Hey Stefan,

I need to create a synthetic monitor using HTTP API request.
How do I pass username + password parameters in HTTP POST request ?

Regards,
Dudu

Hi @Dudu_sla - the information for generating the cUrl requests is available in the API documentation samples.

If you are after an example of an API synthetic script then you could use my sample as a basis.

Hey @stefan_garnham

First of all 10x for your assistance, your script doesn’t include HTTP API authentication, and that it basically what I need.

I want to take a curl command and convert it into an HTTP API monitor.
I need to provide HTTP authentication for the url which needs to be monitored.
Then I need to parse several jason parameters and finally receive a result of 200 OK.

Regards,
Dudu

1 Like

I wrote this script, can you tell me if the syntax is correct ?
I left the json parameters empty, some of them are numbers and some them are strings.

var assert = require(‘assert’);
var username = ‘username’;
var password = ‘password’;

$http.post(‘https://’ + username + ‘:’ + password + ‘@blablabla.com’,
// Post data
{
json: {
id: ,
cloudAccountId: “”,
cloudAccountType: “”,
requestId: ‘’
}
},
// Callback
function (err, response, body) {
assert.equal(response.statusCode, 200, ‘Expected a 200 OK response’);

console.log('Response:', body.json);

}
);

This may help:

Hey @stefan_garnham,

I wrote a new check but still receive error 401.

Can you please take a look and tell me what is wrong, basically I don’t understand how to perform the authentication properly:

//Define your authentication credentials.
var myAccountID = ‘{AccountID}’;
var myInsertKey = ‘{Key}’;
//Import the assert module to validate results.
var assert = require(‘assert’);

var options = {
//Define endpoint URL.
url: “Test URL”,
//Define body of POST request.
body:’{id: ,cloudAccountId: “”,cloudNetwork: “”,region: “”}’,

//Define insert key and expected data type.
headers: {
    'Username': myAccountID,
    'Password': myInsertKey,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
    }

};

//Define expected results using callback function.
function callback(error, response, body) {
//Log status code to Synthetics console.
console.log(response.statusCode + " status code")
//Verify endpoint returns 200 (OK) response code.
assert.ok(response.statusCode == 200, ‘Expected 200 OK response’);
//Parse JSON received from Insights into variable.
var info = JSON.parse(body);
//Verify that info contains element named success with a value of true.
assert.ok(info.success == true, 'Expected True results in Response Body, result was ’ + info.success);
//Log end of script.
console.log(“End reached”);
}

//Make POST request, passing in options and callback.
$http.post(options, callback);

Hey @stefan_garnham

I’ve managed to solve the problem, I used basic authentication with to.string function.

/**

//Define your authentication credentials.
var APIID = ‘ID’;
var APIKey = ‘KEY’;
//Import the assert module to validate results.
var assert = require(‘assert’);
var api = APIID+’:’+APIKey;
var encodeAuth = “Basic " + new Buffer(APIID+”:"+APIKey).toString(“base64”);
var options = {
//Define endpoint URL.
url: “URL”,
//Define body of POST request.
body:’{id: ,cloudAccountId: “”,cloudNetwork: “”,region: “”}’,

//Define insert key and expected data type.
headers: {
    'Authorization': encodeAuth,
    'Content-Type': 'application/json',
    'Accept': 'application/json'
    }

};

//Define expected results using callback function.
function callback(error, response, body) {
//Log status code to Synthetics console.
console.log(response.statusCode + " status code")
//Verify endpoint returns 200 (OK) response code.
assert.ok(response.statusCode == 200, ‘Expected 200 OK response’);
//Log end of script.
console.log(“End reached”);
}

//Make POST request, passing in options and callback.
$http.post(options, callback);

2 Likes