| 1 |
<?php declare(strict_types=1); |
| 2 |
|
| 3 |
/* |
| 4 |
* This file is part of the Monolog package. |
| 5 |
* |
| 6 |
* (c) Jordi Boggiano <[email protected]> |
| 7 |
* |
| 8 |
* For the full copyright and license information, please view the LICENSE |
| 9 |
* file that was distributed with this source code. |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Monolog\Handler; |
| 13 |
|
| 14 |
use Monolog\Logger; |
| 15 |
|
| 16 |
/** |
| 17 |
* Inspired on LogEntriesHandler. |
| 18 |
* |
| 19 |
* @author Robert Kaufmann III <[email protected]> |
| 20 |
* @author Gabriel Machado <[email protected]> |
| 21 |
*/ |
| 22 |
class InsightOpsHandler extends SocketHandler |
| 23 |
{ |
| 24 |
/** |
| 25 |
* @var string |
| 26 |
*/ |
| 27 |
protected $logToken; |
| 28 |
|
| 29 |
/** |
| 30 |
* @param string $token Log token supplied by InsightOps |
| 31 |
* @param string $region Region where InsightOps account is hosted. Could be 'us' or 'eu'. |
| 32 |
* @param bool $useSSL Whether or not SSL encryption should be used |
| 33 |
* |
| 34 |
* @throws MissingExtensionException If SSL encryption is set to true and OpenSSL is missing |
| 35 |
*/ |
| 36 |
public function __construct(string $token, string $region = 'us', bool $useSSL = true, $level = Logger::DEBUG, bool $bubble = true) |
| 37 |
{ |
| 38 |
if ($useSSL && !extension_loaded('openssl')) { |
| 39 |
throw new MissingExtensionException('The OpenSSL PHP plugin is required to use SSL encrypted connection for InsightOpsHandler'); |
| 40 |
} |
| 41 |
|
| 42 |
$endpoint = $useSSL |
| 43 |
? 'ssl://' . $region . '.data.logs.insight.rapid7.com:443' |
| 44 |
: $region . '.data.logs.insight.rapid7.com:80'; |
| 45 |
|
| 46 |
parent::__construct($endpoint, $level, $bubble); |
| 47 |
$this->logToken = $token; |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* {@inheritDoc} |
| 52 |
*/ |
| 53 |
protected function generateDataStream(array $record): string |
| 54 |
{ |
| 55 |
return $this->logToken . ' ' . $record['formatted']; |
| 56 |
} |
| 57 |
} |
| 58 |
|