$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 $name) { $module = module_invoke($name, 'munin_api_info'); $module = $module[$name]; $items['munin_api/'. $name] = array( 'type' => MENU_CALLBACK, 'page callback' => 'munin_api_page_fetch', 'page arguments' => array(1), 'access callback' => 'munin_api_access_fetch', 'access arguments' => array($name), ); $items['munin_api/'. $name .'/config'] = array( 'type' => MENU_CALLBACK, 'page callback' => 'munin_api_page_config', 'page arguments' => array(1), 'access callback' => 'munin_api_access_config', 'access arguments' => array($name), ); $items['admin/reports/munin_api/'. $name] = array( 'type' => MENU_LOCAL_TASK, 'title' => $module['#title'], 'description' => $module['#description'], 'page callback' => 'munin_api_page_report_instance', 'page arguments' => array(3), 'access arguments' => array('access site reports'), ); } return $items; } /** * Page callback for munin config fetches. */ function munin_api_page_config($module) { $data = module_invoke($module, 'munin_api_config'); if (!is_array($data)) { return _munin_report_hook_error('munin_api_config', $module); } $ret = ''; foreach ($data as $attribute => $value) { $ret .= $attribute .' = '. $value . PHP_EOL; } _munin_api_page_closure($ret); } /** * Page callback for munin data fetches. */ function munin_api_page_fetch($module) { $data = module_invoke($module, 'munin_api_fetch'); if (!is_array($data)) { return _munin_report_hook_error('munin_api_fetch', $module); } $ret = ''; foreach ($data as $field => $value) { $ret .= $module .'.'. $field .' = '. $value . PHP_EOL; } _munin_api_page_closure($ret); } /** * Page callback for Munin global report. * * @return string */ function munin_api_page_report_global() { $items = module_invoke_all('munin_api_info'); $header = array( t('Module'), t('Description'), t('Fields'), ); $rows = array(); foreach ($items as $name => $item) { $link_title = $item['#title'] ? $item['#title'] : $name; $rows[] = array( l($link_title, 'admin/reports/munin_api/'. $name), isset($item['#description']) ? $item['#description'] : t('<missing>'), count(element_children($item)), ); } $ret = theme('table', $header, $rows); return $ret; } /** * Page callback for Munin instance report. * * @return string */ function munin_api_page_report_instance($module) { $module_info = module_invoke($module, 'munin_api_info'); if (!is_array($module_info) || count($module_info) != 1) { return _munin_report_hook_error('munin_api_info', $module); } $module_info = reset($module_info); if (!is_array($module_info)) { return _munin_report_hook_error('munin_api_info', $module); } $header = array(t('Name'), t('Description'), t('Type')); $rows = array(); foreach (element_children($module_info) as $name) { $rows[] = array( $name, isset($module_info[$name]['#title']) ? $module_info[$name]['#title'] : t('<missing>'), $module_info[$name]['#type'], ); } $ret = theme('table', $header, $rows); $ret .= '' . l(t('Fetch data'), 'munin_api/'. $module) . ' ' . l(t('Fetch config'), 'munin_api/'. $module .'/config'); return $ret; }