<?php ///////////////////////////////////////////////////////////////////////////// // This API allows you to get cluster name for a hostname // // Currently only query supported is // // hostname=YOURHOSTNAME&search_type=exact // // will give you back the an array of cluster names where host is in ///////////////////////////////////////////////////////////////////////////// $conf['gweb_root'] = dirname(dirname(__FILE__)); include_once $conf['gweb_root'] . "/eval_conf.php"; include_once $conf['gweb_root'] . "/lib/common_api.php"; include_once $conf['gweb_root'] . "/functions.php"; ganglia_cache_metrics(); if (isset($_GET['hostname']) and isset($_GET['search_type']) and $_GET['search_type'] == "exact") { $hostname = $_GET['hostname']; if (isset($index_array['cluster'][$hostname])) { api_return_ok($index_array['cluster'][$hostname]); } else { api_return_error("Cluster not found"); } } else { api_return_error("No valid search provided"); }
if ($conf['graph_engine'] == "rrdtool") { $report_suffix = "php|json"; } else { $report_suffix = "json"; } while (false !== ($file = readdir($handle))) { if (preg_match("/(.*)(_report)\\.(" . $report_suffix . ")/", $file, $out)) { if (!in_array($out[1] . "_report", $context_metrics)) { $context_metrics[] = $out[1] . "_report"; } } } closedir($handle); } sort($context_metrics); $c = 0; foreach ($context_metrics as $key) { $url = rawurlencode($key); if (stripos($key, $term) !== false) { if ($c > 30) { break; } $picker_metrics[] = array('value' => $url, 'label' => $key, 'id' => $key); $c++; } } } api_return_ok($picker_metrics); } else { api_return_error("No valid search provided"); }
} $view['items'][] = $item_array; unset($item_array); } else { if ($_GET['type'] == "metric") { $items = array("hostname" => $_GET['host_name'], "metric" => $_GET['metric_name']); if (isset($_GET['vertical_label'])) { $items["vertical_label"] = $_GET['vertical_label']; } if (isset($_GET['title'])) { $items["title"] = $_GET['title']; } $view['items'][] = $items; } else { $view['items'][] = array("hostname" => $_GET['host_name'], "graph" => $_GET['metric_name']); } } $json = json_encode($view); if (file_put_contents($view_filename, json_prettyprint($json)) === FALSE) { api_return_error("Can't write to file {$view_filename}. Perhaps permissions are wrong."); } else { api_return_ok("View has been updated successfully."); } // end of if ( file_put_contents($view_filename, $json) === FALSE ) } // end of if ( $view_exists == 1 ) } break; // end add_to_view } // end case action
} file_put_contents($conf['nagios_cache_file'], serialize($new_metrics)); unset($metrics); $metrics = $new_metrics; unset($new_metrics); } # Get a list of all hosts $ganglia_hosts_array = array_keys($metrics); $host_found = 0; # Find a FQDN of a supplied server name. for ($i = 0; $i < count($ganglia_hosts_array); $i++) { if (!strcasecmp($ganglia_hosts_array[$i], $host)) { $fqdn = $ganglia_hosts_array[$i]; $host_found = 1; break; } } # Host has been found in the Ganglia tree if ($host_found == 1) { # Check for the existence of a metric if (isset($metrics[$fqdn][$metric_name]['VAL'])) { $metric_value = $metrics[$fqdn][$metric_name]['VAL']; } else { api_return_error($metric_name . " - Invalid metric request for this host. Please check metric exists."); exit(3); } $ganglia_units = $metrics[$fqdn][$metric_name]['UNITS']; api_return_ok(array('metric_value' => $metric_value, 'units' => $ganglia_units)); } else { api_return_error($metric_name . " - Hostname info not available. Likely invalid hostname"); }
if (isset($v['TITLE'])) { $graph_arguments['ti'] = $metrics[$cluster_url]['TITLE']; } $graph['description'] = isset($metrics[$cluster_url]['DESC']) ? $metrics[$cluster_url]['DESC'] : ''; $graph['title'] = isset($metrics[$cluster_url]['TITLE']) ? $metrics[$cluster_url]['TITLE'] : $rrd; # Setup an array of groups that can be used for sorting in group view if (isset($metrics[$name]['GROUP'])) { $groups = $metrics[$name]['GROUP']; } else { $groups = array(""); } $graph['graph_image'] = array('script' => 'graph.php', 'params' => $graph_arguments); $graph['graph_url'] = form_image_url('graph.php', $graph_arguments); $r['graph'][] = $graph; } // end foreach metrics if ($debug) { print "<pre>"; print_r($r); die("</pre>"); } api_return_ok($r); break; // end get // end get default: api_return_error("Invalid action."); break; // bad action } // end case action