Exemplo n.º 1
0
int Read_Rmdir_Config( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    bool           bval;
    rmdir_config_t *conf = ( rmdir_config_t * ) module_config;

    static const char * rmdir_allowed[] =
    {
        "runtime_interval", "nb_threads_rmdir", "rmdir_queue_size", NULL
    };

    /* get RMDIR_PARAM block */

    config_item_t  param_block = rh_config_FindItemByName( config, RMDIR_PARAM_BLOCK );
    if ( param_block == NULL )
      {
          /* no error, because no parameter is mandatory */
          return 0;
      }

    /* check this is a block... */
    if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK )
      {
          strcpy( msg_out, "A block is expected for '" RMDIR_PARAM_BLOCK "' item" );
          return EINVAL;
      }

    /* parse parameters */
    rc = GetDurationParam(param_block, RMDIR_PARAM_BLOCK, "runtime_interval",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                          &conf->runtime_interval, NULL, NULL, msg_out);
    if ((rc != 0) && (rc != ENOENT))
        return rc;

    rc = GetIntParam( param_block, RMDIR_PARAM_BLOCK, "nb_threads_rmdir",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_rmdir,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( param_block, RMDIR_PARAM_BLOCK, "rmdir_queue_size",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->rmdir_queue_size,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam(param_block, RMDIR_PARAM_BLOCK, "simulation_mode",
                      0, &bval, NULL, NULL, msg_out);
    if (rc != ENOENT)
    {
        DisplayLog( LVL_EVENT, "RmdirConfig",
            "WARNING: deprecated parameter 'simulation_mode'. Use '--dry-run' option instead.");
    }

    CheckUnknownParameters( param_block, RMDIR_PARAM_BLOCK, rmdir_allowed );

    return 0;

}
Exemplo n.º 2
0
int ReadLmgrConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    lmgr_config_t *conf = ( lmgr_config_t * ) module_config;
    char         **options = NULL;
    unsigned int   nb_options = 0;
    char           tmpstr[1024];

    config_item_t  db_block;

    static const char *lmgr_allowed[] = {
        "commit_behavior",
        "connect_retry_interval_min",
        "connect_retry_interval_max",
        "user_acct",
        "group_acct",
        MYSQL_CONFIG_BLOCK,
        SQLITE_CONFIG_BLOCK,
        NULL
    };


#ifdef _MYSQL
    static const char *db_allowed[] = {
        "server", "db", "user", "password", "password_file", "port", "socket",
        "innodb", NULL
    };
#elif defined (_SQLITE)
    static const char *db_allowed[] = {
        "db_file", "retry_delay_microsec",
        NULL
    };
#endif

    /* get ListManager block */

    config_item_t  lmgr_block = rh_config_FindItemByName( config, LMGR_CONFIG_BLOCK );

    if ( lmgr_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" LMGR_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( lmgr_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" LMGR_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */

    /* 1) commit_behavior */

    rc = GetStringParam( lmgr_block, LMGR_CONFIG_BLOCK, "commit_behavior",
                         STR_PARAM_NO_WILDCARDS, tmpstr, 1024, &options, &nb_options, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
    {
        if ( !strcasecmp( tmpstr, "autocommit" ) )
            conf->commit_behavior = 0;
        else if ( !strcasecmp( tmpstr, "transaction" ) )
            conf->commit_behavior = 1;
        else if ( !strcasecmp( tmpstr, "periodical" )  /* for backward compatibility */
                  || !strcasecmp( tmpstr, "periodic" ) )
        {
            if ( ( nb_options != 1 ) || !options || !options[0] )
            {
                strcpy( msg_out,
                        "A single argument is expected for periodic commit behavior. Eg: commit_behavior = periodic(1000)" );
                return EINVAL;
            }

            conf->commit_behavior = atoi( options[0] );
            if ( conf->commit_behavior == 0 )
            {
                strcpy( msg_out,
                        "The argument for \"" LMGR_CONFIG_BLOCK
                        "::commit_behavior = periodical\" must be a positive integer. Eg: commit_behavior = periodic(1000)" );
                return EINVAL;
            }
        }
        else
        {
            sprintf( msg_out, "Invalid commit behavior '%s' (expected: autocommit, "
                     "transaction, periodic(<count>))", tmpstr );
            return EINVAL;
        }

    }

    /* 2) connect_retry_interval_min  and connect_retry_interval_max */

    rc = GetDurationParam( lmgr_block, LMGR_CONFIG_BLOCK,
                           "connect_retry_interval_min",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->connect_retry_min, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( lmgr_block, LMGR_CONFIG_BLOCK,
                           "connect_retry_interval_max",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->connect_retry_max, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    /* 3) ACCT configuration*/

    rc = GetBoolParam( lmgr_block, LMGR_CONFIG_BLOCK,
                       "user_acct", 0, &conf->user_acct, NULL, NULL, msg_out);
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( lmgr_block, LMGR_CONFIG_BLOCK,
                       "group_acct", 0, &conf->group_acct, NULL, NULL, msg_out);
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;      

    CheckUnknownParameters( lmgr_block, LMGR_CONFIG_BLOCK, lmgr_allowed );

    /* Database specific parameters */
#ifdef _MYSQL

    /* get MySQL block */

    db_block = rh_config_GetItemByName( lmgr_block, MYSQL_CONFIG_BLOCK );

    if ( db_block == NULL )
    {
        strcpy( msg_out,
                "Missing configuration block '" LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( db_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out,
                 "A block is expected for '" LMGR_CONFIG_BLOCK "::" MYSQL_CONFIG_BLOCK
                 "' item, line %d", rh_config_GetItemLine( db_block ) );
        return EINVAL;
    }

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "server",
                         STR_PARAM_NO_WILDCARDS, conf->db_config.server, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "db",
                         PARAM_MANDATORY | STR_PARAM_NO_WILDCARDS,
                         conf->db_config.db, 256, NULL, NULL, msg_out );
    if ( rc )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "user",
                         STR_PARAM_NO_WILDCARDS, conf->db_config.user, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "password",
                         0, conf->db_config.password, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
    {
        FILE          *passfile;
        char           errstr[1024];

        rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK,
                             "password_file",
                             STR_PARAM_ABSOLUTE_PATH |
                             STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc == ENOENT )
        {
            strcpy( msg_out,
                    MYSQL_CONFIG_BLOCK "::password or "
                    MYSQL_CONFIG_BLOCK "::password_file must be provided" );
            return ENOENT;
        }

        /* read password file and @TODO check its rights */
        passfile = fopen( tmpstr, "r" );
        if ( !passfile )
        {
            rc = errno;
            sprintf( msg_out, "Error openning password file %s : %s", tmpstr, strerror(errno) );
            return rc;
        }
        fscanf( passfile, "%1024s", tmpstr );
        if ( ferror( passfile ) )
        {
            rc = errno;
            strerror_r( rc, errstr, 1024 );
            sprintf( msg_out, "Error reading password file %s : %s", tmpstr, errstr );
            return rc;
        }
        fclose( passfile );
        strncpy( conf->db_config.password, tmpstr, 256 );
    }

    rc = GetIntParam( db_block, MYSQL_CONFIG_BLOCK, "port",
                         INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                         (int*)&conf->db_config.port, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( db_block, MYSQL_CONFIG_BLOCK, "socket",
                         STR_PARAM_NO_WILDCARDS | STR_PARAM_ABSOLUTE_PATH,
                         conf->db_config.socket, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( db_block, MYSQL_CONFIG_BLOCK, "innodb", 0,
                       &conf->db_config.innodb, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( db_block, MYSQL_CONFIG_BLOCK, db_allowed );

#elif defined (_SQLITE)
    /* get SQLite block */

    db_block = rh_config_GetItemByName( lmgr_block, SQLITE_CONFIG_BLOCK );

    if ( db_block == NULL )
    {
        strcpy( msg_out,
                "Missing configuration block '" LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK "'" );
        return ENOENT;
    }

    if ( rh_config_ItemType( db_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out,
                 "A block is expected for '" LMGR_CONFIG_BLOCK "::" SQLITE_CONFIG_BLOCK
                 "' item, line %d", rh_config_GetItemLine( db_block ) );
        return EINVAL;
    }


    rc = GetStringParam( db_block, SQLITE_CONFIG_BLOCK, "db_file",
                         STR_PARAM_ABSOLUTE_PATH |
                         STR_PARAM_NO_WILDCARDS,
                         conf->db_config.filepath, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( db_block, SQLITE_CONFIG_BLOCK,
                      "retry_delay_microsec",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      (int*)&conf->db_config.retry_delay_microsec, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( db_block, SQLITE_CONFIG_BLOCK, db_allowed );
#endif


    return 0;
}
Exemplo n.º 3
0
int Read_ResourceMon_Config( config_file_t config,
                             void *module_config, char *msg_out, int for_reload )
{
    int            rc;
    int            intval;
    resource_monitor_config_t *conf = ( resource_monitor_config_t * ) module_config;

    unsigned int   blc_index;

    static const char *purge_allowed[] = {
        "nb_threads_purge", "post_purge_df_latency",
        "purge_queue_size", "db_result_size_max",
#ifdef ATTR_INDEX_status
        "check_purge_status_on_startup",
#endif
        "recheck_ignored_classes",
#ifdef _TMP_FS_MGR
        "purge_command",
#endif
        NULL
    };

    /* get PURGE_PARAM block */

    config_item_t  param_block = rh_config_FindItemByName( config, PURGE_PARAM_BLOCK );
    if ( param_block != NULL )
    {
        /* no error, because no parameter is mandatory */

        /* check this is a block... */
        if ( rh_config_ItemType( param_block ) != CONFIG_ITEM_BLOCK )
        {
            strcpy( msg_out, "A block is expected for '" PURGE_PARAM_BLOCK "' item" );
            return EINVAL;
        }

        /* parse parameters */
        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "nb_threads_purge",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->nb_threads_purge,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetDurationParam( param_block, PURGE_PARAM_BLOCK, "post_purge_df_latency", INT_PARAM_POSITIVE, /* 0 is authorized: no delay */
                               &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->post_purge_df_latency = intval;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "purge_queue_size",
                          INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, ( int * ) &conf->purge_queue_size,
                          NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

        rc = GetIntParam( param_block, PURGE_PARAM_BLOCK, "db_result_size_max",
                          INT_PARAM_POSITIVE, ( int * ) &conf->db_request_limit, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;

#ifdef ATTR_INDEX_status
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "check_purge_status_on_startup",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->check_purge_status_on_startup = intval;
#endif
        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "recheck_ignored_classes",
                           0, &intval, NULL, NULL, msg_out );
        if ( ( rc != 0 ) && ( rc != ENOENT ) )
            return rc;
        else if ( rc != ENOENT )
            conf->recheck_ignored_classes = intval;

        rc = GetBoolParam( param_block, PURGE_PARAM_BLOCK, "simulation_mode",
                           0, &intval, NULL, NULL, msg_out );
        if ( rc == 0 )
        {
            DisplayLog( LVL_CRIT, RESMONCFG_TAG,
                "WARNING: 'simulation_mode' parameter is deprecated. Use '--dry-run' option instead.");
        }

#ifdef _TMP_FS_MGR
        rc = GetStringParam(param_block, PURGE_PARAM_BLOCK, "purge_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {path}, {fid}, {fsname} */
                         conf->purge_command, RBH_PATH_MAX, NULL, NULL, msg_out);
        if ((rc != 0) && (rc != ENOENT))
            return rc;
#endif

        CheckUnknownParameters( param_block, PURGE_PARAM_BLOCK, purge_allowed );

    } /* end of purge parameters */

    /* get PURGE_TRIGGER blocks */

    for ( blc_index = 0; blc_index < rh_config_GetNbBlocks( config ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetBlockByIndex( config, blc_index );
        critical_err_check( curr_item, "root" );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( block_name, "root" );

        if ( !strcasecmp( block_name, TRIGGER_BLOCK ) )
        {
            if ( conf->trigger_count == 0 )
                conf->trigger_list = ( trigger_item_t * ) malloc( sizeof( trigger_item_t ) );
            else
                conf->trigger_list =
                    ( trigger_item_t * ) realloc( conf->trigger_list,
                                                  ( conf->trigger_count +
                                                    1 ) * sizeof( trigger_item_t ) );

            conf->trigger_count++;

            /* analyze trigger block */
            rc = parse_trigger_block( curr_item, block_name,
                                      &conf->trigger_list[conf->trigger_count - 1], msg_out );

            if ( rc )
                return rc;
        }
    }

    return 0;
}
Exemplo n.º 4
0
static int parse_trigger_block( config_item_t config_blk, const char *block_name,
                                trigger_item_t * p_trigger_item, char *msg_out )
{
    int            rc;
    int            rc_hp, rc_lp, rc_hv, rc_lv, rc_hc, rc_lc;
    unsigned int high_count = 0;
    unsigned int low_count = 0;
    double         h_pct, l_pct;
    unsigned long long h_vol, l_vol;
    uint64_t       h_cnt, l_cnt;
    int            tmpval;
    int            i;
    char           tmpstr[1024];
    char         **arg_tab;
    unsigned int   arg_count;

    static const char *trigger_expect[] =
    {
        "trigger_on", "check_interval",
        "high_threshold_pct", "low_threshold_pct",
        "high_threshold_vol", "low_threshold_vol",
        "high_threshold_cnt", "low_threshold_cnt",
        "alert_high", "alert_low",
        /* for backward compatibility */
        "high_watermark_pct", "low_watermark_pct",
        "high_watermark_vol", "low_watermark_vol",
        "high_watermark_cnt", "low_watermark_cnt",
        "notify", "notify_hw", "alert_lw",
        NULL
    };


    /* retrieve parameters */

    rc = GetStringParam( config_blk, block_name, "trigger_on",
                         PARAM_MANDATORY | STR_PARAM_NO_WILDCARDS, tmpstr, 1024, &arg_tab,
                         &arg_count, msg_out );

    if ( rc )                   /* even ENOENT retruns an error because trigger_on is mandatory */
        return rc;

    /* initialize list of optional args */
    p_trigger_item->list = NULL;
    p_trigger_item->list_size = 0;

    /* analyze trigger_on parameter */
    if ( !strcasecmp( tmpstr, "periodic" ) )
    {
        p_trigger_item->type = TRIGGER_ALWAYS;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = FALSE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "global_usage" ) )
    {
        p_trigger_item->type = TRIGGER_GLOBAL_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "OST_usage" ) )
    {
        p_trigger_item->type = TRIGGER_OST_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* no arg expected */
        if ( arg_count > 0 )
        {
            sprintf( msg_out,
                     "No extra argument expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }
    }
    else if ( !strcasecmp( tmpstr, "user_usage" ) )
    {
        p_trigger_item->type = TRIGGER_USER_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional arguments: user list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "group_usage" ) )
    {
        p_trigger_item->type = TRIGGER_GROUP_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional argument: group list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "pool_usage" ) )
    {
        p_trigger_item->type = TRIGGER_POOL_USAGE;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* optional arguments: user list */
        if ( arg_count > 0 )
        {
            p_trigger_item->list = ( char ** ) calloc( arg_count, sizeof( char * ) );
            p_trigger_item->list_size = arg_count;
            for ( i = 0; i < arg_count; i++ )
            {
                p_trigger_item->list[i] = ( char * ) malloc( strlen( arg_tab[i] ) + 1 );
                strcpy( p_trigger_item->list[i], arg_tab[i] );
            }
        }
    }
    else if ( !strcasecmp( tmpstr, "external_command" ) )
    {
        p_trigger_item->type = TRIGGER_CUSTOM_CMD;

        /* default: alert enabled if LW cannot be reached */
        p_trigger_item->alert_lw = TRUE;

        /* single mandatory argument: command */
        if ( arg_count != 1 )
        {
            sprintf( msg_out,
                     "A single mandatory argument is expected for trigger type '%s': %u argument(s) found.",
                     tmpstr, arg_count );
            return EINVAL;
        }

        p_trigger_item->list = ( char ** ) malloc( sizeof( char * ) );
        p_trigger_item->list[0] = ( char * ) malloc( strlen( arg_tab[0] ) + 1 );
        strcpy( p_trigger_item->list[0], arg_tab[0] );
        p_trigger_item->list_size = 1;
    }
    else
    {
        sprintf( msg_out, "Unexpected value for 'trigger_on' parameter: %s.", tmpstr );
        return EINVAL;
    }


    /* retrieve all threshold params and check their compatibility */
    high_count = low_count = 0;

    rc_hp = GetFloatParam( config_blk, block_name, "high_threshold_pct",
                         FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &h_pct,
                         NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hp == ENOENT )
        rc_hp = GetFloatParam( config_blk, block_name, "high_watermark_pct",
                             FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &h_pct,
                             NULL, NULL, msg_out );

    if ( ( rc_hp != 0 ) && ( rc_hp != ENOENT ) )
        return rc_hp;
    else if ( rc_hp != ENOENT )
        high_count++;

    rc_hv = GetSizeParam( config_blk, block_name, "high_threshold_vol",
                        INT_PARAM_POSITIVE, &h_vol, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hv == ENOENT )
        rc_hv = GetSizeParam( config_blk, block_name, "high_watermark_vol",
                              INT_PARAM_POSITIVE, &h_vol, NULL, NULL, msg_out );

    if ( ( rc_hv != 0 ) && ( rc_hv != ENOENT ) )
        return rc_hv;
    else if ( rc_hv != ENOENT )
        high_count++;

    rc_hc = GetInt64Param( config_blk, block_name, "high_threshold_cnt",
                           INT_PARAM_POSITIVE, &h_cnt, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_hc == ENOENT )
            rc_hc = GetInt64Param( config_blk, block_name, "high_watermark_cnt",
                                   INT_PARAM_POSITIVE, &h_cnt, NULL, NULL, msg_out );
    if ( ( rc_hc != 0 ) && ( rc_hc != ENOENT ) )
        return rc_hc;
    else if ( rc_hc != ENOENT )
        high_count++;

    rc_lp = GetFloatParam( config_blk, block_name, "low_threshold_pct",
                         FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &l_pct,
                         NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lp == ENOENT )
        rc_lp = GetFloatParam( config_blk, block_name, "low_watermark_pct",
                             FLOAT_PARAM_POSITIVE | ALLOW_PCT_SIGN, &l_pct,
                             NULL, NULL, msg_out );

    if ( ( rc_lp != 0 ) && ( rc_lp != ENOENT ) )
        return rc_lp;
    else if ( rc_lp != ENOENT )
        low_count++;

    rc_lv = GetSizeParam( config_blk, block_name, "low_threshold_vol",
                        INT_PARAM_POSITIVE, &l_vol, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lv == ENOENT )
        rc_lv = GetSizeParam( config_blk, block_name, "low_watermark_vol",
                            INT_PARAM_POSITIVE, &l_vol, NULL, NULL, msg_out );
    if ( ( rc_lv != 0 ) && ( rc_lv != ENOENT ) )
        return rc_lv;
    else if ( rc_lv != ENOENT )
        low_count++;

    rc_lc = GetInt64Param( config_blk, block_name, "low_threshold_cnt",
                           INT_PARAM_POSITIVE, &l_cnt, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc_lc == ENOENT )
        rc_lc = GetInt64Param( config_blk, block_name, "low_watermark_cnt",
                               INT_PARAM_POSITIVE, &l_cnt, NULL, NULL, msg_out );
    if ( ( rc_lc != 0 ) && ( rc_lc != ENOENT ) )
        return rc_lc;
    else if ( rc_lc != ENOENT )
        low_count++;

    if ( p_trigger_item->type == TRIGGER_ALWAYS )
    {
        /* in case of 'periodic' trigger, no thresholds are expected */
        if ( (high_count > 0) || (low_count > 0) )
        {
            strcpy( msg_out,
                    "No high/low threshold expected for trigger type 'periodic'" );
            return EINVAL;
        }
    }
    else if ( p_trigger_item->type == TRIGGER_CUSTOM_CMD )
    {
        /* in case of an external command, no thresholds are expected */
        if ( (high_count > 0) || (low_count > 0) )
        {
            strcpy( msg_out,
                    "No high/low thresholds expected for trigger type 'external_command'" );
            return EINVAL;
        }
    }
    else if ( high_count > 1 )
    {
        strcpy( msg_out, "Multiple purge start conditions in trigger." );
        return EINVAL;
    }
    else if ( low_count > 1 )
    {
        strcpy( msg_out, "Multiple purge stop conditions in trigger." );
        return EINVAL;
    }
    else if ( high_count == 0 )
    {
        strcpy( msg_out, "No purge start condition found in trigger "
                         "(mandatory). 'high_threshold_pct', 'high_threshold_vol'"
                         "or 'high_threshold_cnt' expected" );
        return ENOENT;
    }
    else if ( low_count == 0 )
    {
        strcpy( msg_out, "No purge stop condition found in trigger "
                         "(mandatory). 'low_threshold_pct', 'low_threshold_vol'"
                         "or 'low_threshold_cnt' expected" );
        return ENOENT;
    }
    else if ( rc_hc != rc_lc ) /* both 0 or both ENOENT */
    {
        strcpy( msg_out, "Incompatible threshold types: 'high_threshold_cnt' "
                         "must be used with 'low_threshold_cnt'" );
        return ENOENT;
    }

    /* NOTE: count threshold for HSM systems only match online files (not released)*/

    /* count threshold is only on global usage */
    if ( (p_trigger_item->type != TRIGGER_GLOBAL_USAGE)
         && (p_trigger_item->type != TRIGGER_ALWAYS)
         && (p_trigger_item->type != TRIGGER_USER_USAGE)
         && (p_trigger_item->type != TRIGGER_GROUP_USAGE)
         && ( (rc_hc == 0) || (rc_lc == 0) ) )
    {
        strcpy( msg_out, "Threshold on entry count is only supported "
                         "for 'global_usage', 'user_usage', 'group_usage' and 'periodic' triggers" );
        return EINVAL;
    }

    if ( rc_hp == 0 )
    {
        p_trigger_item->hw_type = PCT_THRESHOLD;
        p_trigger_item->hw_percent = h_pct;
    }
    else if ( rc_hv == 0 )
    {
        p_trigger_item->hw_type = VOL_THRESHOLD;
        p_trigger_item->hw_volume = h_vol;
    }
    else if ( rc_hc == 0 )
    {
        p_trigger_item->hw_type = COUNT_THRESHOLD;
        p_trigger_item->hw_count = h_cnt;
    }

    if ( rc_lp == 0 )
    {
        p_trigger_item->lw_type = PCT_THRESHOLD;
        p_trigger_item->lw_percent = l_pct;
    }
    else if ( rc_lv == 0 )
    {
        p_trigger_item->lw_type = VOL_THRESHOLD;
        p_trigger_item->lw_volume = l_vol;
    }
    else if ( rc_lc == 0 )
    {
        p_trigger_item->lw_type = COUNT_THRESHOLD;
        p_trigger_item->lw_count = l_cnt;
    }

    /* retrieve check interval parameter */

    rc = GetDurationParam( config_blk, block_name, "check_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL
                           | PARAM_MANDATORY, &tmpval, NULL,
                           NULL, msg_out );
    if ( rc )
        return rc;
    p_trigger_item->check_interval = tmpval;

    rc = GetBoolParam( config_blk, block_name, "alert_high", 0,
                       &tmpval, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "notify_hw", 0,
                           &tmpval, NULL, NULL, msg_out );
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "notify", 0,
                           &tmpval, NULL, NULL, msg_out );

    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        p_trigger_item->alert_hw = tmpval;

    rc = GetBoolParam( config_blk, block_name, "alert_low", 0,
                       &tmpval, NULL, NULL, msg_out );
    /* for backward compatibility */
    if ( rc == ENOENT )
        rc = GetBoolParam( config_blk, block_name, "alert_lw", 0,
                           &tmpval, NULL, NULL, msg_out );

    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        p_trigger_item->alert_lw = tmpval;

    CheckUnknownParameters( config_blk, block_name, trigger_expect );

    return 0;

}
Exemplo n.º 5
0
int read_scalar_params(config_item_t block, const char *block_name,
                       const cfg_param_t * params, char *msgout)
{
    int i;
    int rc = 0;

    /* read all expected parameters */
    for (i = 0; params[i].name != NULL; i++)
    {
        switch (params[i].type)
        {
            case PT_STRING:
                rc = GetStringParam(block, block_name, params[i].name,
                                    params[i].flags, (char*)params[i].ptr, params[i].ptrsize,
                                    NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_CMD:
                rc = GetCommandParam(block, block_name, params[i].name,
                                     params[i].flags, (char***)params[i].ptr,
                                     NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_BOOL:
                rc = GetBoolParam(block, block_name, params[i].name,
                                  params[i].flags, (bool*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_DURATION:
                rc = GetDurationParam(block, block_name, params[i].name,
                                  params[i].flags, (time_t*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_SIZE:
                rc = GetSizeParam(block, block_name, params[i].name,
                                  params[i].flags,
                                  (unsigned long long*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_INT:
                rc = GetIntParam(block, block_name, params[i].name,
                                  params[i].flags, (int*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_INT64:
                rc = GetInt64Param(block, block_name, params[i].name,
                                  params[i].flags, (uint64_t*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_FLOAT:
                rc = GetFloatParam(block, block_name, params[i].name,
                                  params[i].flags, (double*)params[i].ptr,
                                  NULL, NULL, msgout);
                if cfg_is_err(rc, params[i].flags)
                    return rc;
                break;

            case PT_TYPE:
                sprintf(msgout, "Unexpected type for %s parameter (type)",
                        params[i].name);
                return EINVAL;
        }
    }
    return 0;
}
Exemplo n.º 6
0
int ReadLogConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, tmpval;
    char           tmpstr[1024];
    log_config_t  *conf = ( log_config_t * ) module_config;

    static const char *allowed_params[] = { "debug_level", "log_file", "report_file",
        "alert_file", "alert_mail", "stats_interval", "batch_alert_max",
        "alert_show_attrs", "syslog_facility",
        NULL
    };

    /* get Log block */

    config_item_t  log_block = rh_config_FindItemByName( config, RBH_LOG_CONFIG_BLOCK );

    if ( log_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" RBH_LOG_CONFIG_BLOCK "'" );
        /* no parameter is mandatory => Not an error */
        return 0;
    }

    if ( rh_config_ItemType( log_block ) != CONFIG_ITEM_BLOCK )
    {
        sprintf( msg_out, "A block is expected for '" RBH_LOG_CONFIG_BLOCK "' item, line %d",
                 rh_config_GetItemLine( log_block ) );
        return EINVAL;
    }

    /* retrieve parameters */

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "debug_level",
                         STR_PARAM_NO_WILDCARDS, tmpstr, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
    {
        tmpval = str2debuglevel( tmpstr );

        if ( tmpval < 0 )
        {
            sprintf( msg_out,
                     "Invalid value for " RBH_LOG_CONFIG_BLOCK
                     "::debug_level: '%s'. CRIT, MAJOR, EVENT, VERB, DEBUG or FULL expected",
                     tmpstr );
            return EINVAL;
        }
        else
            conf->debug_level = tmpval;
    }

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "log_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->log_file, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "report_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->report_file, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_file",
                         STR_PARAM_ABSOLUTE_PATH | STR_PARAM_NO_WILDCARDS | STDIO_ALLOWED,
                         conf->alert_file, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
        conf->alert_file[0] = '\0';

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "syslog_facility",
                         STR_PARAM_NO_WILDCARDS,
                         tmpstr, 1024, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
    {
        rc = check_syslog_facility( tmpstr, &conf->syslog_facility,
                                    &conf->syslog_priority );
        if (rc)
        {
            sprintf( msg_out, "Invalid syslog channel '%s': expected syntax: <facility>[.<priority>]",
                     tmpstr );
            return rc;
        }
    }

    rc = GetStringParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_mail",
                         STR_PARAM_MAIL, conf->alert_mail, 256, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == ENOENT )
        conf->alert_mail[0] = '\0';

    rc = GetDurationParam( log_block, RBH_LOG_CONFIG_BLOCK, "stats_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL, &tmpval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc != ENOENT )
        conf->stats_interval = tmpval;

    rc = GetIntParam( log_block, RBH_LOG_CONFIG_BLOCK, "batch_alert_max",
                      INT_PARAM_POSITIVE, (int *)&conf->batch_alert_max,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( log_block, RBH_LOG_CONFIG_BLOCK, "alert_show_attrs",
                      INT_PARAM_POSITIVE, &conf->alert_show_attrs,
                      NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    CheckUnknownParameters( log_block, RBH_LOG_CONFIG_BLOCK, allowed_params );

    return 0;
}
Exemplo n.º 7
0
int FSScan_ReadConfig( config_file_t config, void *module_config, char *msg_out, int for_reload )
{
    int            rc, blc_index;
    fs_scan_config_t *conf = ( fs_scan_config_t * ) module_config;
    int scan_intl_set = FALSE;
    int scan_intl = 0;

    static const char * fsscan_allowed[] =
    {
        "scan_interval", "min_scan_interval", "max_scan_interval",
        "scan_retry_delay", "nb_threads_scan", "scan_op_timeout",
        "exit_on_timeout", "spooler_check_interval", "nb_prealloc_tasks",
		"completion_command",
        IGNORE_BLOCK, NULL
    };

    /* get FS Scan block */

    config_item_t  fsscan_block = rh_config_FindItemByName( config, FSSCAN_CONFIG_BLOCK );

    if ( fsscan_block == NULL )
    {
        strcpy( msg_out, "Missing configuration block '" FSSCAN_CONFIG_BLOCK "'" );
        /* No error because no parameter is mandatory  */
        return 0;
    }

    if ( rh_config_ItemType( fsscan_block ) != CONFIG_ITEM_BLOCK )
    {
        strcpy( msg_out, "A block is expected for '" FSSCAN_CONFIG_BLOCK "' item" );
        return EINVAL;
    }

    /* retrieve parameters */
    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "min_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->min_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "max_scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->max_scan_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
        scan_intl_set = TRUE;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           &scan_intl, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;
    else if ( rc == 0 )
    {
        if (scan_intl_set)
        {
            strcpy( msg_out, "scan_interval parameter cannot be used with min/max_scan_interval" );
            return EINVAL;
        }
        conf->min_scan_interval = scan_intl;
        conf->max_scan_interval = scan_intl;
    }

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "scan_retry_delay",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->scan_retry_delay, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetIntParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                      "nb_threads_scan",
                      INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                      ( int * ) &conf->nb_threads_scan, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "scan_op_timeout",
                            INT_PARAM_POSITIVE,    /* 0 is authorized => no timeout */
                           ( int * ) &conf->scan_op_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetBoolParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "exit_on_timeout", 0,
                       (int*)&conf->exit_on_timeout, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "spooler_check_interval",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->spooler_check_interval, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetDurationParam( fsscan_block, FSSCAN_CONFIG_BLOCK,
                           "nb_prealloc_tasks",
                           INT_PARAM_POSITIVE | INT_PARAM_NOT_NULL,
                           ( int * ) &conf->nb_prealloc_tasks, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;

    rc = GetStringParam( fsscan_block, FSSCAN_CONFIG_BLOCK, "completion_command",
                         STR_PARAM_ABSOLUTE_PATH, /* can contain wildcards: {cfg} or {fspath} */
                         conf->completion_command, RBH_PATH_MAX, NULL, NULL, msg_out );
    if ( ( rc != 0 ) && ( rc != ENOENT ) )
        return rc;


    /* Find and parse "ignore" blocks */
    for ( blc_index = 0; blc_index < rh_config_GetNbItems( fsscan_block ); blc_index++ )
    {
        char          *block_name;
        config_item_t  curr_item = rh_config_GetItemByIndex( fsscan_block, blc_index );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( rh_config_ItemType( curr_item ) != CONFIG_ITEM_BLOCK )
            continue;

        block_name = rh_config_GetBlockName( curr_item );
        critical_err_check( curr_item, FSSCAN_CONFIG_BLOCK );

        if ( !strcasecmp( block_name, IGNORE_BLOCK ) )
        {
            if ( conf->ignore_count == 0 )
                conf->ignore_list = ( whitelist_item_t * ) malloc( sizeof( whitelist_item_t ) );
            else
                conf->ignore_list =
                    ( whitelist_item_t * ) realloc( conf->ignore_list,
                                                 ( conf->ignore_count + 1 )
                                                 * sizeof( whitelist_item_t ) );

            conf->ignore_count++;

            /* analyze boolean expression */
            rc = GetBoolExpr( curr_item, block_name,
                              &conf->ignore_list[conf->ignore_count - 1].bool_expr,
                              &conf->ignore_list[conf->ignore_count - 1].attr_mask, msg_out );

            if ( rc )
                return rc;

        }
    }                           /* Loop on subblocks */

    CheckUnknownParameters( fsscan_block, FSSCAN_CONFIG_BLOCK, fsscan_allowed );

    return 0;

}