forked from nconf/nconf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dependency.php
343 lines (264 loc) · 10.7 KB
/
dependency.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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<?php
###
# call all the functions, make the dependency view
###
function generate_tree ($id, $mode = ''){
# selected item
# get childs
$child_array = get_childs($id, $mode);
# get information of selected item
$query = 'SELECT DISTINCT attr_value as name,ItemLinks.fk_id_item AS item_id,
(SELECT config_class FROM ConfigItems,ConfigClasses
WHERE id_class=fk_id_class AND id_item=item_id) AS type,
(SELECT attr_value
FROM ConfigValues, ItemLinks, ConfigAttrs, ConfigClasses
WHERE ConfigValues.fk_id_item = ItemLinks.fk_item_linked2
AND id_attr = ConfigValues.fk_id_attr
AND attr_name = "icon_image"
AND id_class = fk_id_class
AND config_class = "os"
AND ItemLinks.fk_id_item = item_id
) AS os_icon
FROM ConfigValues,ItemLinks,ConfigAttrs,ConfigClasses
WHERE ItemLinks.fk_id_item=ConfigValues.fk_id_item
AND id_attr=ItemLinks.fk_id_attr
AND ConfigAttrs.visible="yes"
AND fk_id_class=id_class
AND (SELECT naming_attr FROM ConfigAttrs WHERE id_attr=ConfigValues.fk_id_attr)="yes"
AND ItemLinks.fk_id_item="'.$id.'"
ORDER BY config_class DESC,attr_value';
$selected_item_info = db_handler($query, "assoc", "Get informations on selected item");
# get informations about host
# prepend inforomation from selected host to the top of the list
array_unshift($child_array, get_informations($id) );
# set values of selected item AND put all childs (generated bevore) in it.
$root_item = array( $id => array(
"id" => $id,
"selected" => TRUE,
"status" => 'open',
"name" => $selected_item_info["name"],
"type" => $selected_item_info["type"],
"os_icon" => $selected_item_info["os_icon"],
"childs" => $child_array) );
# get parents
$parents_flat = get_parents($id);
# make the parents array ordered top2down
$parents_flat = array_reverse($parents_flat);
# prepare list (if there are parents call the prepare function
if (!empty($parents_flat) ){
$tree = prepare_dependency($parents_flat, $root_item);
}else{
$tree = $root_item;
}
## Display the top tree item
# check for parent loop error
if (isset($tree[0]["status"]) AND $tree[0]["status"] == "loop_error"){
# make a error item at the top
$dependency_tree = array( "root" => array(
"id" => "root",
"status" => 'open',
"name" => TXT_DEPVIEW_ERROR_LOOP,
"type" => "warn",
"childs" => $tree) );
}else{
# make a root tree at the top
$dependency_tree = array( "root" => array(
"id" => "root",
"status" => 'open',
"name" => "Top level",
"type" => "parent",
"childs" => $tree) );
}
//echo "<pre>";
//var_dump($tree);
//echo "</pre>";
echo '<div>';
displayTree_list($dependency_tree);
echo '</div>';
}
###
# get vars
###
# get xmode ( for nagios view)
if ( isset($_GET["xmode"]) ) {
$xmode = $_GET["xmode"];
}else{
$xmode = '';
}
# ID of selected item
if ( isset($_GET["id"]) ) {
$id = $_GET["id"];
}elseif ( isset($_POST["id"]) ) {
$id = $_POST["id"];
}
# set class
$class = "host";
###
# VIEW
###
if ($xmode == "nagiosview"){
# View for nagios (just the tree)
require_once 'main.php';
# Lookup ID of hostname
if ( empty($id) AND !empty($_GET["hostname"]) ){
$id = db_templates("get_id_from_hostname", $_GET["hostname"]);
}
if ( defined('TEMPLATE_DIR') ){
# ownstyle and new.css will be removed in a future release
echo '<link rel="stylesheet" type="text/css" href="design_templates/'.TEMPLATE_DIR.'/new.css">';
# This is the main CSS and will be the only on in later releases
echo '<link rel="stylesheet" type="text/css" href="design_templates/'.TEMPLATE_DIR.'/main.css">';
echo '<link rel="shortcut icon" href="design_templates/'.TEMPLATE_DIR.'/favicon.ico">';
}
# overwrite CSS
echo '
<style type="text/css">
<!--
/* ... styles are defined here ... */
body {
background-image: none !important;
}
-->
</style>
';
echo '
<!-- Load nconf js functions -->
<script src="include/js/nconf.js" type="text/javascript"></script>
';
echo '<link rel="stylesheet" type="text/css" href="design_templates/'.TEMPLATE_DIR.'/main.css">';
echo '<div style="text-align: left; margin: 10px; margin-right: auto;">';
###
# Content of nagiosview
###
echo '<div class="dependency_info color_list2">';
echo '<h2 class="color_list3">Show host parent / child relationships</h2>';
echo VERSION_STRING.' <a target="_new" href="http://www.nconf.org">www.nconf.org</a>';
echo '</div>';
$hostname = db_templates("get_value", $id, "host_name");
echo '<div style="margin-top:20px; margin-bottom:20px;"><h2>parent / child relationships for host \''.$hostname.'\'</h2></div>';
# Show the tree
if (!empty($id)){
generate_tree($id, $xmode);
}
echo '</div>';
}else{
# Normal NConf view
require_once 'include/head.php';
// Form action and url handling
$request_url = set_page();
/*
# Get config classes
#$query = 'SELECT config_class FROM ConfigClasses ORDER BY config_class';
#$classes = db_handler($query, "array", "Get classes");
//$classes = array("host", "services");
$classes = array("host");
if (!isset($classes)){
$classes = array();
message('ERROR', "You didn't select a class");
}else{
# Class
if ( !empty($_GET["class"]) ) {
$class = $_GET["class"];
}elseif ( !empty($_POST["class"]) ) {
$class = $_POST["class"];
}else{
$class = $classes[0];
}
}
*/
###
# Info/Warning in the top right corner
###
echo '<h2 style="margin-right:4px">Show host parent / child relationships</h2>';
echo '
<div class="editor_info">';
$content = 'This view allows you to graphically browse your host\'s parent / child relationships.';
echo NConf_HTML::show_highlight('Info', $content);
echo '</div>';
echo '<form name="editor" action="dependency.php" method="post">
<fieldset class="inline ui-widget-content">
<legend>choose a host</legend>
<table>';
###
# List class and items
###
/*
echo '<tr>';
echo '<td>Class</td>';
echo '</tr>';
echo '<tr><td><select name="class" style="width:192px" onchange="document.editor.id.value=\'\'; document.editor.submit()">';
//echo '<option value="">'.SELECT_EMPTY_FIELD.'</option>';
foreach($classes as $class_item){
echo '<option value='.$class_item;
if ( (!empty($class) ) AND ($class == $class_item) ) echo " SELECTED";
echo '>'.$class_item.'</option>';
}
echo '</select> </td>';
echo '</tr>';
*/
if ( !empty($class) ){
echo '<tr>';
//echo '<td>'.$class.'</td>';
//echo '<td>Host</td>';
echo '</tr>';
if ($class == "host"){
$query = 'SELECT fk_id_item AS ID,
attr_value AS hostname
FROM ConfigValues,ConfigAttrs,ConfigClasses
WHERE id_attr=fk_id_attr AND naming_attr="yes"
AND id_class=fk_id_class
AND config_class="'.$class.'"
ORDER BY hostname';
}else{
$query = 'SELECT id_item AS ID,
attr_value AS entryname,
(SELECT attr_value FROM ConfigValues,ConfigAttrs,ConfigClasses,ItemLinks
WHERE fk_item_linked2=ConfigValues.fk_id_item
AND id_attr=ConfigValues.fk_id_attr
AND naming_attr="yes"
AND fk_id_class = id_class
AND config_class="host"
AND ItemLinks.fk_id_item=id_item) AS hostname
FROM ConfigItems,ConfigValues,ConfigAttrs,ConfigClasses
WHERE id_item=fk_id_item
AND id_attr=fk_id_attr
AND naming_attr="yes"
AND ConfigItems.fk_id_class=id_class
AND config_class="'.$class.'"
ORDER BY hostname,entryname';
}
$items = db_handler($query, "array", "Get items of the class $class");
echo '<tr>';
echo '<td><select name="id" style="width:192px" onchange="document.editor.submit()">';
//echo '<option value="">'.SELECT_EMPTY_FIELD.'</option>';
echo '<option value="">choose a host...</option>';
foreach($items as $item_array){
# set variables
$item_id = $item_array["ID"];
$item_name = "";
if (isset($item_array["hostname"])){
$item_name .= $item_array["hostname"];
if (isset($item_array["entryname"]) ) $item_name .= ":";
}
if (isset($item_array["entryname"]) ) $item_name .= $item_array["entryname"];
echo "<option value=$item_id";
if ( (isset($id) ) AND ($id == $item_id) ){
echo " SELECTED";
# set the name of the selected item
$main_item_name = $item_name;
}
echo ">$item_name</option>";
}
echo '</select> </td>';
echo '</tr>';
}
echo '</table></fieldset>';
echo '</form><br>';
# Show the tree
if (!empty($id)){
generate_tree($id);
}
mysql_close($dbh);
require_once 'include/foot.php';
}
?>