| 
					
				 | 
			
			
				@@ -16,6 +16,19 @@ define('MUNIN_API_DERIVE',   'DERIVE'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 define('MUNIN_API_GAUGE',    'GAUGE'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 define('MUNIN_API_ABSOLUTE', 'ABSOLUTE'); // Counters reset upon reading (uncommon) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_AREA',		'AREA'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_LINE0',  'LINE0'); // Invisible line, but triggers graphs scaling 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_LINE1',  'LINE1'); // Default on Munin 2.0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_LINE2',  'LINE2'); // Default on Munine < 2.0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_LINE3',	'LINE3'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+define('MUNIN_API_DRAW_STACK',  'STACK'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// Styles below are only supported on Munin >= 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. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -84,54 +97,60 @@ function munin_api_menu() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     '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), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  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/'. $name] = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      'type' => MENU_LOCAL_TASK, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      'title' => $module['#title'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      'description' => $module['#description'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      'page callback' => 'munin_api_page_report_instance', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      'page arguments' => array(3), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $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) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $module_info = module_invoke($module, 'munin_api_info'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  if (!is_array($module_info) || count($module_info) != 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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 = reset($module_info); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  $info = $module_info[$graph_name]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $config = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     'graph_title'    => $info['#title'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    // 'graph_vlabel' => '', 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     '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) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -149,8 +168,8 @@ function munin_api_page_config($module) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * Page callback for munin data fetches. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function munin_api_page_fetch($module) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $data = module_invoke($module, 'munin_api_fetch'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -169,22 +188,38 @@ function munin_api_page_fetch($module) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @return string 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function munin_api_page_report_global() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $items = module_invoke_all('munin_api_info'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $header = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     t('Module'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    t('Graph'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     t('Description'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     t('Fields'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $rows = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  foreach ($items as $name => $item) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    $link_title = $item['#label'] ? $item['#label'] : $name; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  foreach (module_implements('munin_api_info') as $module_name) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    $info = module_invoke($module_name, 'munin_api_info'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $rows[] = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      l($link_title, 'admin/reports/munin_api/'. $name), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      isset($item['#info']) ? $item['#info'] : t('<missing>'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      count(element_children($item)), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      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; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -194,30 +229,39 @@ function munin_api_page_report_global() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  * @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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+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('Description'), t('Type')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  $header = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    t('Name'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    t('Title / Description'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    t('Type'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    array('data' => t('Debug'), 'colspan' => 2), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   $rows = array(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  foreach (element_children($module_info) as $name) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+  foreach (element_children($module_info) as $graph_name) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     $rows[] = array( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      $name, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      isset($module_info[$name]['#label']) ? $module_info[$name]['#label'] : t('<missing>'), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-      $module_info[$name]['#type'], 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+      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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-  $ret .= '<h3>Munin debug (text-only)</h3><p>' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    . l(t('Fetch data'), 'munin_api/'. $module) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    . ' ' 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    . l(t('Fetch config'), 'munin_api/'. $module .'/config'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   return $ret; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 |