munin_api.install 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. // $Id$
  3. /**
  4. * @file
  5. * Munin API for Drupal: installation and runtime checks.
  6. *
  7. * @author Frederic G. MARAND
  8. *
  9. * @copyright (c) 2011 Ouest Systèmes Informatiques
  10. *
  11. * Licensed under the General Public License version 2 or later.
  12. */
  13. /**
  14. * Implements hook_requirements().
  15. */
  16. function munin_api_requirements($phase) {
  17. $ret = array();
  18. if ($phase == 'runtime') {
  19. $count = count(module_implements('munin_api_info'));
  20. switch ($count) {
  21. case 0:
  22. $req = array(
  23. 'title' => t('Munin plugin modules'),
  24. 'value' => t('No plugin found'),
  25. 'description' => t('Munin API is enabled, but does not find any plugin, including the one built into the API.'),
  26. 'severity' => REQUIREMENT_ERROR,
  27. );
  28. break;
  29. case 1:
  30. $req = array(
  31. 'title' => t('Munin plugin modules'),
  32. 'value' => t('No Munin plugin module enabled beyond API'),
  33. 'description' => t('Munin API is enabled, but no plugin module is enabled to report to it except the one built within the API. You should either <a href="!link">enable some plugin modules</a> or <a href="!link">disable and uninstall Munin API</a>.', array(
  34. '!link' => url('admin/build/modules'),
  35. )),
  36. 'severity' => REQUIREMENT_INFO,
  37. );
  38. break;
  39. default:
  40. $req = array(
  41. 'title' => t('Munin plugin modules'),
  42. // format plural although $count >= 2 because some languages have several plural forms
  43. 'value' => format_plural($count, '1 Munin plugin enabled.',
  44. '<a href="!link">@count Munin plugins</a> enabled.', array('!link' => url('admin/reports/munin_api'))),
  45. 'severity' => REQUIREMENT_OK,
  46. );
  47. }
  48. $ret[] = $req;
  49. }
  50. elseif ($phase != 'install') {
  51. // This should never happen and points to a severe error somewhere
  52. watchdog('munin_api', 'Invalid phase %phase passed to %function', array(
  53. '%phase' => $phase,
  54. '%function' => __FUNCTION__,
  55. ), WATCHDOG_ERROR);
  56. }
  57. // else $phase == 'install', nothing to do.
  58. return $ret;
  59. }
  60. /**
  61. * Implements hook_uninstall()
  62. */
  63. function munin_api_uninstall() {
  64. $vars = array(
  65. 'init_path',
  66. 'last',
  67. 'next_report',
  68. 'watchdog',
  69. );
  70. foreach ($vars as $tail) {
  71. $name = 'munin_api_'. $tail;
  72. variable_del($name);
  73. }
  74. }