You are here

function statsd_admin_settings_validate in StatsD 7

Same name and namespace in other branches
  1. 6 statsd.admin.inc \statsd_admin_settings_validate()
  2. 7.2 statsd.admin.inc \statsd_admin_settings_validate()

Validation handler for the administrative settings.

File

./statsd.admin.inc, line 104

Code

function statsd_admin_settings_validate($form, &$form_state) {
  $form_state['values']['statsd_host'] = trim($form_state['values']['statsd_host']);
  $form_state['values']['statsd_port'] = trim($form_state['values']['statsd_port']);
  $form_state['values']['statsd_timeout'] = trim($form_state['values']['statsd_timeout']);
  $form_state['values']['statsd_sample_rate'] = trim($form_state['values']['statsd_sample_rate']);
  $form_state['values']['statsd_prefix'] = trim(rtrim($form_state['values']['statsd_prefix'], '.'));
  $form_state['values']['statsd_suffix'] = trim(ltrim($form_state['values']['statsd_suffix'], '.'));
  $form_state['values']['statsd_series_replacement'] = trim($form_state['values']['statsd_series_replacement']);
  $sample_rate = $form_state['values']['statsd_sample_rate'];
  if (!is_numeric($sample_rate) || $sample_rate <= 0 || $sample_rate > 1) {
    form_set_error('statsd_sample_rate', t('The sample rate must be a value between 0 and 1'));
  }
  $statsd_prefix = $form_state['values']['statsd_prefix'];
  if (preg_match(STATSD_SERIES_INVALID_CHARACTERS, $statsd_prefix)) {
    form_set_error('statsd_prefix', t('The prefix cannot contain invalid characters for Graphite series names.'));
  }
  $statsd_suffix = $form_state['values']['statsd_suffix'];
  if (preg_match(STATSD_SERIES_INVALID_CHARACTERS, $statsd_suffix)) {
    form_set_error('statsd_suffix', t('The suffix cannot contain invalid characters for Graphite series names.'));
  }
  $series_replacement = $form_state['values']['statsd_series_replacement'];
  if (preg_match(STATSD_SERIES_INVALID_CHARACTERS, $series_replacement)) {
    form_set_error('statsd_series_replacement', t('The replacement value cannot contain invalid characters for Graphite series names.'));
  }
}