= 1.3.3 define('MUNIN_API_DRAW_LINESTACK1', 'LINESTACK1'); define('MUNIN_API_DRAW_LINESTACK2', 'LINESTACK2'); define('MUNIN_API_DRAW_LINESTACK3', 'LINESTACK3'); define('MUNIN_API_DRAW_AREASTACK', 'AREASTACK'); /** * Finalize result pages for Munin interactions. * * - text content, not HTML * - non cacheable, even for anonymous users */ function _munin_api_page_closure($ret) { drupal_set_header('Content-type: text/plain'); $GLOBALS['conf']['cache'] = CACHE_DISABLED; // prevent page_set_cache() in drupal_page_footer(). print $ret; drupal_page_footer(); exit(); } /** * Display and log an incorrect hook implementation. * * @param string $hook * @param string $module * * @return string */ function _munin_report_hook_error($hook, $module) { $message = t('Incorrect implementation of hook_!hook() in module @module.'); $params = array( '!hook' => $hook, '@module' => $module, ); drupal_set_message(strtr($message, $params), 'error'); watchdog('munin_api', $message, $params, WATCHDOG_ERROR); return '

'. l(t('Back'), 'admin/reports/munin_api/'. $module) .'

'; } /** * Menu access callback for Munin config fetches. * * TODO: define rules, then code */ function munin_api_access_config($module) { return TRUE; // For now, protect at the web server level } /** * Menu access callback for Munin data fetches. * * TODO: define rules, then code */ function munin_api_access_fetch($module) { return TRUE; // For now, protect at the web server level } function munin_api_menu() { $items = array(); $items['admin/reports/munin_api'] = array( 'title' => 'Munin', 'description' => 'Reports about Munin data collectors and their probes', 'page callback' => 'munin_api_page_report_global', 'access arguments' => array('access site reports'), ); $items['admin/reports/munin_api/list'] = array( 'type' => MENU_DEFAULT_LOCAL_TASK, 'title' => 'General', 'weight' => -1, ); foreach (module_implements('munin_api_info') as $module_name) { $module = module_invoke($module_name, 'munin_api_info'); $graphs = element_children($module); $items['admin/reports/munin_api/'. $module_name] = array( 'type' => MENU_LOCAL_TASK, 'title' => $module['#title'], 'description' => $module['#description'], 'page callback' => 'munin_api_page_report_instance', 'page arguments' => array($module_name, $module), 'access arguments' => array('access site reports'), ); foreach ($graphs as $graph_name) { $items['munin_api/'. $graph_name] = array( 'type' => MENU_CALLBACK, 'page callback' => 'munin_api_page_fetch', 'page arguments' => array($module_name, $module, $graph_name), 'access callback' => 'munin_api_access_fetch', 'access arguments' => array($module_name, $graph_name), ); $items['munin_api/'. $graph_name .'/config'] = array( 'type' => MENU_CALLBACK, 'page callback' => 'munin_api_page_config', 'page arguments' => array($module_name, $graph_name), 'access callback' => 'munin_api_access_config', 'access arguments' => array($module_name, $graph_name), ); } } ksort($items); return $items; } /** * Page callback for munin config fetches. */ function munin_api_page_config($module_name, $graph_name) { $module_info = module_invoke($module_name, 'munin_api_info'); if (!is_array($module_info)) { return _munin_report_hook_error('munin_api_info', $module); } $info = $module_info[$graph_name]; $config = array( 'graph_title' => $info['#title'], 'graph_info' => $info['#info'], 'graph_category' => 'Drupal', ); foreach (element_properties($info) as $property_name) { if (!in_array($property_name, array('#title', '#info'))) { $config[drupal_substr($property_name, 1)] = $info[$property_name]; } } foreach (element_children($info) as $field_name) { foreach (element_properties($info[$field_name]) as $property_name) { $config[$field_name .'.'. drupal_substr($property_name, 1)] = $info[$field_name][$property_name]; } } $ret = ''; foreach ($config as $k => $v) { $ret .= $k .' '. $v . PHP_EOL; } _munin_api_page_closure($ret); } /** * Page callback for munin data fetches. */ function munin_api_page_fetch($module_name, $module, $graph_name) { $data = module_invoke($module_name, 'munin_api_fetch', $graph_name); if (!is_array($data)) { return _munin_report_hook_error('munin_api_fetch', $module); } $ret = ''; foreach ($data as $field => $value) { $ret .= $field .'.value '. $value . PHP_EOL; } _munin_api_page_closure($ret); } /** * Page callback for Munin global report. * * @return string */ function munin_api_page_report_global() { $header = array( t('Module'), t('Graph'), t('Description'), t('Fields'), ); $rows = array(); foreach (module_implements('munin_api_info') as $module_name) { $info = module_invoke($module_name, 'munin_api_info'); $rows[] = array( array( 'data' => l($info['#title'], 'admin/reports/munin_api/'. $module_name), 'colspan' => 2, ), array( 'colspan' => 2, 'data' => $info['#description'], ), ); foreach (element_children($info) as $name) { $title = $info[$name]['#title'] ? $info[$name]['#title'] : $name; $rows[] = array( ' ', $title, isset($info[$name]['#info']) ? $info[$name]['#info'] : t('<missing>'), count(element_children($info[$name])), ); } } $ret = theme('table', $header, $rows); return $ret; } /** * Page callback for Munin instance report. * * @return string */ function munin_api_page_report_instance($module_name, $module_info) { if (!is_array($module_info)) { return _munin_report_hook_error('munin_api_info', $module); } $header = array( t('Name'), t('Title / Description'), t('Type'), array('data' => t('Debug'), 'colspan' => 2), ); $rows = array(); foreach (element_children($module_info) as $graph_name) { $rows[] = array( array( 'data' => $module_info[$graph_name]['#title'] ? $module_info[$graph_name]['#title'] : $graph_name, 'colspan' => 3, ), l(t('config'), 'munin_api/'. $graph_name .'/config'), l(t('data'), 'munin_api/'. $graph_name), ); foreach (element_children($module_info[$graph_name]) as $field_name) { $rows[] = array( ' ', isset($module_info[$graph_name][$field_name]['#label']) ? $module_info[$graph_name][$field_name]['#label'] : t('<missing>'), $module_info[$graph_name][$field_name]['#type'], ' ', ' ', ); } } $ret = theme('table', $header, $rows); return $ret; }