You are here

function prod_check_settings_form in Production check & Production monitor 7

Same name and namespace in other branches
  1. 6 includes/prod_check.admin.inc \prod_check_settings_form()

Build settings form.

1 string reference to 'prod_check_settings_form'
prod_check_menu in ./prod_check.module
Implementation of hook_menu()

File

includes/prod_check.admin.inc, line 37

Code

function prod_check_settings_form($form, &$form_state) {
  drupal_set_title(t('Production check settings'));
  $form = array();

  // Add stylesheets & CSS.
  $base = drupal_get_path('module', 'prod_check');
  $form['#attached'] = array(
    'css' => array(
      'type' => 'file',
      'data' => $base . '/css/prod-check.css',
    ),
    'js' => array(
      array(
        'type' => 'file',
        'data' => $base . '/js/jquery.equalheights.js',
      ),
      array(
        'type' => 'file',
        'data' => $base . '/js/jquery.maskedinput.min.js',
      ),
      array(
        'type' => 'file',
        'data' => $base . '/js/prod-check.js',
      ),
    ),
  );

  // E-mail settings.
  $form['prod_check_general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#description' => t('Settings to allow certain checks to function properly.'),
    '#collapsible' => FALSE,
  );
  $form['prod_check_general']['prod_check_sitemail'] = array(
    '#type' => 'textfield',
    '#title' => t('Mail check'),
    '#default_value' => variable_get('prod_check_sitemail', ''),
    '#size' => 60,
    '#description' => t('Enter (part of) the e-mail address you always <strong>use when developing</strong> a website. This is used in a regular expression in the "Site e-mail", Contact and Webform modules check.'),
    '#required' => FALSE,
  );
  if (module_exists('dblog')) {
    $form['prod_check_general']['prod_check_dblog_php'] = array(
      '#type' => 'select',
      '#title' => t('Minimal watchdog severity for PHP errors'),
      '#default_value' => variable_get('prod_check_dblog_php', WATCHDOG_WARNING),
      '#options' => watchdog_severity_levels(),
      '#description' => t('Select the severity level from which to start reporting PHP errors being logged to the watchdog table.'),
      '#required' => TRUE,
    );
    $form['prod_check_general']['prod_check_dblog_php_threshold'] = array(
      '#type' => 'textfield',
      '#title' => t('Threshold for PHP errors'),
      '#size' => 2,
      '#default_value' => variable_get('prod_check_dblog_php_threshold', 1),
      '#description' => t('Enter the number of times a PHP error needs to occur before reporting a problem. E.g. entering 3 here will allow 2 occurences of the exact same PHP error without an error being reported.'),
      '#required' => TRUE,
    );
  }
  $form['prod_check_apc'] = array(
    '#type' => 'fieldset',
    '#title' => t('Advanced APC/OPcache settings'),
    '#description' => t('These settings are used in the !link functionality.', prod_check_link_array('advanced APC', 'admin/reports/status/apc-opc')),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );

  // Cache full count threshold
  $form['prod_check_apc']['prod_check_apc_expunge'] = array(
    '#type' => 'textfield',
    '#title' => t('APC/OPcache cache full count threshold'),
    '#default_value' => variable_get('prod_check_apc_expunge', 0),
    '#size' => 2,
    '#description' => t('Issue a critical error when the cache full count is greater than the number entered here.'),
    '#required' => FALSE,
  );

  // APC user.
  $form['prod_check_apc']['prod_check_apcuser'] = array(
    '#type' => 'textfield',
    '#title' => t('APC advanced features username'),
    '#default_value' => variable_get('prod_check_apcuser', 'apc'),
    '#size' => 60,
    '#description' => t('The username for logging in to the APC settings page.'),
    '#required' => FALSE,
  );

  // APC password.
  $form['prod_check_apc']['prod_check_apcpass'] = array(
    '#type' => 'password_confirm',
    '#title' => t('APC advanced features password'),
    '#size' => 60,
    '#description' => t('The password for logging in to the APC settings page.'),
    '#required' => FALSE,
  );

  // Disabled module settings
  $form['prod_check_disabled'] = array(
    '#type' => 'fieldset',
    '#title' => t('Disabled modules'),
    '#description' => t('You can choose to disable checking for updates for disabled modules here.'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['prod_check_disabled']['prod_check_exclude_disabled_modules'] = array(
    '#type' => 'checkbox',
    '#title' => t("Don't check for updates for disabled modules"),
    '#default_value' => variable_get('prod_check_exclude_disabled_modules', 0),
    '#description' => t('When checked, only enabled modules will be reported. Note that this can cause some modules that are used but not enabled (f.e. APC, memcache, domain,...) to get skipped. See the documentation on how to add disabled modules on a whitelist.'),
    '#required' => FALSE,
  );
  $modules = implode(', ', _prod_check_get_disabled_modules_whitelist());
  $form['prod_check_disabled']['prod_check_disabled_modules_whitelist'] = array(
    '#markup' => t('Currently these modules will be forcefully checked even when they are disabled: %modules', array(
      '%modules' => $modules,
    )),
  );

  // XMLRPC settings.
  $form['prod_check_xmlrpc'] = array(
    '#type' => 'fieldset',
    '#title' => t('Production monitor integration.'),
    '#description' => t('You can set up integration with the Production monitor module here.'),
    '#collapsible' => FALSE,
  );
  $form['prod_check_xmlrpc']['prod_check_enable_xmlrpc'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable XMLRPC API'),
    '#default_value' => variable_get('prod_check_enable_xmlrpc', 0),
    '#description' => t('Tick this box if you would like to the module to open up the XMLRPC api so that it can be queried externally to supply information to a base site for monitoring purposes.'),
    '#ajax' => array(
      'callback' => 'prod_check_enable_xmlrpc',
      'wrapper' => 'prod-check-xmlrpc',
      'effect' => 'fade',
    ),
    '#required' => FALSE,
  );

  // The #value here is necessary for the markup field to be rendered :-(
  $form['prod_check_xmlrpc']['xmlrpc'] = array(
    '#type' => 'markup',
    '#prefix' => '<div id="prod-check-xmlrpc">',
    '#suffix' => '</div>',
  );

  // Only show when the checkbox above is selected.
  if (!isset($form_state['values']['prod_check_enable_xmlrpc'])) {
    $form_state['values']['prod_check_enable_xmlrpc'] = variable_get('prod_check_enable_xmlrpc', 0);
  }
  if ($form_state['values']['prod_check_enable_xmlrpc']) {
    $form['prod_check_xmlrpc']['xmlrpc']['prod_check_xmlrpc_key'] = array(
      '#type' => 'textfield',
      '#title' => t('API key'),
      '#default_value' => variable_get('prod_check_xmlrpc_key', prod_check_generate_key()),
      '#maxlength' => 128,
      '#size' => 60,
      '#description' => t('Enter a key here to ensure secure transfer of data over the API. Use a mixture of alphanumeric and special characters for increased security.'),
      '#required' => FALSE,
    );
    $form['prod_check_xmlrpc']['xmlrpc']['prod_check_module_list_day'] = array(
      '#type' => 'select',
      '#title' => t('Report module list every'),
      '#options' => array(
        t('Sunday'),
        t('Monday'),
        t('Tuesday'),
        t('Wednesday'),
        t('Thursday'),
        t('Friday'),
        t('Saturday'),
      ),
      '#default_value' => variable_get('prod_check_module_list_day', 0),
      '#description' => t('Defines which day the module list will be fetchable by Production monitor for an update status check.'),
      '#required' => FALSE,
    );
    $form['prod_check_xmlrpc']['xmlrpc']['prod_check_module_list_time'] = array(
      '#type' => 'textfield',
      '#title' => t('at this time'),
      '#default_value' => variable_get('prod_check_module_list_time', '03:00'),
      '#maxlength' => 5,
      '#size' => 5,
      '#description' => t('Defines what time (HH:MM) the module list will be fetchable by Production monitor for an update status check.'),
      '#required' => FALSE,
    );

    // See http://drupal.org/node/1058896#comment-5594076 .
    if (variable_get('prod_check_module_list_lastrun', 0) != -1) {
      $form['prod_check_xmlrpc']['xmlrpc']['reset'] = array(
        '#prefix' => '<div class="clear">',
        '#type' => 'submit',
        '#value' => t('Force immediate module list reporting'),
        '#postfix' => '</div>',
      );
    }
    else {
      $form['prod_check_xmlrpc']['xmlrpc']['reset'] = array(
        '#markup' => '<div class="description clear">' . t('Production monitor will fetch the module list on next cron run or when manually invoked for this site!') . '</div>',
      );
    }
  }

  // Nagios settings.
  if (module_exists('nagios')) {
    $form['prod_check_nagios'] = array(
      '#type' => 'fieldset',
      '#title' => t('Nagios integration.'),
      '#description' => t('You can set up integration with the !link module here.', prod_check_link_array('Nagios', 'http://drupal.org/project/nagios')),
      '#collapsible' => FALSE,
    );
    $form['prod_check_nagios']['prod_check_enable_nagios'] = array(
      '#type' => 'checkbox',
      '#title' => t('Enable Nagios integration'),
      '#description' => t('Tick this box if you want to enable integration with Nagios. The !link module is required for this to function.', array(
        '!link' => l(t('Nagios'), 'http://drupal.org/project/nagios', array(
          'attributes' => array(
            'title' => t('Nagios'),
          ),
        )),
      )),
      '#default_value' => variable_get('prod_check_enable_nagios', 0),
      '#ajax' => array(
        'callback' => 'prod_check_enable_nagios',
        'wrapper' => 'prod-check-nagios',
        'effect' => 'fade',
      ),
      '#required' => FALSE,
    );

    // The #value here is necessary for the markup field to be rendered :-(
    $form['prod_check_nagios']['nagios'] = array(
      '#type' => 'markup',
      '#prefix' => '<div id="prod-check-nagios">',
      '#suffix' => '</div>',
    );

    // Only show when the checkbox above is selected.
    if (!isset($form_state['values']['prod_check_enable_nagios'])) {
      $form_state['values']['prod_check_enable_nagios'] = variable_get('prod_check_enable_nagios', 0);
    }

    // TODO: find a way to detect when this is rendered so we can adjust the
    // prod-check.js and apply equalheights/width
    if ($form_state['values']['prod_check_enable_nagios']) {
      $form['prod_check_nagios']['nagios']['settings'] = _prod_check_functions_as_form();
      $options = variable_get('prod_check_nagios_checks', array());
      if (!empty($options)) {

        // Just to increase readability of the source here.
        $monitor_settings =& $form['prod_check_nagios']['nagios']['settings']['prod_check_settings']['monitor_settings'];

        // Set default values to last saved state
        foreach (element_children($monitor_settings) as $set) {
          if (isset($options[$set])) {
            $monitor_settings[$set]['#default_value'] = $options[$set];
          }
          else {

            // No settings available, so uncheck all.
            $monitor_settings[$set]['#default_value'] = array();
          }
        }
      }
      $form['prod_check_nagios']['nagios']['settings']['prod_check_nagios_unique'] = array(
        '#type' => 'select',
        '#title' => t('When Nagios unique ID not recieved'),
        '#description' => t('Select what should happen when the Nagios unique ID is not recieved by the nagios page.'),
        '#options' => array(
          'default' => t('default Nagios module behavior'),
          '404' => t('throw a 404 error'),
          'home' => t('redirect to homepege'),
        ),
        '#default_value' => variable_get('prod_check_nagios_unique', 'default'),
        '#required' => FALSE,
      );
      $form['prod_check_nagios']['nagios']['settings']['prod_check_nagios_takeover'] = array(
        '#markup' => '<p>' . t('If you want prod_check to take over the Nagios status page, you can edit the !settings and enter %callback. Only then will the setting above have any effect!', array(
          '!settings' => l(t('Nagios page callback'), 'admin/config/system/nagios'),
          '%callback' => 'prod_check_nagios_status_page',
        )) . '</p>',
      );
      $form['prod_check_nagios']['nagios']['settings']['prod_check_nagios_verbose'] = array(
        '#type' => 'checkbox',
        '#title' => t('Show verbose status info'),
        '#description' => t('Tick this box if you want to see detailed information about every check. Useful for debugging or first setup, but <strong>not recommended for production use!</strong>'),
        '#default_value' => variable_get('prod_check_nagios_verbose', 0),
        '#required' => FALSE,
      );
    }
  }

  // Submit buttons.
  // Markup field for proper styling.
  $form['buttons'] = array(
    '#type' => 'markup',
    '#prefix' => '<div class="form-actions">',
    '#suffix' => '</div>',
  );
  $form['buttons']['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Save configuration'),
  );
  $form['buttons']['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
  );
  return $form;
}