Skip to content

Instantly share code, notes, and snippets.

@charliemoseley
Created April 9, 2015 13:22
Show Gist options
  • Save charliemoseley/3fd6b0590893ae0baf05 to your computer and use it in GitHub Desktop.
Save charliemoseley/3fd6b0590893ae0baf05 to your computer and use it in GitHub Desktop.
Simple script to load a bunch of test monitors into API Science.
var https = require("https");
loopCount = process.argv[2];
if (typeof loopCount === 'undefined') {
loopCount = 1;
}
location = process.argv[3];
if (typeof location === 'undefined') {
location = 'or';
}
var post_data = JSON.stringify({
name: 'TEST Monitor ' + location,
frequency: 1,
active: true,
location: 'or',
templates:
[
{
method: 'get',
url: 'http://graph.facebook.com/ibm'
},
{
method: 'get',
url: 'http://graph.facebook.com/microsoft'
}
]
});
var post_options = {
host: 'api.apiscience.com',
port: 443,
path: '/v1/monitors',
method: 'post',
headers: { 'Authorization' : 'Bearer g1Fq_N6x9nh0FpRWGScmug', 'Content-Type' : 'application/json', 'Content-Length' : post_data.length }
};
for (i = 0; i < loopCount; i++) {
post_request = https.request(post_options, function(res) {
console.log('STATUS: ' + res.statusCode);
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log('BODY: ' + chunk);
});
});
post_request.write(post_data);
post_request.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment