1<?php
2// Pandora FMS - http://pandorafms.com
3// ==================================================
4// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas
5// Please see http://pandorafms.org for full contribution list
6
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation for version 2.
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13// GNU General Public License for more details.
14
15// Load global vars
16require_once ("include/config.php");
17require_once ("include/functions_reporting.php");
18require_once ($config['homedir'] . "/include/functions_agents.php");
19require_once ($config['homedir'] . '/include/functions_users.php');
20require_once ("include/functions_groupview.php");
21
22check_login ();
23// ACL Check
24if (! check_acl ($config['id_user'], 0, "AR")) {
25	db_pandora_audit("ACL Violation",
26	"Trying to access Agent view (Grouped)");
27	require ("general/noaccess.php");
28	exit;
29}
30$offset = get_parameter('offset', 0);
31// Update network modules for this group
32// Check for Network FLAG change request
33// Made it a subquery, much faster on both the database and server side
34if (isset ($_GET["update_netgroup"])) {
35	$group = get_parameter_get ("update_netgroup", 0);
36
37	if (check_acl ($config['id_user'], $group, "AW")) {
38		if ($group == 0) {
39			db_process_sql_update('tagente_modulo', array('flag' => 1));
40		}
41		else {
42			db_process_sql("UPDATE `tagente_modulo`
43				SET `flag` = 1
44				WHERE `id_agente` = ANY(SELECT id_agente
45					FROM tagente
46					WHERE id_grupo = " . $group . ")");
47		}
48	}
49	else {
50		db_pandora_audit("ACL Violation", "Trying to set flag for groups");
51		require ("general/noaccess.php");
52		exit;
53	}
54}
55
56if ($config["realtimestats"] == 0) {
57	$updated_time ="<a href='index.php?sec=estado&sec2=operation/agentes/tactical&force_refresh=1'>";
58	$updated_time .= __('Last update'). " : ". ui_print_timestamp (db_get_sql ("SELECT min(utimestamp) FROM tgroup_stat"), true);
59	$updated_time .= "</a>";
60}
61else {
62	$updated_time = __("Updated at realtime");
63}
64
65// Header
66ui_print_page_header (__("Group view"), "images/group.png", false, "", false, $updated_time);
67
68$strict_user = db_get_value('strict_acl', 'tusuario', 'id_user', $config['id_user']);
69
70$all_data = groupview_status_modules_agents ($config['id_user'], $strict_user, 'AR', $strict_user);
71
72$total_agentes = 0;
73$monitor_ok = 0;
74$monitor_warning = 0;
75$monitor_critical = 0;
76$monitor_unknown = 0;
77$monitor_not_init = 0;
78$agents_unknown = 0;
79$agents_notinit = 0;
80$all_alerts_fired = 0;
81
82foreach ($all_data as $group_all_data) {
83	$total_agentes += $group_all_data["_total_agents_"];
84	$monitor_ok += $group_all_data["_monitors_ok_"];
85	$monitor_warning += $group_all_data["_monitors_warning_"];
86	$monitor_critical += $group_all_data["_monitors_critical_"];
87	$monitor_unknown += $group_all_data["_monitors_unknown_"];
88	$monitor_not_init += $group_all_data["_monitors_not_init_"];
89
90	$agents_unknown += $group_all_data["_agents_unknown_"];
91	$agents_notinit += $group_all_data["_agents_not_init_"];
92
93	$all_alerts_fired += $group_all_data["_monitors_alerts_fired_"];
94}
95
96$total = $monitor_ok + $monitor_warning + $monitor_critical + $monitor_unknown + $monitor_not_init;
97
98//Monitors
99$total_ok = format_numeric (($monitor_ok*100)/$total,2);
100$total_warning = format_numeric (($monitor_warning*100)/$total,2);
101$total_critical = format_numeric (($monitor_critical*100)/$total,2);
102$total_unknown = format_numeric (($monitor_unknown*100)/$total,2);
103$total_monitor_not_init = format_numeric (($monitor_not_init*100)/$total,2);
104//Agents
105$total_agent_unknown = format_numeric (($agents_unknown*100)/$total_agentes,2);
106$total_not_init = format_numeric (($agents_notinit*100)/$total_agentes,2);
107
108echo '<table cellpadding="0" cellspacing="0" border="0" width="100%" class="databox">';
109	echo "<tr>";
110		echo "<th colspan=2 style='text-align: center;'>" . __("Summary of the status groups") . "</th>";
111	echo "</tr>";
112	echo "<tr>";
113		echo "<th width=30% style='text-align:center'>" . __("Agents") . "</th>";
114		echo "<th width=70% style='text-align:center'>" . __("Modules") . "</th>";
115	echo "</tr>";
116	echo "<tr height=70px'>";
117		echo "<td align='center'>";
118			echo "<span id='sumary' style='background-color:#B2B2B2;'>". $total_agent_unknown ."%</span>";
119			echo "<span id='sumary' style='background-color:#5bb6e5;'>". $total_not_init ."%</span>";
120		echo "</td>";
121		echo "<td align='center'>";
122			echo "<span id='sumary' style='background-color:#FC4444;'>". $total_critical ."%</span>";
123			echo "<span id='sumary' style='background-color:#FAD403;'>". $total_warning ."%</span>";
124			echo "<span id='sumary' style='background-color:#80BA27;'>". $total_ok ."%</span>";
125			echo "<span id='sumary' style='background-color:#B2B2B2;'>". $total_unknown ."%</span>";
126			echo "<span id='sumary' style='background-color:#5bb6e5;'>". $total_monitor_not_init ."%</span>";
127		echo "</td>";
128	echo "</tr>";
129echo "</table>";
130
131//Groups and tags
132$result_groups = groupview_get_groups_list($config['id_user'], $strict_user,
133	'AR', true, true);
134
135$count = count($result_groups);
136
137if ($count == 1) {
138	if ($result_groups[0]['_id_'] == 0) {
139		unset($result_groups[0]);
140	}
141}
142
143ui_pagination($count);
144
145if (!empty($result_groups)) {
146
147	echo '<table cellpadding="0" cellspacing="0" style="margin-top:10px;" class="databox data" border="0" width="100%">';
148		echo "<tr>";
149			echo "<th colspan=2 ></th>";
150			echo "<th colspan=3 class='difference' style='text-align:center'>" . __("Agents") . "</th>";
151			echo "<th colspan=6 style='text-align:center'>" . __("Modules") . "</th>";
152		echo "</tr>";
153
154		echo "<tr>";
155			echo "<th style='width: 26px;'>" . __("Force") . "</th>";
156			echo "<th width='30%' style='min-width: 60px;'>" . __("Group") . "/" . __("Tags") . "</th>";
157			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Total") . "</th>";
158			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Unknown") . "</th>";
159			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Not init") . "</th>";
160			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Unknown") . "</th>";
161			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Not Init") . "</th>";
162			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Normal") . "</th>";
163			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Warning") . "</th>";
164			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Critical") . "</th>";
165			echo "<th width='10%' style='min-width: 60px;text-align:center;'>" . __("Alert fired") . "</th>";
166		echo "</tr>";
167
168		$result_groups = array_slice($result_groups, $offset, $config['block_size']);
169
170		foreach ($result_groups as $data) {
171
172			$groups_id = $data["_id_"];
173
174			// Calculate entire row color
175			if ($data["_monitors_alerts_fired_"] > 0) {
176				$color_class = 'group_view_alrm';
177				$status_image = ui_print_status_image ('agent_alertsfired_ball.png', "", true);
178			}
179			elseif ($data["_monitors_critical_"] > 0) {
180				$color_class = 'group_view_crit';
181				$status_image = ui_print_status_image ('agent_critical_ball.png', "", true);
182			}
183			elseif ($data["_monitors_warning_"] > 0) {
184				$color_class = 'group_view_warn';
185				$status_image = ui_print_status_image ('agent_warning_ball.png', "", true);
186			}
187			elseif ($data["_monitors_ok_"] > 0)  {
188
189				$color_class = 'group_view_ok';
190				$status_image = ui_print_status_image ('agent_ok_ball.png', "", true);
191			}
192			elseif (($data["_monitors_unknown_"] > 0) ||  ($data["_agents_unknown_"] > 0)) {
193				$color_class = 'group_view_unk';
194				$status_image = ui_print_status_image ('agent_no_monitors_ball.png', "", true);
195			}
196			else {
197				$color_class = '';
198				$status_image = ui_print_status_image ('agent_no_data_ball.png', "", true);
199			}
200
201			echo "<tr style='height: 35px;'>";
202
203			// Force
204			echo "<td class='group_view_data' style='text-align: center; vertica-align: middle;'>";
205			if (!isset($data['_is_tag_']) && check_acl ($config['id_user'], $data['_id_'], "AW")) {
206				echo '<a href="index.php?sec=estado&sec2=operation/agentes/group_view&update_netgroup='.$data['_id_'].'">' .
207					html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'))) . '</a>';
208			}
209			echo "</td>";
210
211			$prefix = "";
212			if (!isset($data['_is_tag_'])) {
213				if ($data['_id_'] != 0) {
214					$prefix = '&nbsp;&nbsp;&nbsp;&nbsp;';
215				}
216			}
217
218			// Groupname and Tags
219			echo "<td>";
220			if (isset($data['_is_tag_'])) {
221				$deep = "";
222				$link = "<a href='index.php?sec=monitoring&sec2=operation/tree&tag_id=".$data['_id_']. "'>";
223			} else {
224				$deep = groups_get_group_deep ($data['_id_']);
225				$link = "<a href='index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=".$data['_id_']."'>";
226			}
227
228			$group_name = "<b><span style='font-size: 7.5pt'>" . ui_print_truncate_text($data['_name_'], 50) . "</span></b>";
229
230			$item_icon = '';
231			if (isset($data['_iconImg_']) && !empty($data['_iconImg_']))
232				$item_icon = $data['_iconImg_'];
233
234			if ($data['_name_'] != "All")
235				echo $deep . $link . $group_name . "</a>";
236			else
237				echo $link . $group_name . "</a>";
238
239			if (isset($data['_is_tag_'])){
240				echo '<a>' . html_print_image("images/tag.png", true, array("border" => '0', "style" => 'width:18px;margin-left:5px', "title" => __('Tag'))) . '</a>' ;
241			}
242
243			echo "</td>";
244
245			// Total agents
246			echo "<td style='font-weight: bold; font-size: 18px;' align='center' class='$color_class'>";
247			if (isset($data['_is_tag_'])) {
248				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
249				href='index.php?sec=monitoring&sec2=operation/tree&tag_id=".$data['_id_']. "'>";
250			} else {
251				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
252				href='index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=".$data['_id_']."'>";
253			}
254			if ($data["_id_"] == 0) {
255				echo $link . $total_agentes . "</a>";
256			}
257			if ($data["_total_agents_"] > 0 && $data["_id_"] != 0) {
258				echo $link . $data["_total_agents_"] . "</a>";
259			}
260			echo "</td>";
261
262			// Agents unknown
263			echo "<td class='group_view_data group_view_data_unk $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
264			if (isset($data['_is_tag_'])) {
265				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
266				href='index.php?sec=monitoring&sec2=operation/tree&tag_id=".$data['_id_']. "&status=" . AGENT_STATUS_UNKNOWN ."'>";
267			} else {
268				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
269				href='index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=".$data['_id_']."&status=" . AGENT_STATUS_UNKNOWN ."'>";
270			}
271			if (($data["_id_"] == 0) && ($agents_unknown != 0)) {
272				echo $link . $agents_unknown . "</a>";
273			}
274			if ($data["_agents_unknown_"] > 0 && ($data["_id_"] != 0)) {
275				echo $link . $data["_agents_unknown_"] . "</a>";
276			}
277			echo "</td>";
278
279			// Agents not init
280			echo "<td class='group_view_data group_view_data_unk $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
281			if (isset($data['_is_tag_'])) {
282				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
283				href='index.php?sec=monitoring&sec2=operation/tree&tag_id=".$data['_id_']. "&status=" . AGENT_STATUS_NOT_INIT ."'>";
284			} else {
285				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
286				href='index.php?sec=estado&sec2=operation/agentes/estado_agente&group_id=".$data['_id_']."&status=" . AGENT_STATUS_NOT_INIT ."'>";
287			}
288			if (($data["_id_"] == 0) && ($agents_notinit != 0)) {
289				echo $link . $agents_notinit . "</a>";
290			}
291
292			if ($data["_agents_not_init_"] > 0 && ($data["_id_"] != 0)) {
293				echo $link . $data["_agents_not_init_"] . "</a>";
294			}
295			echo "</td>";
296
297			// Monitors unknown
298			echo "<td class='group_view_data group_view_data_unk $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
299			if (!isset($data['_is_tag_'])) {
300				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
301				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&ag_group=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_UNKNOWN . "'>";
302			} else {
303				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
304				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&tag_filter=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_UNKNOWN . "'>";
305			}
306			if (($data["_id_"] == 0) && ($monitor_unknown != 0)) {
307				echo $link . $monitor_unknown . "</a>";
308			}
309			if ($data["_monitors_unknown_"] > 0 && ($data["_id_"] != 0)) {
310				echo $link . $data["_monitors_unknown_"] . "</a>";
311			}
312			echo "</td>";
313
314			// Monitors not init
315			echo "<td class='group_view_data group_view_data_unk $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
316			if (!isset($data['_is_tag_'])) {
317				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
318				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&ag_group=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_NOT_INIT . "'>";
319			} else {
320				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
321				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&tag_filter=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_NOT_INIT . "'>";
322			}
323			if (($data["_id_"] == 0) && ($monitor_not_init != 0)) {
324				echo $link . $monitor_not_init . "</a>";
325			}
326			if ($data["_monitors_not_init_"] > 0 && ($data["_id_"] != 0)) {
327				echo $link . $data["_monitors_not_init_"] . "</a>";
328			}
329			echo "</td>";
330
331			// Monitors OK
332			echo "<td class='group_view_data group_view_data_ok $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
333			if (!isset($data['_is_tag_'])) {
334				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
335				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&ag_group=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_NORMAL . "'>";
336			} else {
337				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
338				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&tag_filter=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_NORMAL . "'>";
339			}
340			if (($data["_id_"] == 0) && ($monitor_ok != 0)) {
341				echo $link . $monitor_ok . "</a>";
342			}
343			if ($data["_monitors_ok_"] > 0 && ($data["_id_"] != 0)) {
344				echo $link . $data["_monitors_ok_"] . "</a>";
345			}
346			echo "</td>";
347
348			// Monitors Warning
349			echo "<td class='group_view_data group_view_data_warn $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
350			if (!isset($data['_is_tag_'])) {
351				$link = "<a class='group_view_data group_view_data_warn $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
352				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&ag_group=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_WARNING . "'>";
353			} else {
354				$link = "<a class='group_view_data group_view_data_warn $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
355				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&tag_filter=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_WARNING . "'>";
356			}
357			if (($data["_id_"] == 0) && ($monitor_warning != 0)) {
358				echo $link . $monitor_warning . "</a>";
359			}
360			if ($data["_monitors_warning_"] > 0 && ($data["_id_"] != 0)) {
361				echo $link . $data["_monitors_warning_"] . "</a>";
362			}
363			echo "</td>";
364
365			// Monitors Critical
366			echo "<td class='group_view_data group_view_data_crit $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'>";
367			if (!isset($data['_is_tag_'])) {
368				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
369				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&ag_group=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD . "'>";
370			} else {
371				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
372				href='index.php?sec=estado&sec2=operation/agentes/status_monitor&tag_filter=".$data['_id_']."&status=" . AGENT_MODULE_STATUS_CRITICAL_BAD . "'>";
373			}
374			if (($data["_id_"] == 0) && ($monitor_critical != 0)) {
375				echo $link . $monitor_critical . "</a>";
376			}
377			if ($data["_monitors_critical_"] > 0 && ($data["_id_"] != 0)) {
378				echo $link . $data["_monitors_critical_"] . "</a>";
379			}
380			echo "</td>";
381
382			// Alerts fired
383			echo "<td class='group_view_data group_view_data_alrm $color_class' style='font-weight: bold; font-size: 18px;  text-align: center;'>";
384			if (!isset($data['_is_tag_'])) {
385				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
386				href='index.php?sec=estado&sec2=operation/agentes/alerts_status&ag_group=".$data['_id_']."&filter=fired'>";
387			} else {
388				$link = "<a class='group_view_data $color_class' style='font-weight: bold; font-size: 18px; text-align: center;'
389				href='index.php?sec=estado&sec2=operation/agentes/alerts_status&tag_filter=".$data['_id_']."&filter=fired'>";
390			}
391			if (($data["_id_"] == 0) && ($all_alerts_fired != 0)) {
392				echo $link . $all_alerts_fired . "</a>";
393			}
394			if ($data["_monitors_alerts_fired_"] > 0 && ($data["_id_"] != 0)) {
395				echo $link . $data["_monitors_alerts_fired_"] . "</a>";
396			}
397			echo '</td>';
398
399			echo "</tr>";
400		}
401	echo '</table>';
402} else {
403	ui_print_info_message ( __('There are no defined agents'));
404}
405?>