prod_check.api.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. /**
  3. * @file
  4. * Documentation for hooks defined by prod_check.
  5. */
  6. /**
  7. * hook_prod_check_alter()
  8. *
  9. * You can implement hook_prod_check_alter() in your own module to add
  10. * additional checks or modify the core checks.
  11. * The hook receives the default functions divided into 7 categories:
  12. *
  13. * - settings
  14. * - server
  15. * - performance
  16. * - security
  17. * - modules
  18. * - seo
  19. * - prod_mon
  20. * - perf_data
  21. *
  22. * 'prod_mon' & 'perf_data' are special categories that will only be used by the
  23. * accompanying Production monitor module.
  24. *
  25. * Your function that implements the actual check must accept 1 string parameter
  26. * and return an array using the prod_check_execute_check() function.
  27. *
  28. * An example implementation (note the pass by reference in the hook!):
  29. */
  30. /**
  31. * Implements hook_prod_check_alter()
  32. * @param array reference to an associative array of all available checks
  33. */
  34. function my_module_prod_check_alter(&$checks) {
  35. // Add custom check to the server category:
  36. // function_name => title
  37. // Do not use t() for the title!
  38. $checks['server']['functions']['my_module_additional_check'] = 'Additional check title';
  39. // Add custom check for Production Monitor only
  40. $checks['prod_mon']['functions']['my_module_prod_mon_check'] = 'My Production Monitor only check';
  41. // Gather performance data
  42. $checks['perf_data']['functions']['my_module_prod_check_return_data'] = 'Performance logging';
  43. // Add entirely new category.
  44. $checks['my_category'] = array(
  45. 'title' => 'Custom category',
  46. 'description' => 'Collection of checks I find important.',
  47. 'functions' => array(
  48. 'my_module_check_stuff' => 'Check stuff',
  49. 'my_module_check_more_stuff' => 'Check more stuff',
  50. ),
  51. );
  52. }
  53. /**
  54. * Custom function to check some things.
  55. * @param string the caller of the function, defaults to 'internal' but can also
  56. * be 'xmlrpc' or 'nagios'
  57. * @return array you _must_ return prod_check_execute_check($check, $caller) as
  58. * per the example below to insure a proper status array is returned.
  59. */
  60. function my_module_additional_check($caller = 'internal') {
  61. $check = array();
  62. $title = 'My modules settings';
  63. $setting1 = t('Enable debug info');
  64. $setting2 = t('Disable debug info');
  65. $path = 'admin/config/system/my-module-settings-page';
  66. if ($caller != 'internal') {
  67. $path = PRODCHECK_BASEURL . $path;
  68. }
  69. $check['my_module_additional_check'] = array(
  70. '#title' => t($title),
  71. '#state' => variable_get('my_module_debug', 1) != 1,
  72. '#severity' => ($caller == 'nagios') ? NAGIOS_STATUS_CRITICAL : PROD_CHECK_REQUIREMENT_ERROR,
  73. '#value_ok' => $setting2,
  74. '#value_nok' => $setting1,
  75. '#description_ok' => prod_check_ok_title($title, $path),
  76. '#description_nok' => t('Your !link settings are set to %setting1, they should be set to %setting2 on a producion environment!',
  77. array(
  78. '!link' => '<em>' . l(t($title), $path, array('attributes' => array('title' => t($title)))) . '</em>',
  79. '%setting1' => $setting1,
  80. '%setting2' => $setting2,
  81. )
  82. ),
  83. '#nagios_key' => 'MYCHCK',
  84. '#nagios_type' => 'state',
  85. );
  86. return prod_check_execute_check($check, $caller);
  87. }
  88. function my_module_check_stuff($caller = 'internal') {
  89. [...]
  90. return prod_check_execute_check($check, $caller);
  91. }
  92. function my_module_check_more_stuff($caller = 'internal') {
  93. [...]
  94. return prod_check_execute_check($check, $caller);
  95. }
  96. /**
  97. * Custom callback for a prod_mon only check. Note the additional parameter in
  98. * the prod_check_execute_check() call!
  99. */
  100. function my_module_prod_mon_check($caller = 'internal') {
  101. [...]
  102. return prod_check_execute_check($check, $caller, 'prod_mon');
  103. }
  104. /**
  105. * Return performance data to Production Monitor.
  106. */
  107. function my_module_prod_check_return_data() {
  108. $data = my_module_gather_summary_data();
  109. if (!$data) {
  110. return array(
  111. 'my_module' => array (
  112. 'title' => 'Performance logging',
  113. 'data' => 'No performance data found.',
  114. ),
  115. );
  116. }
  117. return array(
  118. 'my_module' => array (
  119. 'title' => 'Performance logging',
  120. 'data' => array(
  121. 'Total number of page accesses' => array($data['total_accesses']),
  122. 'Average duration per page' => array($data['ms_avg'], 'ms'),
  123. 'Average memory per page' => array($data['mb_avg'], 'MB'),
  124. 'Average querycount' => array($data['query_count']),
  125. 'Average duration per query' => array($data['ms_query'], 'ms'),
  126. ),
  127. ),
  128. );
  129. }
  130. /**
  131. * hook_prod_check_disabled_modules_whitelist()
  132. *
  133. * Check for updates for these modules even if they are disabled. Some modules
  134. * (f.e. cache backends) are included directly but don't necessarily have the
  135. * module enabled in the module list. This list can be extended by other modules
  136. * or updated with other commonly used modules that are used in such a way.
  137. */
  138. /**
  139. * Implements hook_prod_check_disabled_modules_whitelist().
  140. */
  141. function my_module_prod_check_disabled_modules_whitelist() {
  142. return array('apc', 'memcache', 'varnish');
  143. }
  144. /**
  145. * hook_prod_check_disabled_modules_whitelist_alter()
  146. *
  147. * Allow other modules to add or delete modules to force check.
  148. */
  149. /**
  150. * Implements hook_prod_check_disabled_modules_whitelist_alter().
  151. */
  152. function my_module_prod_check_disabled_modules_whitelist_alter(&$modules) {
  153. // Remove apc module from the whitelist.
  154. if ($pos = array_search('apc', $modules)) {
  155. unset($modules[$pos]);
  156. }
  157. }