diff --git a/README.md b/README.md index 365939d..e968b56 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,32 @@ var options = { dogapi.initialize(options); ``` +### HTTPS Proxy + +If you are behind a proxy you need to a proxy agent. You can use the https proxy agent from +http://blog.vanamco.com/proxy-requests-in-node-js/ if you like. +To configure dogapi with the agent just add it to the options. + +```javascript +var dogapi = require("dogapi"); + +//Code from http://blog.vanamco.com/proxy-requests-in-node-js/ +var HttpsProxyAgent = require("./httpsproxyagent"); + +var agent = new HttpsProxyAgent({ + proxyHost: "MY_PROXY_HOST", + proxyPort: 3128 +}); + +var options = { + api_key: "YOUR_KEY_HERE", + app_key: "YOUR_KEY_HERE", + proxy_agent: agent +}; + +dogapi.initialize(options); +``` + ## CLI Usage `dogapi` now ships with a command line interface `dogapi`. To use it you diff --git a/lib/api/graph.js b/lib/api/graph.js index 84fdbff..5902fd8 100644 --- a/lib/api/graph.js +++ b/lib/api/graph.js @@ -18,7 +18,7 @@ var client = require("../client"); * dogapi.initialize(options); * var query = "system.cpu.idle{*}"; * var to = dogapi.now(); - * var from = from - 3600; // an hour ago + * var from = to - 3600; // an hour ago * dogapi.graph.snapshot(query, from, to, function(err, res){ * console.dir(res); * }); diff --git a/lib/client.js b/lib/client.js index 3e91e40..88b209e 100644 --- a/lib/client.js +++ b/lib/client.js @@ -3,7 +3,6 @@ var https = require("https"); var url = require("url"); var util = require("util"); - /*section: client *comment: | * the constructor for _client_ object @@ -14,6 +13,7 @@ var util = require("util"); var client = function(){ this.api_key = null; this.app_key = null; + this.proxy_agent = null; this.api_version = "v1"; this.api_host = "app.datadoghq.com"; }; @@ -69,9 +69,13 @@ client.prototype.request = function(method, path, params, callback){ hostname: this.api_host, port: 443, method: method.toUpperCase(), - path: path, + path: path }; + if(this.proxy_agent){ + http_options["agent"] = this.proxy_agent; + } + if(["POST", "PUT"].indexOf(http_options["method"]) >= 0){ http_options["headers"] = { "Content-Type": "application/json", diff --git a/lib/index.js b/lib/index.js index 08f06fa..9e4ef18 100644 --- a/lib/index.js +++ b/lib/index.js @@ -11,13 +11,26 @@ require("./api")(module.exports); * * app_key: your app key * * api_version: the version of the api [default: `v1`] * * api_host: the host to call [default: `api.datadoghq.com`] + * * proxy_agent: Optional, A Https Proxy agent. *example: * | * ```javascript * var dogapi = require("dogapi"); + * + * // Optional for Proxy -------8<---------- + * // Code from http://blog.vanamco.com/proxy-requests-in-node-js/ + * var HttpsProxyAgent = require("./httpsproxyagent"); + * + * var agent = new HttpsProxyAgent({ + * proxyHost: "MY_PROXY_HOST", + * proxyPort: 3128 + * }); + * // Optional for Proxy -------->8---------- + * * var options = { * api_key: "", - * app_key: "" + * app_key: "", + * proxy_agent: agent // Optional for Proxy * }; * dogapi.initialize(options); * dogapi.event.create(...); diff --git a/package.json b/package.json index f639aa1..e8f198b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dogapi", - "version": "1.0.0", + "version": "1.0.1", "description": "Datadog API Node.JS Client", "main": "lib/index.js", "scripts": { @@ -25,7 +25,8 @@ "author": "Brett Langdon (http://brett.is)", "contributors": [ "colinjonesx (http://www.thetestpeople.com)", - "dalehamel (http://blog.srvthe.net)" + "dalehamel (http://blog.srvthe.net)", + "egut (https://github.com/egut)" ], "license": "MIT", "readmeFilename": "README.md",