forked from bmelim/zabdash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup_hosts.php
147 lines (119 loc) · 5.75 KB
/
group_hosts.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
<?php
$group = get_hostgroup_by_groupid($groupID);
$groupName = $group['name'];
$dbHostsCount = DBselect( 'SELECT COUNT(h.hostid) AS hc FROM hosts h, hosts_groups hg WHERE h.status <> 3 AND h.flags = 0 AND h.hostid = hg.hostid AND hg.groupid = '.$groupID );
$hostsCount = DBFetch($dbHostsCount);
//check version
if(ZABBIX_EXPORT_VERSION >= '4.0'){
$grps = 'hstgrp';
}
else {
$grps = 'groups';
}
$dbHosts = DBselect( 'SELECT h.hostid, h.name, h.status, h.snmp_available AS sa, h.snmp_disable_until AS sd, h.flags, g.name AS gname, h.maintenance_status AS ms FROM hosts h, hosts_groups hg, '.$grps.' g WHERE h.status <> 3 AND h.flags = 0 AND h.hostid = hg.hostid AND g.groupid = hg.groupid AND hg.groupid = '.$groupID.' ORDER BY h.name ASC');
$md = 11;
//echo 'SELECT h.hostid, h.name, h.status, h.snmp_available AS sa, h.snmp_disable_until AS sd, h.flags, g.name AS gname FROM hosts h, hosts_groups hg, '.$grps.' g WHERE h.status <> 3 AND h.flags = 0 AND h.hostid = hg.hostid AND g.groupid = hg.groupid AND hg.groupid = '.$groupID.' ORDER BY h.name ASC' ;
echo "
<div class='align col-md-".$md." col-sm-".$md."' style='margin-bottom:80px;' >
<h3 style='color:#000 !important; margin-top:-2 px; text-align:center;'> " .$groupName."</h3>
<table id='tab_hosts' class='box table table-striped table-hover' border='0' >
<thead>
<tr>
<th width='4px;' style='padding:3px !important; text-align:right;'></th>
<th style='text-align:center;'>Hosts (".$hostsCount['hc'].")</th>
<th style='text-align:center;'>".$labels['O.S.']."</th>
<th style='text-align:center;'>". _('IP')."</th>
<th style='text-align:center;'>". _('Triggers')."</th>
<th style='text-align:center;'>". _('Status')."</th>
</tr>
</thead>
<tbody> ";
while ($hosts = DBFetch($dbHosts)) {
if($hosts['sd'] <> 0) { $conn = "Offline"; $cor = "#E3573F"; $value = 1; }
else { $conn = "Online"; $cor = "#4BAC64"; $value = 0; }
$dbIP = DBSelect('SELECT DISTINCT ip FROM interface WHERE hostid ='.$hosts['hostid']);
$IP = DBFetch($dbIP);
$hostOS = getOS($hosts['hostid']);
$trigger = $api->triggerGet(array(
'output' => 'extend',
'hostids' => $hosts['hostid'],
'sortfield' => 'priority',
'sortorder' => 'DESC',
'only_true' => '1',
'active' => '1', // include trigger state active not active
'withUnacknowledgedEvents' => '1' // show only unacknowledgeevents
));
if ($trigger) {
// Highest Priority error
$hostdivprio = $trigger[0]->priority;
$priority = $event->priority;
$description = $event->description;
foreach ($trigger as $event) {
$conta = $count++ ;
}
echo "
<tr>
<td style='background-color:".$cor.";' title='".$conn."' data-order='".$value."'>
</td>
<td class='link2' style='vertical-align:middle; text-align:left; padding:5px;'>
<a href='host_detail.php?hostid=".$hosts['hostid']."' target='_self' >".$hosts['name']."</a>
</td>
<td style='text-align:center;' data-order='".$hostOS."'>
<img src='img/os/".$hostOS.".png' title='".$hostOS."' alt=''/>
</td>
<td style='text-align:center; vertical-align:middle; '>
".$IP['ip']."
</td>
<td style='text-align:center; width:155px;'>
<div class='hostdiv nok". $hostdivprio ." hostevent trig_radius' onclick=\"window.open('".$zabURL."zabbix.php?action=problem.view&page=1&filter_hostids[]=".$hosts['hostid']."&filter_show=1&filter_application=&filter_name=&filter_severity=0&filter_inventory[0][field]=type&filter_inventory[0][value]=&filter_evaltype=0&filter_tags[0][tag]=&filter_tags[0][operator]=0&filter_tags[0][value]=&filter_show_tags=3&filter_tag_name_format=0&filter_tag_priority=&filter_set=1')\">
<span class='eventdate'>". from_epoch($trigger[0]->lastchange)."</span>
</div>
</td>
<td style='text-align:center; vertical-align:middle'>
". hostStatus($hosts['status'],$hosts['ms']) ."
</td>
</tr>";
}
else {
echo "
<tr>
<td style='background-color:".$cor.";' title='".$conn."' data-order='".$value."'>
</td>
<td class='link2' style='vertical-align:middle; text-align:left; padding:5px;'>
<a href='host_detail.php?hostid=".$hosts['hostid']."' target='_self' >".$hosts['name']."</a>
</td>
<td style='text-align:center;' data-order='".$hostOS."'>
<img src='img/os/".$hostOS.".png' title='".$hostOS."' alt=''/>
</td>
<td style='text-align:center; vertical-align:middle; '>
".$IP['ip']."
</td>
<td style='text-align:center; width:155px;'>
<div class='hostdiv ok hostevent trig_radius' onclick=\"window.open('".$zabURL."zabbix.php?action=problem.view&page=1&filter_hostids[]=".$hosts['hostid']."&filter_show=1&filter_application=&filter_name=&filter_severity=0&filter_inventory[0][field]=type&filter_inventory[0][value]=&filter_evaltype=0&filter_tags[0][tag]=&filter_tags[0][operator]=0&filter_tags[0][value]=&filter_show_tags=3&filter_tag_name_format=0&filter_tag_priority=&filter_set=1')\">
<span class='eventdate' style='color:#fff !important;'> <i class='fa fa-check'></i> </span>
</div>
</td>
<td style='text-align:center; vertical-align:middle'>
". hostStatus($hosts['status'],$hosts['ms']) ."
</td>
</tr>";
}
}
echo " </tbody>
</table>
</div>\n";
?>
<script type="text/javascript">
$(document).ready(function() {
$('#tab_hosts').DataTable({
"select": false,
"paging": true,
"ordering": true,
"info": true,
"order": [[ 1, "asc" ]],
pagingType: "full_numbers",
displayLength: 15,
lengthMenu: [[15,25, 50, 100, -1], [15,25, 50, 100, "All"]],
});
});
</script>