Exemplo n.º 1
0
int main(int argc, char **argv)
{
    option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION);
    option_define_bool("verbose", OPT_OPTIONAL, 0, &verbose, NULL, "verbose output (to stderr)");
    option_define_str("blacklist_fields", OPT_OPTIONAL, NULL, NULL, parse_blacklisted_fields, "comma separated list of fields to remove");
    option_define_str("encrypted_fields", OPT_OPTIONAL, NULL, NULL, parse_encrypted_fields, "comma separated list of fields to encrypt");
    option_define_str("expected_key", OPT_OPTIONAL, NULL, &expected_key, NULL, "key to expect in messages before echoing to clients");
    option_define_str("expected_value", OPT_OPTIONAL, NULL, &expected_value, NULL, "value to expect in --expected-key field in messages before echoing to clients");
    
    if (!option_parse_command_line(argc, argv)) {
        return 1;
    }
    
    if ( !!expected_key ^ !!expected_value ) {
        fprintf(stderr, "--expected-key and --expected-value must be used together\n");
        exit(1);
    }
    
    while (fgets(buf, BUF_SZ, stdin)) {
        msgRecv++;
        process_message(buf);
    }
    
    fprintf(stderr, "processed %lu lines, failed to parse %lu of them\n", msgRecv, msgFail);
    free_options();
    free_fields(blacklisted_fields, num_blacklisted_fields);
    free_fields(encrypted_fields, num_encrypted_fields);
    
    return 0;
}
Exemplo n.º 2
0
int main(int argc, char **argv)
{
    char *pubsub_url;
    char *address;
    int port;
    char *path;
    char *filename_format = NULL;
    struct output_metadata *data;
    
    define_simplehttp_options();
    option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION);
    option_define_str("pubsub_url", OPT_REQUIRED, "http://127.0.0.1:80/sub?multipart=0", &pubsub_url, NULL, "url of pubsub to read from");
    option_define_str("filename_format", OPT_REQUIRED, NULL, &filename_format, NULL, "/var/log/pubsub.%%Y-%%m-%%d_%%H.log");
    
    if (!option_parse_command_line(argc, argv)){
        return 1;
    }
    
    data = calloc(1, sizeof(struct output_metadata));
    data->filename_format = filename_format;
    data->current_filename[0] = '\0';
    data->temp_filename[0] = '\0';
    data->output_file = NULL;
    
    if (simplehttp_parse_url(pubsub_url, strlen(pubsub_url), &address, &port, &path)) {
        pubsubclient_main(address, port, path, process_message_cb, error_cb, data);
        
        if (data->output_file) {
            fclose(data->output_file);
        }
        
        free(address);
        free(path);
    } else {
        fprintf(stderr, "ERROR: failed to parse pubsub_url\n");
    }
    
    free(data);
    free_options();
    free(pubsub_url);
    free(filename_format);
    
    return 0;
}
Exemplo n.º 3
0
int main(int argc, char **argv)
{
    option_define_bool("version", OPT_OPTIONAL, 0, NULL, version_cb, VERSION);
    option_define_str("db_file", OPT_REQUIRED, NULL, NULL, NULL, "path to leveldb file");
    option_define_bool("create_db_if_missing", OPT_OPTIONAL, 1, NULL, NULL, "Create leveldb file if missing");
    option_define_bool("error_if_db_exists", OPT_OPTIONAL, 0, NULL, NULL, "Error out if leveldb file exists");
    option_define_bool("paranoid_checks", OPT_OPTIONAL, 1, NULL, NULL, "leveldb paranoid checks");
    option_define_int("write_buffer_size", OPT_OPTIONAL, 4 << 20, NULL, NULL, "write buffer size");
    option_define_int("cache_size", OPT_OPTIONAL, 4 << 20, NULL, NULL, "cache size (frequently used blocks)");
    option_define_int("block_size", OPT_OPTIONAL, 4096, NULL, NULL, "block size");
    option_define_bool("compression", OPT_OPTIONAL, 1, NULL, NULL, "snappy compression");
    option_define_bool("verify_checksums", OPT_OPTIONAL, 1, NULL, NULL, "verify checksums at read time");
    option_define_int("leveldb_max_open_files", OPT_OPTIONAL, 4096, NULL, NULL, "leveldb max open files");
    
    option_define_str("input_file", OPT_OPTIONAL, NULL, NULL, NULL, "path to output file (default:stdin)");
    option_define_bool("quiet", OPT_OPTIONAL, 0, NULL, NULL, "quiet mode");
    option_define_int("stats_every", OPT_OPTIONAL, 1000, NULL, NULL, "show a status after processing x records");
    option_define_str("input_deliminator", OPT_OPTIONAL, ",", NULL, NULL, "input deliminator");
    
    if (!option_parse_command_line(argc, argv)) {
        return 1;
    }
    
    if (!db_open()) {
        return 1;
    }
    
    if (!read_csv()) {
        return 1;
    }
    
    db_close();
    free_options();
    
    return 0;
}