This repository has been archived by the owner on Jul 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
host.php
266 lines (184 loc) · 9.28 KB
/
host.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
<?php
/*********************************************************************
iciwebface
Страница детальной информации о хосте
Павел Сатин <[email protected]>
19.01.2016
**********************************************************************/
require_once( "config.php" );
if (!empty($_GET['host'])) {
$host = trim($_GET['host']);
$url_host = "https://".ICINGA2_HOST.":5665/v1/objects/hosts/".$host."/";
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url_host);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output_host = curl_exec($ch);
if (FALSE === $output_host)
throw new Exception(curl_error($ch), curl_errno($ch));
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
$url_services = "https://".ICINGA2_HOST.":5665/v1/objects/services?filter=match(%22".$host."%22,host.name)";
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url_services);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output_services = curl_exec($ch);
if (FALSE === $output_services)
throw new Exception(curl_error($ch), curl_errno($ch));
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
$url_puppet = "http://".ICINGA2_HOST."/puppet-node.php?host=".$host;
try {
$ch = curl_init();
if (FALSE === $ch)
throw new Exception('failed to initialize');
curl_setopt($ch, CURLOPT_URL, $url_puppet);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output_puppet = curl_exec($ch);
if (FALSE === $output_puppet)
throw new Exception(curl_error($ch), curl_errno($ch));
} catch(Exception $e) {
trigger_error(sprintf(
'Curl failed with error #%d: %s',
$e->getCode(), $e->getMessage()),
E_USER_ERROR);
}
$obj=json_decode($output_host);
$obj_services=json_decode($output_services);
$obj_puppet=json_decode($output_puppet);
//$graphite_name = str_replace('-', '_', str_replace('.', '_', $obj->results[0]->attrs->display_name));
}
?>
<?php include ( "header.php" ) ?>
<button id="fab_checkhost" class="fab-check-host mdl-button mdl-shadow--4dp mdl-js-ripple-effect mdl-js-button mdl-button--fab mdl-color--accent" data-upgraded=",MaterialButton,MaterialRipple" role="presentation">
<i class="material-icons mdl-color-text--white" role="presentation">refresh</i>
</button>
<section class="mdl-color--white mdl-grid">
<div class="mdl-cell mdl-cell--1-col"></div>
<div class="mdl-cell mdl-cell--10-col">
<div class="mdl-layout__header-row" style="padding: 0 0 0 0; border-bottom: 1px solid; border-color: rgba(0,0,0,0.1);">
<?php
if ($obj->results[0]->attrs->state == "0") {
echo "<table class='mdl-data-table' style='border: 0px; border-top: 0px; border-bottom: 0px'><tr><td style='border: 0px; border-top: 0px; border-bottom: 0px'>";
echo "<img src='" . $obj->results[0]->attrs->icon_image ."' />";
echo "</td><td style='border: 0px; border-top: 0px; border-bottom: 0px'>";
echo "<input readonly class='mdl-textfield__input' type='text' name='checkhost' id='checkhost' value='". $obj->results[0]->attrs->display_name . "' />";
echo "<small><div id='show-data-host' /></small></td></tr></table>";
} else {
if (strpos($obj->results[0]->attrs->icon_image, "_gray.png")) {
$img_gray = $obj->results[0]->attrs->icon_image;
} else {
$img_gray = substr($obj->results[0]->attrs->icon_image,0,-4) . "_gray.png";
}
echo "<table class='mdl-data-table' style='border: 0px; border-top: 0px; border-bottom: 0px'><tr><td style='border: 0px; border-top: 0px; border-bottom: 0px'>";
echo "<img src='" . $img_gray ."' />";
echo "</td><td style='border: 0px; border-top: 0px; border-bottom: 0px'>";
//echo "<span class='mdl-badge mdl-badge--overlap' data-badge='!'></span>";
echo "<input readonly class='mdl-textfield__input' type='text' name='checkhost' id='checkhost' value='". $obj->results[0]->attrs->display_name . "' />";
echo "<small><div id='show-data-host' /></small></td></tr></table>";
}
?>
</div>
<br />
<?php
echo "<h4>Характеристики:</h4>";
echo "<table class='mdl-data-table mdl-js-data-table' style='margin: auto; width: 100%'>";
echo "<td class='mdl-data-table__cell--non-numeric'>";
echo "Операционная система: ";
echo "</td><td class='mdl-data-table__cell--non-numeric' style='word-wrap: break-word'><small>";
echo $obj_puppet->parameters->osfamily . " " . $obj_puppet->parameters->operatingsystemmajrelease ;
echo "</small></td></tr>";
echo "<td class='mdl-data-table__cell--non-numeric'>";
echo "Процессор: ";
echo "</td><td class='mdl-data-table__cell--non-numeric' style='word-wrap: break-word'><small>";
echo $obj_puppet->parameters->processor0;
echo "</small></td></tr>";
echo "</table>";
echo "<h4>Сервисы:</h4>";
echo "<table class='mdl-data-table mdl-js-data-table' style='width: 100%; white-space: normal;'>";
foreach ($obj_services->results as $hservice) {
if ($hservice->attrs->state == "0") {
//OK
echo "<tr style='background-color: gray;'><td class='mdl-data-table__cell--non-numeric' colspan='2'>";
echo $hservice->attrs->name;
echo "</td></tr>";
} elseif ($hservice->attrs->state == "1") {
//WARNING
echo "<tr style='background-color: #FCF38D;'><td class='mdl-data-table__cell--non-numeric' colspan='2'>";
echo "<span class='mdl-badge mdl-badge--overlap' data-badge='!'></span>";
echo $hservice->attrs->name;
echo "</td></tr>";
} elseif ($hservice->attrs->state == "2") {
//CRITICAL
echo "<tr style='background-color: #FC8D8D;'><td class='mdl-data-table__cell--non-numeric' colspan='2'>";
echo "<span class='mdl-badge mdl-badge--overlap' data-badge='!'></span>";
echo $hservice->attrs->name;
echo "</td></tr>";
} elseif ($hservice->attrs->state == "3") {
//UNKNOWN
echo "<tr style='background-color: #D5BADE;'><td class='mdl-data-table__cell--non-numeric' colspan='2'>";
echo "<span class='mdl-badge mdl-badge--overlap' data-badge='!'></span>";
echo $hservice->attrs->name;
echo "</td></tr>";
} else {
echo "<tr style='background-color: gray;'><td class='mdl-data-table__cell--non-numeric' colspan='2'>";
echo $hservice->attrs->name;
echo "</td></tr>";
}
echo "<tr><td class='mdl-data-table__cell--non-numeric'>";
//echo $hservice->attrs->state;
echo "</td><td class='mdl-data-table__cell--non-numeric' style='word-wrap: break-word'><small>";
echo $hservice->attrs->last_check_result->output;
echo "</small></td></tr>";
}
echo "</table>";
/*
echo "<div class='mdl-grid'>";
foreach ($obj_services->results as $hservice) {
echo "<div class='mdl-card mdl-shadow--2dp mdl-cell mdl-cell--8-col-tablet mdl-cell--4-col-phone mdl-cell--6-col-desktop'>";
echo " <div class='mdl-card__title'>";
if ($hservice->attrs->state == "0") {
echo $hservice->attrs->name;
} else {
echo "<span class='mdl-badge mdl-badge--overlap' data-badge='!'></span>";
echo $hservice->attrs->name;
}
echo " </div>";
echo " <div class='mdl-card__media'>";
echo " </div>";
echo " <div class='mdl-card__supporting-text'>";
echo $hservice->attrs->last_check_result->output;
echo " </div>";
echo " <div class='mdl-card__actions'>";
echo " </div>";
echo "</div>";
//echo "<td class='mdl-data-table__cell--non-numeric'>";
//echo $hservice->attrs->state;
}
echo "</div>";
*/
?>
</div>
</section>
<?php include ( "footer.php" ) ?>