refactor: Updated and added more options for http proxy support (#4718)

This commit is contained in:
Neil Lathwood 2016-10-14 02:07:07 +01:00 committed by Tony Murray
parent 6073ba6112
commit d5ba013a8a
13 changed files with 67 additions and 14 deletions

View File

@ -289,7 +289,9 @@ $config['alert']['transports']['irc'] = true;
> You can configure these options within the WebUI now, please avoid setting these options within config.php
The Slack transport will POST the alert message to your Slack Incoming WebHook using the [attachments](https://api.slack.com/docs/message-attachments) option, you are able to specify multiple webhooks along with the relevant options to go with it. Simple html tags are stripped from the message. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options:
[Using a proxy?](../Support/Configuration.md#proxy-support)
The Slack transport will POST the alert message to your Slack Incoming WebHook using the [attachments](https://api.slack.com/docs/message-attachments) option, you are able to specify multiple webhooks along with the relevant options to go with it. Simple html tags are stripped from the message. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options:
~~
```php
@ -304,6 +306,8 @@ $config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack.
> You can configure these options within the WebUI now, please avoid setting these options within config.php
[Using a proxy?](../Support/Configuration.md#proxy-support)
The HipChat transport requires the following:
__room_id__ = HipChat Room ID
@ -353,6 +357,8 @@ $config['alert']['transports']['hipchat'][] = array("url" => "https://api.hipcha
> You can configure these options within the WebUI now, please avoid setting these options within config.php
[Using a proxy?](../Support/Configuration.md#proxy-support)
Enabling PagerDuty transports is almost as easy as enabling email-transports.
All you need is to create a Service with type Generic API on your PagerDuty dashboard.
@ -371,6 +377,8 @@ __Note__: Currently ACK notifications are not transported to PagerDuty, This is
## <a name="transports-pushover">Pushover</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
Enabling Pushover support is fairly easy, there are only two required parameters.
Firstly you need to create a new Application (called LibreNMS, for example) in your account on the Pushover website (https://pushover.net/apps)
@ -400,6 +408,8 @@ $config['alert']['transports']['pushover'][] = array(
## <a name="transports-boxcar">Boxcar</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
Enabling Boxcar support is super easy.
Copy your access token from the Boxcar app or from the Boxcar.io website and setup the transport in your config.php like:
@ -424,6 +434,8 @@ $config['alert']['transports']['boxcar'][] = array(
## <a name="transports-pushbullet">Pushbullet</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
Enabling Pushbullet is a piece of cake.
Get your Access Token from your Pushbullet's settings page and set it in your config like:
@ -435,6 +447,8 @@ $config['alert']['transports']['pushbullet'] = 'MYFANCYACCESSTOKEN';
## <a name="transports-clickatell">Clickatell</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
Clickatell provides a REST-API requiring an Authorization-Token and at least one Cellphone number.
Please consult Clickatell's documentation regarding number formatting.
Here an example using 3 numbers, any amount of numbers is supported:
@ -450,6 +464,8 @@ $config['alert']['transports']['clickatell']['to'][] = '+1234567892';
## <a name="transports-playsms">PlaySMS</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
PlaySMS is an open source SMS-Gateway that can be used via their HTTP-API using a Username and WebService-Token.
Please consult PlaySMS's documentation regarding number formatting.
Here an example using 3 numbers, any amount of numbers is supported:
@ -467,6 +483,8 @@ $config['alert']['transports']['playsms']['to'][] = '+1234567891';
## <a name="transports-victorops">VictorOps</a>
[Using a proxy?](../Support/Configuration.md#proxy-support)
VictorOps provide a webHook url to make integration extremely simple. To get the URL required login to your VictorOps account and go to:
Settings -> Integrations -> REST Endpoint -> Enable Integration.

View File

@ -93,13 +93,30 @@ $config['neato'] = "/usr/bin/neato";
$config['sfdp'] = "/usr/bin/sfdp";
```
#### Proxy support
For alerting and the callback functionality, we support the use of a http proxy setting.
These can be any one of the following:
```php
$config['callback_proxy'] = 'proxy.domain.com';
$config['http_proxy'] = 'proxy.domain.com';
```
We can also make use of one of these environment variables which can be set in `/etc/environment`:
```bash
http_proxy=proxy.domain.com
https_proxy=proxy.domain.com
```
#### Memcached
[Memcached](../Extensions/Memcached.md]
[Memcached](../Extensions/Memcached.md)
#### RRDCached
[RRDCached](../Extensions/RRDCached.md]
[RRDCached](../Extensions/RRDCached.md)
#### WebUI Settings

View File

@ -31,6 +31,7 @@ foreach( $opts as $method=>$apis ) {
}
// var_dump($api); //FIXME: propper debuging
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, ($method == "get" ? $host."?".$api : $host) );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, strtoupper($method));

View File

@ -77,6 +77,7 @@ foreach( $opts as $api ) {
}
$data['notification[long_message]'] = $message_text;
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, 'https://new.boxcar.io/api/notifications');
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

View File

@ -27,7 +27,7 @@ if (!empty($opts['from'])) {
}
$url = 'https://api.clickatell.com/http/sendmsg?'.http_build_query($data);
$curl = curl_init($url);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

View File

@ -55,7 +55,7 @@ foreach($opts as $option) {
$data[] = "message_format=".urlencode($option["message_format"]);
$data = implode('&', $data);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);

View File

@ -40,6 +40,7 @@ foreach( $obj['faults'] as $fault=>$data ) {
$protocol['details'][] = $data['string'];
}
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, 'https://events.pagerduty.com/generic/2010-04-15/create_event.json' );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type'=> 'application/json'));

View File

@ -28,6 +28,7 @@ if (!empty($opts['from'])) {
$url = $opts['url'].'&op=pv&'.http_build_query($data);
$curl = curl_init($url);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

View File

@ -27,6 +27,7 @@ $data = array("type" => "note", "title" => $obj['title'], "body" => $obj['msg'])
$data = json_encode($data);
$curl = curl_init('https://api.pushbullet.com/v2/pushes');
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

View File

@ -79,6 +79,7 @@ foreach( $opts as $api ) {
}
$data['message'] = $message_text;
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, 'https://api.pushover.net/1/messages.json');
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);

View File

@ -44,6 +44,7 @@ foreach( $opts as $tmp_api ) {
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json')
);
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, $host);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST,true);

View File

@ -44,6 +44,7 @@ foreach( $obj['faults'] as $fault=>$data ) {
}
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, $url );
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type'=> 'application/json'));

View File

@ -1118,18 +1118,28 @@ function guidv4($data)
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
function set_curl_proxy($post)
/**
* @param $curl
*/
function set_curl_proxy($curl)
{
global $config;
if (isset($_ENV['https_proxy'])) {
$tmp = rtrim($_ENV['https_proxy'], "/");
$proxystr = str_replace(array("http://", "https://"), "", $tmp);
$config['callback_proxy'] = $proxystr;
echo "Setting proxy to ".$proxystr." (from https_proxy=".$_ENV['https_proxy'].")\n";
$proxy = '';
if (getenv('http_proxy')) {
$proxy = getenv('http_proxy');
} elseif (getenv('https_proxy')) {
$proxy = getenv('https_proxy');
} elseif (isset($config['callback_proxy'])) {
$proxy = $config['callback_proxy'];
} elseif (isset($config['http_proxy'])) {
$proxy = $config['http_proxy'];
}
if (isset($config['callback_proxy'])) {
echo "Using ".$config['callback_proxy']." as proxy\n";
curl_setopt($post, CURLOPT_PROXY, $config['callback_proxy']);
$tmp = rtrim($proxy, "/");
$proxy = str_replace(array("http://", "https://"), "", $tmp);
if (!empty($proxy)) {
curl_setopt($curl, CURLOPT_PROXY, $proxy);
}
}