forked from ganglia/ganglia-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views_view.php
284 lines (246 loc) · 9.9 KB
/
views_view.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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
include_once("./eval_conf.php");
include_once("./functions.php");
include_once("./global.php");
if (! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::VIEW, $conf))
die("You do not have access to view views.");
///////////////////////////////////////////////////////////////////////////////
// Create new view
///////////////////////////////////////////////////////////////////////////////
if (isset($_GET['create_view'])) {
if(! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
$output = "You do not have access to edit views.";
} else {
// Check whether the view name already exists
$view_exists = 0;
$available_views = get_available_views();
foreach ($available_views as $view_id => $view) {
if ($view['view_name'] == $_GET['view_name']) {
$view_exists = 1;
}
}
if ($view_exists == 1) {
$output = "<strong>Alert:</strong> View with the name " .
$_GET['view_name'] .
" already exists.";
} else {
$empty_view = array ("view_name" => $_GET['view_name'],
"items" => array());
$view_suffix = str_replace(" ", "_", $_GET['view_name']);
$view_filename = $conf['views_dir'] . "/view_" . $view_suffix . ".json";
$json = json_encode($empty_view);
if (file_put_contents($view_filename,
json_prettyprint($json)) === FALSE) {
$output = "<strong>Alert:</strong>" .
" Can't write to file $view_filename." .
" Perhaps permissions are wrong.";
} else {
$output = "View has been created successfully.";
}
}
}
?>
<div class="ui-widget">
<div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
<?php echo $output ?></p>
</div>
</div>
<?php
exit(0);
}
///////////////////////////////////////////////////////////////////////////////
// Delete view
///////////////////////////////////////////////////////////////////////////////
if (isset($_GET['delete_view'])) {
if (! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
$output = "You do not have access to edit views.";
} else {
// Check whether the view name already exists
$view_exists = 0;
$available_views = get_available_views();
foreach ($available_views as $view_id => $view) {
if ($view['view_name'] == $_GET['view_name']) {
$view_exists = 1;
}
}
if ($view_exists != 1) {
$output = "<strong>Alert:</strong> View with the name " .
$_GET['view_name'] .
" does not exist.";
} else {
$view_suffix = str_replace(" ", "_", $_GET['view_name']);
$view_filename = $conf['views_dir'] . "/view_" . $view_suffix . ".json";
if (unlink($view_filename) === FALSE) {
$output = "<strong>Alert:</strong>" .
" Can't remove file $view_filename." .
" Perhaps permissions are wrong.";
} else {
$output = "View has been successfully removed.";
}
}
}
} // delete_view
///////////////////////////////////////////////////////////////////////////////
// Add to view
///////////////////////////////////////////////////////////////////////////////
if (isset($_GET['add_to_view'])) {
if (! checkAccess(GangliaAcl::ALL_VIEWS, GangliaAcl::EDIT, $conf)) {
$output = "You do not have access to edit views.";
} else {
$view_exists = 0;
// Check whether the view name already exists
$available_views = get_available_views();
foreach ($available_views as $view_id => $view) {
if ($view['view_name'] == $_GET['view_name']) {
$view_exists = 1;
break;
}
}
if ($view_exists == 0) {
$output = "<strong>Alert:</strong> View " .
$_GET['view_name'] .
" does not exist. This should not happen.";
} else {
// Read in contents of an existing view
$view_filename = $view['file_name'];
// Delete the file_name index
unset($view['file_name']);
# Check if we are adding an aggregate graph
if (isset($_GET['aggregate'])) {
foreach ( $_GET['mreg'] as $key => $value )
$metric_regex_array[] = array("regex" => $value);
foreach ($_GET['hreg'] as $key => $value)
$host_regex_array[] = array("regex" => $value);
$item_array = array("aggregate_graph" => "true",
"metric_regex" => $metric_regex_array,
"host_regex" => $host_regex_array,
"graph_type" => stripslashes($_GET['gtype']),
"vertical_label" => stripslashes($_GET['vl']),
"title" => $_GET['title'],
"glegend" => $_GET['glegend']);
if (isset($_GET['x']) && is_numeric($_GET['x'])) {
$item_array["upper_limit"] = $_GET['x'];
}
if ( isset($_GET['n']) && is_numeric($_GET['n'])) {
$item_array["lower_limit"] = $_GET['n'];
}
if ( isset($_GET['c']) ) {
$item_array["cluster"] = $_GET['c'];
}
if ( isset($_GET['h']) ) { $item_array['host'] = $_GET['h']; unset($item_array['host_regex']); }
if ( isset($_GET['m']) ) { $item_array['metric'] = $_GET['m']; unset($item_array['metric_regex']); }
if ( isset($_GET['g']) ) { $item_array['graph'] = $_GET['g']; }
if ($item_array['host_regex'] == null) $item_array['host_regex'] = '.*';
$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"] = stripslashes($_GET['vertical_label']);
if (isset($_GET['title']))
$items["title"] = stripslashes($_GET['title']);
if (isset($_GET['c']))
$items["cluster"] = $_GET['c'];
if (isset($_GET['warning']) && is_numeric($_GET['warning']))
$items["warning"] = $_GET['warning'];
if (isset($_GET['critical']) && is_numeric($_GET['critical']))
$items["critical"] = $_GET['critical'];
$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 ) {
$output = "<strong>Alert:</strong>" .
" Can't write to file $view_filename." .
" Perhaps permissions are wrong.";
} else {
$output = "View has been updated successfully.";
}
}
}
?>
<div class="ui-widget">
<div class="ui-state-default ui-corner-all" style="padding: 0 .7em;">
<p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>
<?php echo $output ?></p>
</div>
</div>
<?php
exit(0);
}
$available_views = get_available_views();
$existing_views = '';
foreach ($available_views as $view) {
$v = $view['view_name'];
$vid = viewId($v);
$checked = ($_GET['vn'] == $v);
$existing_views .= '<input type="radio" id="' . $vid . '" onClick="selectView(\'' . $v . '\'); return false;"' . ($checked ? " checked" : "") . '><label style="text-align:left;" class="nobr" for="' . $vid . '">' . $v . '</label>';
}
if (isset($_GET['views_menu'])) {
?>
<div id="views_menu">
<?php echo $existing_views ?>
</div>
<script type="text/javascript">$(function(){$("#views_menu").buttonsetv();});</script>
<?php
exit(0);
}
$tpl = new Dwoo_Template_File( template("views_view.tpl") );
$data = new Dwoo_Data();
$data->assign("range",$range);
// Pop up a warning message if there are no available views
// (Disable temporarily, otherwise we can't create views)
if (sizeof($available_views) == -1) {
$error_msg = '
<div class="ui-widget">
<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;">
<p><span class="ui-icon ui-icon-alert"
style="float: left; margin-right: .3em;"></span>
<strong>Alert:</strong> There are no views defined.</p>
</div>
</div>';
}
$size = isset($clustergraphsize) ? $clustergraphsize : 'default';
//set to 'default' to preserve old behavior
$size = $size == 'medium' ? 'default' : $size;
$additional_host_img_css_classes = "";
if ( isset($conf['zoom_support']) && $conf['zoom_support'] === true )
$additional_host_img_css_classes = "host_${size}_zoomable";
$data->assign("additional_host_img_css_classes",
$additional_host_img_css_classes);
$data->assign("existing_views", $existing_views);
$data->assign("view_name", $user["viewname"]);
$view_items = NULL;
foreach ($available_views as $view_id => $view) {
if ($view['view_name'] == $user["viewname"]) {
$view_elements = get_view_graph_elements($view);
$view_items = array();
if ( count($view_elements) != 0) {
$graphargs = "";
if ($cs)
$graphargs .= "&cs=" . rawurlencode($cs);
if ($ce)
$graphargs .= "&ce=" . rawurlencode($ce);
foreach ($view_elements as $id => $element) {
$view_items[] = array ("legend" => isset($element['hostname']) ? $element['hostname'] : "Aggregate graph",
"url_args" => htmlentities($element['graph_args']) . "&r=" . $range . $graphargs,
"aggregate_graph" => isset($element['aggregate_graph']) ? 1 : 0
);
}
}
$data->assign("number_of_view_items", sizeof($view_items));
break;
} // end of if ( $view['view_name'] == $view_name
} // end of foreach ( $views as $view_id
if (isset($view_items))
$data->assign("view_items", $view_items);
$data->assign('GRAPH_BASE_ID', $GRAPH_BASE_ID);
$data->assign('SHOW_EVENTS_BASE_ID', $SHOW_EVENTS_BASE_ID);
$dwoo->output($tpl, $data);
?>