diff --git a/monitoring.module b/monitoring.module index 8a9728f..3d72334 100644 --- a/monitoring.module +++ b/monitoring.module @@ -21,7 +21,11 @@ use Drupal\monitoring\SensorRunner; * Sensor info. */ function monitoring_sensor_info($sensor_name = NULL, $reset = FALSE) { - $info = &drupal_static(__FUNCTION__, array(), $reset); + $info = &drupal_static(__FUNCTION__, array()); + + if ($reset) { + $info = array(); + } if (empty($info)) { @@ -41,14 +45,14 @@ function monitoring_sensor_info($sensor_name = NULL, $reset = FALSE) { // Favor custom implementation. if (in_array($module, $custom_implementations)) { $result = module_invoke($module, 'monitoring_sensor_info'); - $info = array_merge_recursive($info, $result); + $info = drupal_array_merge_deep($info, $result); } // If there is no custom implementation try to find local integration. elseif (function_exists('monitoring_' . $module . '_monitoring_sensor_info')) { $function = 'monitoring_' . $module . '_monitoring_sensor_info'; $result = $function(); if (is_array($result)) { - $info = array_merge_recursive($info, $result); + $info = drupal_array_merge_deep($info, $result); } } } @@ -73,6 +77,9 @@ function monitoring_sensor_info($sensor_name = NULL, $reset = FALSE) { ); $value['settings'] = monitoring_sensor_settings_merge($key, $value['settings']); } + + // Support variable overrides. + $info = drupal_array_merge_deep($info, variable_get('monitoring_sensor', array())); } if (!empty($sensor_name)) { @@ -116,10 +123,14 @@ function monitoring_sensor_info_by_categories($enabled = TRUE) { * A populated SensorInfo object. */ function monitoring_sensor_info_instance($sensor_name = NULL, $reset = FALSE) { - $instances = &drupal_static(__FUNCTION__, array(), $reset); + $instances = &drupal_static(__FUNCTION__, array()); + if ($reset) { + $instances = array(); + } if (empty($instances)) { foreach (monitoring_sensor_info(NULL, $reset) as $key => $value) { + $instances[$key] = new SensorInfo($key, $value); } } diff --git a/test/tests/monitoring.api.test b/test/tests/monitoring.api.test index af000fb..302e6a6 100644 --- a/test/tests/monitoring.api.test +++ b/test/tests/monitoring.api.test @@ -242,6 +242,20 @@ class MonitoringApiTest extends MonitoringTestBase { variable_set('test_sensor_result_data', $test_sensor_result_data); $result = monitoring_sensor_run('test_sensor', TRUE); $this->assertNull($result->getSensorValue()); + + // Test variable-based overrides. + global $conf; + $conf['monitoring_sensor']['test_sensor'] = array( + 'label' => 'Overridden sensor', + 'settings' => array( + 'caching time' => 1, + 'new setting' => 'example value', + ), + ); + $info = monitoring_sensor_info_instance('test_sensor', TRUE); + $this->assertEqual('Overridden sensor', $info->getLabel()); + $this->assertEqual(1, $info->getSetting('caching time')); + $this->assertEqual('example value', $info->getSetting('new setting')); } function testLogging() {