Exemple #1
0
LogDriver *
afmongodb_dd_new(void)
{
  MongoDBDestDriver *self = g_new0(MongoDBDestDriver, 1);

  mongo_util_oid_init (0);

  log_dest_driver_init_instance(&self->super);
  self->super.super.super.init = afmongodb_dd_init;
  self->super.super.super.deinit = afmongodb_dd_deinit;
  self->super.super.super.queue = afmongodb_dd_queue;
  self->super.super.super.free_fn = afmongodb_dd_free;

  afmongodb_dd_set_servers((LogDriver *)self, g_list_append (NULL, g_strdup ("127.0.0.1:27017")));
  afmongodb_dd_set_database((LogDriver *)self, "syslog");
  afmongodb_dd_set_collection((LogDriver *)self, "messages");
  afmongodb_dd_set_safe_mode((LogDriver *)self, FALSE);

  init_sequence_number(&self->seq_num);

  self->writer_thread_wakeup_cond = g_cond_new();
  self->suspend_mutex = g_mutex_new();
  self->queue_mutex = g_mutex_new();

  return (LogDriver *)self;
}
Exemple #2
0
LogDriver *
afmongodb_dd_new(GlobalConfig *cfg)
{
  MongoDBDestDriver *self = g_new0(MongoDBDestDriver, 1);

  mongo_util_oid_init (0);

  log_threaded_dest_driver_init_instance(&self->super);

  self->super.super.super.super.init = afmongodb_dd_init;
  self->super.super.super.super.free_fn = afmongodb_dd_free;
  self->super.queue_method = afmongodb_dd_queue_method;

  self->super.worker.thread_init = afmongodb_worker_thread_init;
  self->super.worker.thread_deinit = afmongodb_worker_thread_deinit;
  self->super.worker.disconnect = afmongodb_dd_disconnect;
  self->super.worker.insert = afmongodb_worker_insert;
  self->super.format.stats_instance = afmongodb_dd_format_stats_instance;
  self->super.format.persist_name = afmongodb_dd_format_persist_name;
  self->super.stats_source = SCS_MONGODB;

  afmongodb_dd_set_database((LogDriver *)self, "syslog");
  afmongodb_dd_set_collection((LogDriver *)self, "messages");
  afmongodb_dd_set_safe_mode((LogDriver *)self, FALSE);

  init_sequence_number(&self->seq_num);

  log_template_options_defaults(&self->template_options);
  afmongodb_dd_set_value_pairs(&self->super.super.super, value_pairs_new_default(cfg));

  return (LogDriver *)self;
}
static void
_test_legacy_correct(void)
{
  GList *servers = g_list_append(NULL, g_strdup("127.0.0.2:27018"));
  servers = g_list_append(servers, g_strdup("localhost:1234"));
  afmongodb_dd_set_servers(mongodb, servers);
  _expect_uri_in_log("servers_multi", "127.0.0.2:27018,localhost:1234/syslog" SAFEOPTS,
                     "syslog", "messages");

  servers = g_list_append(NULL, g_strdup("127.0.0.2"));
  afmongodb_dd_set_servers(mongodb, servers);
  _expect_uri_in_log("servers_single", "127.0.0.2:27017/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_host(mongodb, "localhost");
  _expect_uri_in_log("host", "localhost:27017/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_host(mongodb, "localhost");
  afmongodb_dd_set_port(mongodb, 1234);
  _expect_uri_in_log("host_port", "localhost:1234/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_port(mongodb, 27017);
  _expect_uri_in_log("port_default", "127.0.0.1:27017/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_port(mongodb, 1234);
  _expect_uri_in_log("port", "127.0.0.1:1234/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_path(mongodb, "/tmp/mongo.sock");
  _expect_uri_in_log("path", "/tmp/mongo.sock" SAFEOPTS, "tmp/mongo.sock", "messages");

  afmongodb_dd_set_database(mongodb, "syslog-ng");
  _expect_uri_in_log("database", "127.0.0.1:27017/syslog-ng" SAFEOPTS, "syslog-ng", "messages");

  afmongodb_dd_set_safe_mode(mongodb, TRUE);
  _expect_uri_in_log("safe_mode_true", "127.0.0.1:27017/syslog" SAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_safe_mode(mongodb, FALSE);
  _expect_uri_in_log("safe_mode_false", "127.0.0.1:27017/syslog" UNSAFEOPTS, "syslog", "messages");

  afmongodb_dd_set_user(mongodb, "user");
  afmongodb_dd_set_password(mongodb, "password");
  _expect_uri_in_log("user_password", "user:[email protected]:27017/syslog" SAFEOPTS,
                     "syslog", "messages");

  afmongodb_dd_set_collection(mongodb, "messages2");
  afmongodb_dd_set_safe_mode(mongodb, FALSE);
  _expect_uri_in_log("collection_safe_mode", "127.0.0.1:27017/syslog" UNSAFEOPTS,
                     "syslog", "messages2");

  afmongodb_dd_set_user(mongodb, "");
  afmongodb_dd_set_password(mongodb, "password");
  _expect_uri_in_log("empty_user", ":[email protected]:27017/syslog" SAFEOPTS,
                     "syslog", "messages");

  afmongodb_dd_set_user(mongodb, "user");
  afmongodb_dd_set_password(mongodb, "");
  _expect_uri_in_log("empty_password", "user:@127.0.0.1:27017/syslog" SAFEOPTS,
                     "syslog", "messages");

  afmongodb_dd_set_user(mongodb, "");
  afmongodb_dd_set_password(mongodb, "");
  _expect_uri_in_log("empty_user_password", ":@127.0.0.1:27017/syslog" SAFEOPTS,
                     "syslog", "messages");

  afmongodb_dd_set_user(mongodb, "127.0.0.1:27017/syslog?dont-care=");
  afmongodb_dd_set_password(mongodb, "");
  _expect_uri_in_log("hijacked_user", "127.0.0.1:27017/syslog?dont-care=:@127.0.0.1:27017/syslog"
                     SAFEOPTS, "syslog", "messages");
}