spatie/laravel-backup notifications not posting - laravel-5

Using Laravel 5.3 and v4 from spatie/laravel-backup package.
I am using this package from Spatie which allows me to take backups using a simple terminal command. It is pretty straight forward to set up and when I run the command the backup runs as intended.
But there is also an option in the config file to set notifications (send mail, post to slack, ...) after a backup. This does not seem to do anything for me. I neither receive mails (and I have set my mailaddress) or see posts to my dedicated slack channel (and i have added the webhook).
I have already included the following composer packages since researching this problem:
Guzzlehttp/guzzle
maknz/slack-laravel
maknz/slack
This is the simple notifications section in the config file:
'notifications' => [
'notifications' => [
\Spatie\Backup\Notifications\Notifications\BackupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\UnhealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupHasFailed::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\BackupWasSuccessful::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\HealthyBackupWasFound::class => ['mail'],
\Spatie\Backup\Notifications\Notifications\CleanupWasSuccessful::class => ['mail'],
],
/*
* Here you can specify the notifiable to which the notifications should be sent. The default
* notifiable will use the variables specified in this config file.
*/
'notifiable' => \Spatie\Backup\Notifications\Notifiable::class,
'mail' => [
'to' => 'nicolas#******.***',
],
'slack' => [
'webhook_url' => 'https://hooks.slack.com/services/*****/*****/*************',
],
],
Not really sure if I am forgetting something? Thanks for the help
The output I get in terminal after running the commands: gist.github
Extra:
This is a talk at Laracon EU 2016, where the creator (Freek) shows off his package.

Related

How to manage data at DO Spaces with Laravel Storage

I am trying to manage DO's Spaces with Laravel's 8 Storage, however I am getting errors which seems to come from Laravel's side.
At start I wrote this line in terminal as I was instructed in Laravel's documentation
composer require league/flysystem-aws-s3-v3 "~1.0"
afterwards I edited my environmental variables
DO_SPACES_KEY=*KEY*
DO_SPACES_SECRET=*SECRET*
DO_SPACES_ENDPOINT=ams3.digitaloceanspaces.com
DO_SPACES_REGION=AMS3
DO_SPACES_BUCKET=test-name
also added changes in config/filesystems.php
'do_spaces' => [
'driver' => 's3',
'key' => env('DO_SPACES_KEY'),
'secret' => env('DO_SPACES_SECRET'),
'endpoint' => env('DO_SPACES_ENDPOINT'),
'region' => env('DO_SPACES_REGION'),
'bucket' => env('DO_SPACES_BUCKET'),
],
After visiting this test Route
Route::get('/test', function (Request $request) {
Storage::disk('do_spaces')->put('test.txt', 'hello world');
});
I am getting this error
Error executing "PutObject" on "//test-name./test-name/test.txt"; AWS HTTP error: cURL error 6: Couldn't resolve host 'test-name' (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for http://test-name./test-name/test.txt
It seems that problem occurs while laravel is trying to compile url which should not look as it is here (wrong - http://test-name./test-name/test.txt). However I have no clue how to fix this issue and what I am doing wrong, since I was following all steps as many tutorials and documetations were telling to do.
I had the same problem. I solved it next way:
Add https:// to DO_SPACES_ENDPOINT (https://ams3.digitaloceanspaces.com)
In put method use path to text.txt:
Storage::disk('do_spaces')->put('YOUR_SPACE_NAME/YOUR_FOLDER_NAME(if you have)/test.txt', 'hello world');

Laravel 5.6 won't log to Slack

Currently my config/logging.php channels section contains like the following:
'stack' => [
'driver' => 'stack',
'channels' => ['single', 'slack'],
],
Then in my slack section I have set a webhook using the Incoming Webhooks section in Slack. https://slack.com/apps/A0F7XDUAZ-incoming-webhooks
Other incoming webhooks I've set for other application (not Laravel) have all worked perfectly.
When I call the following:
Log::channel('stack')->info('test'); then it successfully logs to the file, but not to Slack.
or
Log::channel('slack')->info('test'); just seemingly does nothing.
In my Slack channels as I add the configuration I can see the notification "added an integration to this channel: Laravel Log"
Not sure what else to do to even troubleshoot this or get it working?
Make sure info is not below the specified minimum level for messages to be escalated to Slack in config/logging.php.
if the channel level is on the debug, all kinds of log functions work.
the following levels can be used for logs in order of importance
1- emergency
2-alert
3-critical
4-error
5-warning
6-notice
7-info
8-debug
and if the level you used in the channel settings should be higher than the log level. The log does not work
For example, if the channel level settings are critical
Log::error($message);
Log::warning($message);
Log::notice($message);
Log::info($message);
Log::debug($message);
does not work
But
Log::emergency($message);
Log::alert($message);
Log::critical($message);
they are working.
So if the channel level is on the debug, all kinds of log functions work.
'slack_channel' => [
'driver' => 'slack',
'url' => 'https://hooks.slack.com/services/.....',
'username' => 'Laravel Log',
'emoji' => ':boom:',
// 'level' => 'critical',///<---- in critical level it`s work for Log::channel('slack_channel')->critical('message') || alert('message') || emergency('message')
'level' => 'debug',///<---- in debug level it`s work for each type log. for example Log::channel('slack_channel')->debug('message') || info('message') || notice('message') .... emergency('message')
],

Hybridauth + composer: how to add custom providers

I'm converting a php project to use composer as dependency manager.
The dependencies are loaded via this line in my main script.
require 'vendor/autoload.php';
One of these dependencies is hybridauth (version 2.9). Since using Composer, it throws 'file not found' errors when looking for custom providers files.
For instance, my main controller calls Hybrid like this:
$config_file_path = dirname(__FILE__) .'/hybridauth/config.php';
$hybridauth = new Hybrid_Auth( $config_file_path );
Now, here is the config file. The provider i'm using is "Facebooktest".
Note that I had to specify the path via the [wrapper][path]; array key to get to the next error message.
return
array(
"base_url" => WWWROOT."/auth",
"providers" => array(
"Facebook" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxxxx"),
"scope" => "email",
"trustForwarded" => false
),
"Facebooktest" => array(
"enabled" => true,
"keys" => array("id" => "xxxxxxx", "secret" => "xxxxxx"),
"scope" => "email",
"trustForwarded" => false,
"wrapper"=> array(
"class"=>'Hybrid_Providers_Facebooktest',
"path"=> './controllers/hybridauth/Hybrid/Providers/Facebooktest.php'
)
)
),
"debug_mode" => false,
"debug_file" => "",
);
The error message (with trace):
require_once(/path/to/composer-project/vendor/hybridauth/hybridauth/hybridauth/Hybrid/thirdparty/Facebook/autoload.php): failed to open stream: No such file or directory
[vendor/bcosca/fatfree/lib/base.php:2174] Base->error()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] Base->{closure}()
[controllers/hybridauth/Hybrid/Providers/Facebooktest.php:61] require_once()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Model.php:99] Hybrid_Providers_Facebooktest->initialize()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Provider_Adapter.php:101] Hybrid_Provider_Model->__construct()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:278] Hybrid_Provider_Adapter->factory()
[vendor/hybridauth/hybridauth/hybridauth/Hybrid/Auth.php:230] Hybrid_Auth::setup()
[controllers/auth-action.get.php:19] Hybrid_Auth::authenticate()
I find it strange that I now need to modify paths inside the "vendor/hybridauth/" project. It defeats the purpose of using a dependency manager. Surely, I must be doing it wrong.
Can you advise?
Check my answer to another question here
If you have recently installed Hybridauth through composer you probably have downloaded v2.9.2, which contain a bug in their Facebook class that replace the vendor path from yours to hybridauth/vendor, causing such issue.
I suspect you created that Facebooktest class by copying their Facebook class and therefore sustained that error. Either update to their dev branch and copy that Facebook class, or simply use other provider class as template for your custom provider class.

Laravel 5 - change default log location, move log file outside the app

How can I change default log file location <project-name>/storage/logs/laravel.log to something like /var/logs/<project-name>/laravel.log?
I resolved this case by using errorlog logging model and configuring webserver.
1. Configure Laravel:
In config/app.php configuration file:
'log' => 'errorlog'
Read more about Laravel log configuration: http://laravel.com/docs/5.1/errors#configuration
2. Configure webserver (in my case Nginx):
error_log /var/log/nginx/<project_name>-error.log;
For those who don't want to use errorlog and just really want to replace the file to log to, you can do this:
\Log::useFiles(env('APP_LOG_FILE'), config('app.log_level', 'debug'));
$handlers = \Log::getMonolog()->getHandlers();
$handler = array_shift($handlers);
$handler->setBubble(false);
on App\Providers\AppServiceProvider.php or any Provider for that matter. This will log to the value of APP_LOG_FILE instead of the default laravel.log. Set bubbling to true and the application will log on both files.
For anyone still coming across this post in hopes of changing their log file location, I believe this is now easier in newer versions of Laravel. I am currently using 8.x
In your /config/logging.php you can define the path for your single and daily logs. Just update whichever one your are looking to change. Just make sure you also include the name of the log file, not just the path to where you'd like it saved.
'single' => [
'driver' => 'single',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
],
'daily' => [
'driver' => 'daily',
'path' => "/your/desired/log/path/file.log", // edit here
'level' => env('LOG_LEVEL', 'debug'),
'days' => 14,
]

Using Yii2's default messages

I can't figure out, how to use Yii's default messages, without overwriting them with the message command.
I have 2 translation categories: app, data.
I'd like to use the default messages, like "Are you sure you want to delete this item?" and "(not set)" from the Yii2 core, but if I use Yii::t('yii', 'Are you sure you want to delete this item?') and then run the yii message command, it creates a yii.php file in the messages folder with this token.
Part of my config:
'i18n' => [
'translations' => [
'app*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
],
'data*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '#app/messages',
],
],
],
How should I set up my config to use the built in texts and not to overwrite them?
You don't have to do anything. The yii-category is automatically defined as soon as you use translation and it points to the messages in the framework.
That it creates an empty file is for 'yii' is normal, because you actually use that category in your code. This is unrelated to where the messages will be loaded from during normal execution.
Just make sure that you configure your apps' language and sourceLanguage correctly if not already done.

Resources