![Coverage Status][ico-scrutinizer]
![Total Downloads][ico-downloads], (*1)
Laravel and Non-Laravel Library To Connect to Incomings.io Service
, (*2)
Sign up for the service https://incomings.io, (*3)
Then setup and start watching your processes come in one place instead of 5 plus places!, (*4)
, (*5)
Docs below and at https://incomings.io/help, (*6)
Install
Tested on Laravel 4.2 and 5.x more platforms to be tested soon., (*7)
Composer install, (*8)
composer require alfred-nutile-inc/incomings-client:">=2.0"
Add to app.php, (*9)
'AlfredNutileInc\Incomings\IncomingsServiceProvider',
NOTE: If you are using Lumen, instead of the above you need to enable the provider in bootstrap/app.php like this:, (*10)
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
|
| Here we will register all of the application's service providers which
| are used to bind services into the container. Service providers are
| totally optional, so you are not required to uncomment this line.
|
*/
$app->register('AlfredNutileInc\Incomings\IncomingsServiceProvider');
Set in your .env, (*11)
INCOMINGS_URL=https://incomings.io
INCOMINGS_TOKEN=token_of_project
Laravel 5.6
Add the incomings
log channel to your config/logging.php
file:, (*12)
'channels' => [
'stack' => [
'driver' => 'stack',
// Add incomings to the stack:
'channels' => ['single', 'incomings'],
],
'incomings' => [
'driver' => 'incomings',
'level' => 'debug',
],
],
Send Data to the Service
URL
This is the most simple helper. Each project gets one, (*13)
@TODO fix broken image need to find the right one
, (*14)
So you can for example use that on Iron.io as a PUSH queue route since you can have more than one., (*15)
Or even on your server setup a cron job to post every minute your server resource status or security status., (*16)
Example Iron.io, (*17)
, (*18)
Laravel Facade
Say you are about to send off to a queue, (*19)
Queue::push("foo", $data);
Now try, (*20)
$data = ['title' => 'Foo Bar', 'message' => [1,2,3]]
Incomings::send($data);
Queue::push("foo", $data);
For the above Facade to work you might have to add, (*21)
use AlfredNutileInc\Incomings\IncomingsFacade as Incomings;
NOTE: If you're using Lumen, make sure to enable facades in bootstrap/app.php with $app->withFacades();
, (*22)
Also see Laravel Docs for failed Queue https://laravel.com/docs/5.2/queues, (*23)
For example I can register with my AppServiceProvider
, (*24)
Queue::failing(function (JobFailed $event) {
$message = sprintf("Connection %s, Job %s, Exception %s %s %s",
$event->connectionName, implode("\n", $event->data), $event->job->getRawBody()
);
$data = ['title' => 'Failed Queue From FooBar', 'message' =>
json_encode($message, JSON_PRETTY_PRINT)
];
Incomings::send($data);
});
Logger
This setup will allow you to use Log::info("Some Message") and all the other Log methods as normal., (*25)
All you need to do at the top of your Class is to set use as follow, (*26)
use AlfredNutileInc\Incomings\Log;
From there on your log messages go to Incomings then to Logger, (*27)
Even better you now can/should do this, (*28)
$send = [
'title' => 'foo',
'message' => "bar",
];
Log::info($send);
The IncomingLogger will pass this array to Incomings.io giving your incoming more context and then it will
just pass the message to Log as normal. So you could even do., (*29)
$send = [
'title' => 'foo',
'message' => print_r($some_array_payload, 1),
];
Like sometimes we do in Log::info as we are watching for non string based info in the logs. Or, (*30)
$send = [
'title' => 'foo',
'message' => json_encode($some_array_payload, JSON_PRETTY_PRINT),
];
For nicer looking data., (*31)
MiddleWare
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'incomings' => \AlfredNutileInc\Incomings\IncomingsMiddleWare::class
];
Then plug it in, (*32)
Route::get('foobar', ['middleware' => 'incomings', function() {
return "Send to incomings!";
}]);
Then data coming in via POST, GET, etc will be sent to Incomings for a sense of is the data coming into my system correctly etc., (*33)
You can pass a title as well, (*34)
Route::get('foobar', ['middleware' => 'incomings:My Title', function() {
return "Send to incomings!";
}]);
Laravel Exceptions
Just edit your app/Exceptions/Handler.php
so it uses Incomings Exception handler, (*35)
Before, (*36)
<?php
namespace App\Exceptions;
use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;
use IncomingsExceptionHandler as ExceptionHandler;
class Handler extends ExceptionHandler
{
After, (*37)
<?php
namespace App\Exceptions;
use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;
use AlfredNutileInc\Incomings\IncomingsExceptionHandler as ExceptionHandler;
class Handler extends ExceptionHandler
{
If you are using Lumen, you will need to use the IncomingsExceptionHandlerForLumen
instead, like so:, (*38)
<?php
namespace App\Exceptions;
use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;
use AlfredNutileInc\Incomings\IncomingsExceptionHandlerForLumen as ExceptionHandler;
class Handler extends ExceptionHandler
{
Then as seen in this route it will send a message first to Incomings.io, (*39)
Route::get('/example_exception', function() {
throw new \Exception("Yo Incomings!!!");
});
Will send a message like, (*40)
, (*41)
Bugsnag Too
If you are using a service like BugSnag just follow their directions so your app/Exceptions/Handler.php
would then look like this., (*42)
<?php namespace App\Exceptions;
use Exception;
use Bugsnag\BugsnagLaravel\BugsnagExceptionHandler as ExceptionHandler;
use AlfredNutileInc\Incomings\IncomingsFacade as Incomings;
class Handler extends ExceptionHandler
{
protected $dontReport = [
HttpException::class,
];
public function report(Exception $e)
{
$data = [
'title' => 'Application Exception Error',
'message' => sprintf(
"Error Filename %s \n on line %d \n with message %s \n with Code %s",
$e->getFile(),
$e->getLine(),
$e->getMessage(),
$e->getCode()
),
];
Incomings::send($data);
return parent::report($e);
}
}
Filter for Laravel 4.2
As above plug in your provider, (*43)
If you are not using DotEnv as I write about here https://alfrednutile.info/posts/113, (*44)
Then update your .env.php
to have your tokens and url, (*45)
<?php
return array(
'INCOMINGS_URL' => 'https://post.incomings.io',
'INCOMINGS_TOKEN' => 'foo-bar-foo'
);
Then in your route, (*46)
Route::get('/', ['before' => 'incomings', function()
{
return View::make('hello');
}]);
Finally in your filter file add the following app/filters.php
, (*47)
Route::filter('incomings', function() {
try
{
$incomings = new \AlfredNutileInc\Incomings\IncomingsFilter();
$incomings->handle(\Illuminate\Support\Facades\Request::instance());
}
catch(\Exception $e)
{
Log::error(sprintf("Error with Incomings :( %s", $e->getMessage());
}
});
This will catch any issues and not mess up your application., (*48)
, (*49)
Curl
Here is an example of using Curl. In this case I want to see some info from my server every hour., (*50)
curl -k -H "Content-Type: application/json" -H "Accept: application/json" -X POST --data @status.json https://post.incomings.io/incomings/f4ac705d-5087-3432-8182-334de6726fc5
Then every hour I get to see the updates to that file. The CronJob would run this as root, (*51)
01 * * * * apt-get upgrade -s | grep -i security > /tmp/status.json
03 * * * * curl -k -H "Content-Type: application/json" -H "Accept: application/json" -X POST --data @/tmp/status.json https://post.incomings.io/incomings/foobar
You can even make a bach command to run this all and gather more data like "Last Run" etc., (*52)
Drupal 8
Coming Soon..., (*53)
Drupal 7
Coming Soon..., (*54)