Created
April 9, 2015 14:24
-
-
Save charliemoseley/6e28000bd83613eb3cf4 to your computer and use it in GitHub Desktop.
Simple script to add demo monitors to API Science (v2).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var https = require("https"); | |
loopCount = process.argv[2]; | |
if (typeof loopCount === 'undefined') { | |
loopCount = 1; | |
} | |
location = process.argv[3]; | |
if (typeof location === 'undefined') { | |
location = 'or'; | |
} | |
for (i = 0; i < loopCount; i++) { | |
var post_data = JSON.stringify({ | |
name: 'TEST Monitor ' + (i + 1) + ' ' + location, | |
frequency: 1, | |
active: true, | |
location: location, | |
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 } | |
}; | |
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