monitoring_munin.install in Monitoring 7
Monitoring munin install file.
File
modules/monitoring_munin/monitoring_munin.installView source
<?php
/**
* @file
* Monitoring munin install file.
*/
use Drupal\monitoring\Sensor\NonExistingSensorException;
use Drupal\monitoring\Sensor\SensorInfo;
/**
* Implements hook_enable()
*
* Creates Munin multigraphs and does default Munin specific sensors config.
*/
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']);
}
}
}
}
/**
* Implements hook_uninstall().
*/
function monitoring_munin_uninstall() {
db_delete('variable')
->condition('name', 'monitoring_munin%', 'LIKE')
->execute();
}
Functions
Name | Description |
---|---|
monitoring_munin_enable | Implements hook_enable() |
monitoring_munin_uninstall | Implements hook_uninstall(). |