function monitoring_munin_enable in Monitoring 7
Implements hook_enable()
Creates Munin multigraphs and does default Munin specific sensors config.
File
- modules/
monitoring_munin/ monitoring_munin.install, line 15 - Monitoring munin install file.
Code
function monitoring_munin_enable() {
$sensor_info_by_categories = monitoring_sensor_info_by_categories();
foreach (module_implements('munin_default_multigraphs') as $module) {
foreach (module_invoke($module, 'munin_default_multigraphs') as $multigraph_title => $multigraph_info) {
$has_sensors = FALSE;
// Configure sensors in the categories to be part of the given multigraph.
// Yes this nesting is not nice, however this is just one time enable
// logic with test coverage.
if (isset($multigraph_info['categories'])) {
foreach ($multigraph_info['categories'] as $category) {
if (isset($sensor_info_by_categories[$category])) {
/** @var SensorInfo $sensor_info */
foreach ($sensor_info_by_categories[$category] as $sensor_info) {
if ($sensor_info
->isNumeric()) {
$settings = monitoring_sensor_settings_get($sensor_info
->getName());
$settings['munin']['munin_enabled'] = TRUE;
$settings['munin']['multigraphs'][] = $multigraph_title;
monitoring_sensor_settings_save($sensor_info
->getName(), $settings);
$has_sensors = TRUE;
}
}
}
}
}
// Configure individual sensors to be part of the given multigraph.
if (isset($multigraph_info['sensors'])) {
foreach ($multigraph_info['sensors'] as $sensor_name) {
try {
$sensor_info = monitoring_sensor_manager()
->getSensorInfoByName($sensor_name);
} catch (NonExistingSensorException $e) {
drupal_set_message($e
->getMessage(), 'error');
watchdog_exception('monitoring_munin', $e);
}
if (!$sensor_info
->isEnabled()) {
continue;
}
$settings = monitoring_sensor_settings_get($sensor_info
->getName());
$settings['munin']['munin_enabled'] = TRUE;
$settings['munin']['multigraphs'][] = $multigraph_title;
monitoring_sensor_settings_save($sensor_info
->getName(), $settings);
$has_sensors = TRUE;
}
}
// Get a fresh list in case the graph has been created in previous
// iterations.
// Also create a multigraph only if there are any sensors enabled for it.
$multigraphs = monitoring_munin_multigraphs();
if ($has_sensors && !isset($multigraphs[$multigraph_title])) {
monitoring_munin_multigraph_save($multigraph_title, $multigraph_info['vlabel']);
}
}
}
}