Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

automatically add specific reports to cluster_view and host_view #191

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion cluster_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,9 +401,28 @@ function get_cluster_optional_reports($conf,
json_decode(file_get_contents($cluster_file), TRUE));
}

// Here we are looking for reports like cluster_<name>.*_report.json

if ($handle = opendir($conf['gweb_root'] . '/graph.d/')) {
$fs_reports = array();
// If we are using RRDtool reports can be json or PHP suffixes
if ( $conf['graph_engine'] == "rrdtool" )
$report_suffix = "php|json";
else
$report_suffix = "json";

while (false !== ($file = readdir($handle))) {
if ( preg_match("/(cluster_" . $clustername . ".*)(_report)\.(" . $report_suffix .")/", $file, $out) ) {
$fs_reports["$out[1]"] = $out[1] . "_report";
}
}

closedir($handle);
}

# Merge arrays
$reports["included_reports"] =
array_merge($default_reports["included_reports"],$override_reports["included_reports"]);
array_merge($default_reports["included_reports"],$override_reports["included_reports"],$fs_reports);
$reports["excluded_reports"] =
array_merge($default_reports["excluded_reports"],$override_reports["excluded_reports"]);

Expand Down
6 changes: 6 additions & 0 deletions conf_default.php.in
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ $conf['strip_domainname'] = false;
#
$conf['cluster_hide_down_hosts'] = false;

#
# hide special metrics from drop-down list in cluster view,
# all metrics matching the regular expression are hidden
#
$conf['cluster_hide_metrics_from_menu'] = '^(cluster|host)_.*_report';

#
# Optional summary graphs
# This function is deprecated. Please configure included reports
Expand Down
6 changes: 4 additions & 2 deletions edit_optional_graphs.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ function create_radio_button($variable_name, $variable_value = "ignored") {

while (false !== ($file = readdir($handle))) {
if ( preg_match("/(.*)(_report)\.(" . $report_suffix .")/", $file, $out) ) {
if ( ! in_array($out[1] . "_report", $available_reports) )
$available_reports[] = $out[1] . "_report";
if ( ! preg_match("/((cluster|host)_.*)(_report)/", $file) ) {
if ( ! in_array($out[1] . "_report", $available_reports) )
$available_reports[] = $out[1] . "_report";
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,9 @@ function make_node_menu($self,
if (count($metrics)) {
foreach ($metrics as $firsthost => $bar) {
foreach ($metrics[$firsthost] as $m => $foo)
$context_metrics[$m] = $m;
if ( ! preg_match("/" . $conf['cluster_hide_metrics_from_menu'] . "/", $m) ) {
$context_metrics[$m] = $m;
}
}
foreach ($reports as $r => $foo)
$context_metrics[] = $r;
Expand Down Expand Up @@ -423,8 +425,10 @@ function make_node_menu($self,

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";
if ( ! preg_match("/" . $conf['cluster_hide_metrics_from_menu'] . "/", $file) ) {
if ( ! in_array($out[1] . "_report", $context_metrics) )
$context_metrics[] = $out[1] . "_report";
}
}
}

Expand Down
23 changes: 22 additions & 1 deletion host_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,32 @@ function getOptionalReports($hostname,
}
}

// Here we are looking for reports like host_<name>.*_report.json

if ($handle = opendir($conf['gweb_root'] . '/graph.d/')) {
$fs_reports = array();
// If we are using RRDtool reports can be json or PHP suffixes
if ( $conf['graph_engine'] == "rrdtool" )
$report_suffix = "php|json";
else
$report_suffix = "json";

while (false !== ($file = readdir($handle))) {
if ( preg_match("/(host_" . $hostname . ".*)(_report)\.(" . $report_suffix .")/", $file, $out) ) {
$fs_reports["$out[1]"] = $out[1] . "_report";
}
}

closedir($handle);
}


// Merge arrays
$reports["included_reports"] = array_merge(
$default_reports["included_reports"],
$cluster_override_reports["included_reports"],
$override_reports["included_reports"]);
$override_reports["included_reports"],
$fs_reports);

$reports["excluded_reports"] = array_merge(
$default_reports["excluded_reports"] ,
Expand Down