forked from ganglia/ganglia-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_context.php
218 lines (188 loc) · 7.52 KB
/
get_context.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
include_once "./functions.php";
$cluster_designator = "Cluster Overview";
///////////////////////////////////////////////////////////////////////////////
// Determine which context we are in. Context is not specifically specified
// so we have to figure it out ie. if vn(view_name) is present it's the views
// context, if cluster name is specified without a hostname it's cluster etc.
///////////////////////////////////////////////////////////////////////////////
// Blocking malicious CGI input.
$user['clustername'] = isset($_GET["c"]) ?
sanitize($_GET["c"]) : NULL;
$user['gridname'] = isset($_GET["G"]) ?
sanitize($_GET["G"]) : NULL;
$user['viewname'] = '';
if ( isset($_GET["vn"]) && is_proper_view_name ($_GET["vn"]) ) {
$user['viewname'] = $_GET["vn"];
}
if($conf['case_sensitive_hostnames'] == 1) {
$user['hostname'] = isset($_GET["h"]) ?
sanitize($_GET["h"]) : NULL;
} else {
$user['hostname'] = isset($_GET["h"]) ?
strtolower( sanitize($_GET["h"]) ) : NULL;
}
$user['range'] = isset( $_GET["r"] ) && in_array($_GET["r"], array_keys( $conf['time_ranges'] ) ) ?
escapeshellcmd( rawurldecode($_GET["r"])) : NULL;
$user['metricname'] = isset($_GET["m"]) ?
sanitize($_GET["m"]) : NULL;
$user['metrictitle'] = isset($_GET["ti"]) ?
sanitize($_GET["ti"]) : NULL;
$user['sort'] = isset($_GET["s"]) ?
sanitize($_GET["s"]) : NULL;
$user['controlroom'] = isset($_GET["cr"]) ?
sanitize($_GET["cr"]): NULL;
# Default value set in conf.php, Allow URL to overrride
if (isset($_GET["hc"]))
//TODO: shouldn't set $conf from user input.
$conf['hostcols'] = clean_number($_GET["hc"]);
if (isset($_GET["mc"]))
$conf['metriccols'] = clean_number($_GET["mc"]);
# Flag, whether or not to show a list of hosts
$user['showhosts'] = isset($_GET["sh"]) ?
clean_number( $_GET["sh"] ) : NULL;
# The 'p' variable specifies the verbosity level in the physical view.
$user['physical'] = isset($_GET["p"]) ?
clean_number( $_GET["p"] ) : NULL;
$user['tree'] = isset($_GET["t"]) ?
sanitize($_GET["t"] ) : NULL;
# A custom range value for job graphs, in -sec.
$user['jobrange'] = isset($_GET["jr"]) ?
clean_number( $_GET["jr"] ) : NULL;
# A red vertical line for various events. Value specifies the event time.
$user['jobstart'] = isset($_GET["js"]) ?
clean_number( $_GET["js"] ) : NULL;
# custom start and end
$user['cs'] = isset($_GET["cs"]) ?
sanitize($_GET["cs"]) : NULL;
$user['ce'] = isset($_GET["ce"]) ?
sanitize($_GET["ce"]) : NULL;
# Custom step, primarily for use in exporting the raw data from graph.php
$user['step'] = isset($_GET["step"]) ?
clean_number( $_GET["step"] ) : NULL;
# The direction we are travelling in the grid tree
$user['gridwalk'] = isset($_GET["gw"]) ?
sanitize($_GET["gw"]) : NULL;
# Size of the host graphs in the cluster view
$user['clustergraphsize'] = isset($_GET["z"]) && in_array( $_GET[ 'z' ], $conf['graph_sizes_keys'] ) ?
sanitize($_GET["z"]) : NULL;
# A stack of grid parents. Prefer a GET variable, default to cookie.
if (isset($_GET["gs"]) and $_GET["gs"])
$user['gridstack'] = explode( ">", rawurldecode( $_GET["gs"] ) );
else if ( isset($_COOKIE['gs']) and $_COOKIE['gs'])
$user['gridstack'] = explode( ">", $_COOKIE["gs"] );
if (isset($user['gridstack']) and $user['gridstack']) {
foreach( $user['gridstack'] as $key=>$value )
$user['gridstack'][ $key ] = sanitize( $value );
}
/////////////////////////////////////////////////////////////////////////////
// Used with to limit hosts shown
if ( isset($_GET['host_regex']) )
$user['host_regex'] = sanitize ($_GET['host_regex']);
if ( isset($_GET['max_graphs']) && is_numeric($_GET['max_graphs'] ) )
$user['max_graphs'] = $_GET['max_graphs'];
/////////////////////////////////////////////////////////////////////////////
$user['selected_tab'] = isset($_GET["tab"]) ? rawurldecode($_GET["tab"]) : 'm';
$user['compare_hosts'] = ($user['selected_tab'] == 'ch') ? 1 : NULL;
$user['decompose_graph'] = isset($_GET["dg"]) ? 1 : NULL;
# Assume we are the first grid visited in the tree if there is no gridwalk
# or gridstack is not well formed. Gridstack always has at least one element.
if ( !isset($user['gridstack']) or !strstr($user['gridstack'][0], "http://"))
$initgrid = TRUE;
# Default values
if (!isset($conf['hostcols']) || !is_numeric($conf['hostcols'])) $conf['hostcols'] = 4;
if (!isset($conf['metriccols']) || !is_numeric($conf['metriccols'])) $conf['metriccols'] = 2;
if (!is_numeric($user['showhosts'])) $user['showhosts'] = 1;
# Filters
if(isset($_GET["choose_filter"]))
{
$req_choose_filter = $_GET["choose_filter"];
$user['choose_filter'] = array();
foreach($req_choose_filter as $k_req => $v_req)
{
$k = sanitize ($k_req);
$v = sanitize ($v_req);
$user['choose_filter'][$k] = $v;
}
}
# Set context.
#
# WARNING WARNING WARNING WARNING. If you create another context
# e.g. views, compare_hosts please make sure you add those to
# get_ganglia.php and ganglia.php otherwise you may be making
# requests to the gmetad any time you access it which will impact
# performance read make it really slow
$context = NULL;
if(!$user['clustername'] && !$user['hostname'] && $user['controlroom']) {
$context = "control";
} else if (isset($user['tree'])) {
$context = "tree";
} else if ( $user['compare_hosts'] ) {
$context = "compare_hosts";
} else if ( $user['decompose_graph'] ) {
$context = "decompose_graph";
} else if ($user['selected_tab'] == 'v') {
$context = "views";
} else if(!$user['clustername'] and !$user['gridname'] and !$user['hostname']) {
$context = "meta";
} else if($user['gridname']) {
$context = "grid";
} else if ($user['clustername'] and !$user['hostname'] and $user['physical']) {
$context = "physical";
} else if ($user['clustername'] and !$user['hostname'] and !$user['showhosts']) {
$context = "cluster-summary";
} else if($user['clustername'] and !$user['hostname']) {
$context = "cluster";
} else if($user['clustername'] and $user['hostname'] and $user['physical']) {
$context = "node";
} else if($user['clustername'] and $user['hostname']) {
$context = "host";
}
if (!$user['range'])
$user['range'] = $conf['default_time_range'];
$end = "now";
# $conf['time_ranges'] defined in conf.php
if( $user['range'] == 'job' && isset( $user['jobrange'] ) ) {
$start = $user['jobrange'];
} else if( isset( $conf['time_ranges'][ $user['range'] ] ) ) {
$start = $conf['time_ranges'][ $user['range'] ] * -1 . "s";
} else {
$start = $conf['time_ranges'][ $conf['default_time_range'] ] * -1 . "s";
}
if ($user['cs'] or $user['ce'])
$user['range'] = "custom";
if (!$user['metricname'])
$user['metricname'] = $conf['default_metric'];
if (!$user['sort'])
$user['sort'] = "by name";
# Since cluster context do not have the option to sort "by hosts down" or
# "by hosts up", therefore change sort order to "descending" if previous
# sort order is either "by hosts down" or "by hosts up"
if ($context == "cluster") {
if ($user['sort'] == "by hosts up" || $user['sort'] == "by hosts down") {
$user['sort'] = "descending";
}
}
// TODO: temporary step until all scripts expect $user.
extract( $user );
# A hack for pre-2.5.0 ganglia data sources.
$always_constant = array(
"swap_total" => 1,
"cpu_speed" => 1,
"swap_total" => 1
);
$always_timestamp = array(
"gmond_started" => 1,
"reported" => 1,
"sys_clock" => 1,
"boottime" => 1
);
# List of report graphs
$reports = array(
"load_report" => 1,
"cpu_report" => 1,
"mem_report" => 1,
"network_report" => 1,
"packet_report" => 1
);
?>