I'm trying to add a custom filter to Logstash 1.4.2, which is installed as a Debian package. The contrib plugins (http://logstash.net/docs/1.4.2/contrib-plugins) are also installed. This filter establishes a connection to an sqlite database, and for that it makes use of the JDBC sqlite driver:
require "logstash/filters/base"
require "logstash/namespace"
require "jdbc/sqlite3"
require "java"
class LogStash::Filters::MyFilter < LogStash::Filters::Base
(...)
public
def register
if #database.nil?
raise "You must specify 'database => ...' in your filter"
elsif not File.exists?(#database)
raise "The database does not exist"
end
url = "jdbc:sqlite:" + #database
Java::OrgSqlite::JDBC #initialize the driver
#connection = java.sql.DriverManager.getConnection(url)
#logger.info("Using database", :path => #database)
end # def register
(...)
end # class LogStash::Filters::MyFilter
However, when I try to start logstash I get the following error in the logs :
"cannot load Java class org.sqlite.JDBC"
I've tried to place the sqlite-jdbc-3.7.2.jar file provided by the contrib plugins into several locations, but so far I couldn't figure out what's the right one for JARs required by custom plugins, or whether it is a configuration issue.
Any ideas?
While I couldn't find the way of using external jars with Logstash 1.4, I could get it to work by replacing SQlite JDBC with Sequel, which is already included.
require "logstash/filters/base"
require "logstash/namespace"
require "sequel"
class LogStash::Filters::MyFilter < LogStash::Filters::Base
(...)
public
def register
if #database.nil?
raise "You must specify 'database => ...' in your filter"
elsif not File.exists?(#database)
raise "The database does not exist"
end
#db = Sequel.connect("jdbc:sqlite:#{#database}")
#logger.info("Using database", :path => #database)
end # def register
(...)
end # class LogStash::Filters::MyFilter
Related
Say I have two lua modules, like this.
Filename: my/lua/app/caller.lua
Module name: my.lua.app.caller
local reflect = require('my.lib.reflect')
-- should return "my.lua.app.caller"
reflect.get_caller_module_name()
Filename: my/lib/reflect.lua
Module name: my.lib.reflect
M = {}
function M.get_caller_module_name()
-- magic here?
return module_name
end
return M
Now running my.lua.app.caller should allow it to get its own module name, my.lua.app.caller. Is this doable in Lua?
(I realize that I can get the module name by inserting local module_name, _ = ... as the very first line of the caller's module, but I want to be able to do this without this without needing any special modifications to the caller's module.)
Ruby 2.6.3
Rails 6.0.3
I don't why, when I try to create or update a record in a loop, adding an attachment or attachments, just only one or two recoreds can be updated. I also tested this behaviour with only one attachment and only for creating. But the behaviour is the same.
In the code below, I'm trying to reload attachments on aws, using active storage. But only 1 record is updated.
namespace :uploads do
task migrate_to_active_storage: :environment do
Upload.where.not(csv_file_name: nil).find_each do |upload|
%w[csv log].map do |attachment_type|
attach_url = [
'https://',
ENV['AWS_BUCKET'],
".s3-#{ENV['AWS_REGION']}.amazonaws.com/",
upload.business.normalized_name,
'/upload/',
upload.id.to_s,
"/#{attachment_type}/",
upload.csv_file_name
].join
upload.send(attachment_type).attach(
io: open(attach_url),
filename: upload["#{attachment_type}_file_name"],
content_type: upload["#{attachment_type}_content_type"]
)
end
end
ap 'DONe WITH SUCCESS' # never appears
end
end
I've managed to fix this, using threds. But I don't know why it doesn't work in the code above.
This solution works fine.
namespace :uploads do
task migrate_to_active_storage: :environment do
uploads = Thread.new { Upload.ids }.value
uploads.each do |id|
Thread.new do
sleep 2
upload = Upload.find id
upload.update csv: get_attachment(upload, 'csv'),
log: get_attachment(upload, 'log')
end.join
end
end
end
def get_attachment(upload, attachment_type)
attachment_url = [
'https://',
ENV['AWS_BUCKET'],
".s3-#{ENV['AWS_REGION']}.amazonaws.com/",
upload.business.normalized_name,
'/upload/',
upload.id.to_s,
"/#{attachment_type}/",
upload["#{attachment_type}_file_name"]
].join
{
io: open(attachment_url),
filename: "#{upload.id}_#{upload["#{attachment_type}_file_name"]}",
content_type: upload["#{attachment_type}_content_type"]
}
end
And what is really a mystic. When I try to call a differen model, for instance, like User. And even if it does nothing, the code above won't work. Only 1 record will'be updated.
I installed recently laravel 5.7. How to fix error "php artisan migrate"?
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Illuminate\Database\QueryException : SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `users_email_unique`(`email`))
at C:\laravel\blg2\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error 661| // message to include the bindings with SQL, which will make this exception a 662| // lot more helpful to the developer instead of just the database's errors. 663| catch (Exception $e) {
> 664| throw new QueryException(
665| $query, $this->prepareBindings($bindings), $e
666| );
667| }
668|
Exception trace:
1 PDOException::("SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes") C:\laravel\blg2\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
2 PDOStatement::execute()
C:\laravel\blg2\vendor\laravel\framework\src\Illuminate\Database\Connection.php:458
Please use the argument -v to see more details.
Thank you
Laravel uses the utf8mb4 character set by default, which includes support for storing "emojis" in the database. If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them.
Inside your AppServiceProvider:
use Illuminate\Support\Facades\Schema;
...
public function boot()
{
Schema::defaultStringLength(191);
}
Alternatively, you may enable the innodb_large_prefix option for your database. Refer to your database's documentation for instructions on how to properly enable this option.
For more information about indexes: https://laravel.com/docs/5.7/migrations#indexes
If you are running a version of MySQL older than the 5.7.7 release or MariaDB older than the 10.2.2 release, you may need to manually configure the default string length generated by migrations in order for MySQL to create indexes for them.
You can have it fixed as Chin Leung said.
Or adding the length of the record directly in the migration.
$table->string('email', 100); VARCHAR equivalent column with a optional length.
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 50);
$table->string('email', 90)->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
On xampp php 7.3.2, laravel 5.7 & also in laravel 5.8.3 it happened to me. Only changed the config/database.php file.
config/database.php
Changed charset & collation on mysql & it worked fine. Change this part
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
as
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
Now it will accept the long keys.
You need to go to
App\Providers\AppServiceProvider.php
Now Add the following code and then save and run php artisan serve
use Illuminate\Support\Facades\Schema;
...
public function boot()
{
Schema::defaultStringLength(191);
}
I use Laravel 5.7 but this error always comes up. ADD this code in every project. Also try to use Laravel with php7+ so that it doesnot show you PDO::Exception Error...
Open your AppServiceProvider.php, Path >> App\Providers\AppServiceProvider.php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
**use Illuminate\Support\Facades\Schema;**
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
**Schema::defaultStringLength(191);**
}
You can define the string length as well to solve this kind of error
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name',20);
$table->string('email',80)->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password',8);
$table->rememberToken();
$table->timestamps();
});
I'm setting up a Puppet provision file to install, configure and restore a dump file into a Oracle Database.
I would like to include a check in the exec command in order to check if the restore was successful.
Here is what I have so far:
exec {"import-dump":
command => "impdp system/password DUMPFILE=MYDUMP.DMP LOGFILE=import-dump.log SCHEMAS=MYSCHEMA",
path => "/u01/app/oracle/product/11.2.0/xe/bin/",
-- something to check if the import command already runned successfully ---
require => Exec["install-oracle"],
}
I would use an approach like the following:
exec { "import-dump":
command => "impdp system/password DUMPFILE=MYDUMP.DMP LOGFILE=import-dump.log SCHEMAS=MYSCHEMA",
path => "/u01/app/oracle/product/11.2.0/xe/bin/",
unless => "/bin/grep 'terminated successfully' /path/to/import-dump.log",
require => Exec["install-oracle"],
}
In this way you can check if a previous import job was run successfully.
I use silverstripe 3.1
I would like to limit the languages (To only German and English) which are available in the drop down in the CMS. Therefore I put
the following code in my mysite/_config.php
i18n::set_locale('de_DE');
$allowed_locales = array(
'de_DE' => array('Deutsch', 'Deutsch'),
'en_EN' => array('English', 'English')
);
i18n::$common_locales = $allowed_locales;
Afer a flush=1 i get the following error:
Fatal error: Cannot access private property i18n::$common_locales in ... _config.php
Any ideas what goes wrong?
Thank you
as of 3.1 most of the static php variables are private. this means you can no longer access those.
the reason for this api change is that they are now cached by the config layer (this is also why you have to ?flush=1 now after changing private statics in classes like for example with private static $db)
if you want to update something in the config layer, you can do this with:
Config::inst()->update('CLASS', 'FIELD', $value);
you could use use the config update to overwrite the common locales (class would be 'i18n', and field would be 'common_locales'):
Config::inst()->update('i18n', 'common_locales', $array);
Note: if you want to completely overwrite an existing configuration, you have to do a remove() first.
Config::inst()->remove('i18n', 'common_locales');
Config::inst()->update('i18n', 'common_locales', $array);
however, if you are using the translatable module and you want to limit the number of translatable languages, there is a much better way already built in:
// in your _config.php
i18n::set_locale('en_US');
Translatable::set_allowed_locales(array(
'de_DE',
'en_US',
));
Config it through YAML:
i18n:
common_locales:
nl_BE:
name: Dutch (Belgium)
native: Nederlands
fr_BE:
name: French (Belgium)
native: Francais