forked from bmelim/zabdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_storage.php
187 lines (144 loc) · 6.93 KB
/
group_storage.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
<?php
foreach( $groupID as $g ) {
$dbHosts = DBselect( 'SELECT h.hostid, h.name, h.status, h.available, h.snmp_available AS sa, h.snmp_disable_until AS sd, h.flags FROM hosts h, hosts_groups hg WHERE hg.groupid = '.$g.' AND h.hostid = hg.hostid ORDER BY h.name ASC');
//get group name
$group = get_hostgroup_by_groupid($g);
$groupName = $group['name'];
echo '
<div class="col-md-12 col-sm-12">
<h3 style="color:#000 !important; margin-top: 15px; margin-bottom:15px;"> '.$groupName.'</h3>
</div>';
$md = 12;
while ($hosts = DBFetch($dbHosts)) {
//if($hosts['status'] == 0 && $hosts['flags'] == 0) {
if($hosts['available'] == 1 && $hosts['sa'] == 0 ) { $keyValue = 'vfs.fs.size'; }
else { $keyValue = 'inbytes'; }
// get all items
$disks = $api->itemGet(array(
'output' => 'extend',
'hostids' => $hosts['hostid'],
'search' => array('key_' => $keyValue)
));
// print disks ID with graph name
foreach($disks as $disk) {
if($hosts['available'] == 1 && $hosts['sa'] == 0 ) {
$searchValSize = 'total';
$searchValUsed = 'used';
$diskSize = get_item_values($disk->itemid, $searchValSize);
$diskUsed = get_item_values($disk->itemid, $searchValUsed);
}
else {
$searchValSize = 'hrStorageSizeinBytes';
$searchValUsed = 'hrStorageUsedinBytes';
$diskSize = get_item_values($disk->itemid, $searchValSize);
$diskUsed = get_item_values_storage($disk->itemid, $searchValUsed);
}
//Size
if(strchr(get_item_label($diskSize['key_']),"A:") != '') {
if($diskSize['value_max'] != 0) {
$arrSize[]= get_item_label($diskSize['key_']).",".$diskSize['value_max'];
}
}
else {
if($diskSize['value_max'] != 0 || get_item_label($diskSize['key_']) != '') {
$arrSize[]= get_item_label($diskSize['key_']).",".$diskSize['value_max'];
}
}
//Used
if(strchr(get_item_label($diskUsed['key_']),"A:") == '') {
if($diskUsed['name'] != '') {
$arrUsed[]= get_item_label($diskUsed['key_']).",".$diskUsed['value_max'];
}
}
else {
if($diskUsed['name'] != '') {
if($diskUsed['value_max'] != 0) {
$arrUsed[]= get_item_label($diskUsed['key_']).",".$diskUsed['value_max'];
}
}
}
}
sort($arrSize);
sort($arrUsed);
if($arrSize[0] != '') {
//hosts
if($hosts['sd'] <> 0) { $conn = "Offline"; $cor = "#E3573F"; } else { $conn = "Online"; $cor = "#4BAC64"; }
//$dbIP = DBSelect('SELECT DISTINCT ip FROM interface WHERE hostid ='.$hosts['hostid']);
//$IP = DBFetch($dbIP);
echo "<div class='hostdivx col-md-".$md." col-sm-".$md."' style='margin-bottom:0px;'>";
echo "<table class='tabs box table table-striped table-hover table-condensed' border='0' width='50%' style='border:1px solid #f2f2f2; '>
<thead>
<tr>
<th style='background:".$cor."; width:1%;' title='".$conn."'></th>
<th colspan='1' class='linkb' style='width:50%; font-weight:bold; text-align:left;'><a href='host_detail.php?hostid=".$hosts['hostid']."'> ".$hosts['name']." </a></th>
<th colspan='1' style='width:18%; text-align:left;'>". $labels['Used'] ."</th>
<th colspan='1' style='text-align:left;'> ". _('Total') ." </th>
<th colspan='1' style='text-align:left;'> % ". $labels['Used'] ." </th>
</tr>
</thead>
<tbody>\n";
for($i=0;$i<count($arrUsed);$i++) {
$s = explode(",",$arrSize[$i]);
$u = explode(",",$arrUsed[$i]);
if(isset($u[2])) {
$s[1] = $s[2];
$u[1] = $u[2];
}
//if( stripos($s[0] , 'Memory') != true ) {
if($s[1] != 0) {
$barra = round((100*$u[1])/$s[1],1);
}
else { $barra = 0; }
// cor barra
if($barra >= 100) { $cor = "progress-bar-danger"; $perc_cor = "#fff"; }
if($barra >= 80 and $barra <= 100) { $cor = "progress-bar-danger"; $perc_cor = "#fff"; }
if($barra >= 61 and $barra <= 79) { $cor = "progress-bar-warning"; $perc_cor = "#fff"; }
if($barra >= 26 and $barra <= 60) { $cor = " "; $perc_cor = "#fff"; }
if($barra >= 0 and $barra <= 25) { $cor = "progress-bar-success"; $perc_cor = "#000";}
if($barra < 0) { $cor = "progress-bar-danger"; $barra = 0; }
echo "<tr style='text-align:left;'>\n";
echo " <td colspan='2'>". $s[0] ."</td>\n";
echo " <td colspan='1'>". formatBytes($u[1],1) ."</td>\n";
echo " <td colspan='1'>". formatBytes($s[1],1) ."</td>\n";
echo "<td width='15%' style='padding-right:15px; '>
<div style='font-size:13px; position:absolute; vertical-align:middle; color:".$perc_cor.";'> ".$barra."%</div>
<div class='progress-bar ". $cor ." progress-bar ' role='progressbar' aria-valuenow='".$barra."' aria-valuemin='0' aria-valuemax='100' style='text-align:left; width: ".$barra."%;'> </div>
</td>\n";
echo "</tr>\n";
//}
}
unset($arrSize);
unset($arrUsed);
unset($arrUsed2);
echo "</tbody></table>\n";
echo "</div>\n";
echo "<div style='margin-bottom:60px;'></div>\n";
}
else {
//hosts
if($hosts['sd'] <> 0) { $conn = "Offline"; $cor = "#E3573F"; } else { $conn = "Online"; $cor = "#4BAC64"; }
echo "<div class='col-md-".$md." col-sm-".$md."' style='margin-bottom:0px;'>\n";
echo "<table class='tabs box table table-striped table-hover table-condensed' border='0' width='50%' style='border:1px solid #f2f2f2; '>
<thead>
<tr>
<th style='background:".$cor."; width:1%;' title='".$conn."'></th>
<th colspan='1' class='linkb' style='width:50%; font-weight:bold; text-align:left;'><a href='host_detail.php?hostid=".$hosts['hostid']."'> ".$hosts['name']." </a></th>
<th colspan='1' style='width:18%; text-align:left;'>". $labels['Used'] ."</th>
<th colspan='1' style='text-align:left;'> ". _('Total') ." </th>
<th colspan='1' style='text-align:left;'> % ". $labels['Used'] ." </th>
</tr>
</thead>
<tbody>\n";
echo "<tr style='text-align:left;'>\n";
echo " <td colspan='2'>No data</td>\n";
echo " <td colspan='1'></td>\n";
echo " <td colspan='1'></td>\n";
echo "<td width='15%' style='padding-right:15px;'></td>\n";
echo "</tr>\n";
echo "</tbody></table>\n";
echo "</div>\n";
echo "<div style='margin-bottom:60px;'></div>\n";
}
}
}
?>