Already committed
rev. 5697
rev. 5697
diff -ruN zabbix-original/frontends/php/latest.php zabbix/frontends/php/latest.php
--- zabbix-original/frontends/php/latest.php 2008-04-30 04:03:14.000000000 -0400
+++ zabbix/frontends/php/latest.php 2008-05-12 08:57:22.000000000 -0400
@@ -50,7 +50,7 @@
check_fields($fields);
validate_sort_and_sortorder('i.description',ZBX_SORT_UP);
- $options = array("allow_all_hosts","monitored_hosts","with_monitored_items");//,"always_select_first_host");
+ $options = array("allow_all_hosts","monitored_hosts","with_monitored_items","always_select_first_host");
if(!$ZBX_WITH_SUBNODES) array_push($options,"only_current_node");
validate_group_with_host(PERM_READ_ONLY,$options);
@@ -97,14 +97,56 @@
$r_form->AddVar("select",$_REQUEST["select"]);
+ $available_groups= get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST);
+ $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST);
+
+ $result=DBfetch(DBselect('SELECT DISTINCT g.groupid,g.name '.
+ ' FROM groups g, hosts_groups hg, hosts h, items i '.
+ ' WHERE g.groupid in ('.$available_groups.') '.
+ ' AND hg.groupid=g.groupid '.
+ ' AND h.status='.HOST_STATUS_MONITORED.
+ ' AND h.hostid=i.hostid '.
+ ' AND hg.hostid=h.hostid '.
+ ' AND i.status='.ITEM_STATUS_ACTIVE.
+ ' ORDER BY g.name'.
+ ' LIMIT 1'));
+
+ if(str_in_array("always_select_first_host",$options) && $_REQUEST["groupid"] == 0)
+ $_REQUEST["groupid"] = $result["groupid"];
+
+ if($_REQUEST['groupid'] > 0){
+ $sql='SELECT DISTINCT h.hostid,h.host '.
+ ' FROM hosts h,items i,hosts_groups hg '.
+ ' WHERE h.status='.HOST_STATUS_MONITORED.
+ ' AND h.hostid=i.hostid '.
+ ' AND hg.groupid='.$_REQUEST['groupid'].
+ ' AND hg.hostid=h.hostid'.
+ ' AND i.status='.ITEM_STATUS_ACTIVE.
+ ' AND h.hostid in ('.$available_hosts.') '.
+ ' ORDER BY h.host'.
+ ' LIMIT 1';
+ }
+ else{
+ $sql='SELECT DISTINCT h.hostid,h.host '.
+ ' FROM hosts h,items i '.
+ ' WHERE h.status='.HOST_STATUS_MONITORED.
+ ' AND i.status='.ITEM_STATUS_ACTIVE.
+ ' AND h.hostid=i.hostid'.
+ ' AND h.hostid in ('.$available_hosts.') '.
+ ' ORDER BY h.host'.
+ ' LIMIT 1';
+ }
+
+ $result=DBfetch(DBselect($sql));
+
+ if(str_in_array("always_select_first_host",$options) && $_REQUEST["hostid"] == 0)
+ $_REQUEST["hostid"] = $result["hostid"];
+
$cmbGroup = new CComboBox("groupid",$_REQUEST["groupid"],"submit()");
$cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit()");
$cmbGroup->AddItem(0,S_ALL_SMALL);
$cmbHosts->AddItem(0,S_ALL_SMALL);
-
- $available_groups= get_accessible_groups_by_user($USER_DETAILS,PERM_READ_LIST);
- $available_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_LIST);
$result=DBselect('SELECT DISTINCT g.groupid,g.name '.
' FROM groups g, hosts_groups hg, hosts h, items i '.
@@ -220,12 +262,12 @@
order_by('h.host,h.hostid','a.name,a.applicationid'));
while($db_app = DBfetch($db_applications)){
- $db_items = DBselect('SELECT DISTINCT i.* '.
- ' FROM items i,items_applications ia'.
- ' WHERE ia.applicationid='.$db_app['applicationid'].
- ' AND i.itemid=ia.itemid'.
- ' AND i.status='.ITEM_STATUS_ACTIVE.
- order_by('i.description,i.itemid,i.lastclock'));
+ $db_items = DBselect('SELECT DISTINCT i.itemid,i.description,i.lastclock,i.key_,i.lastvalue,i.prevvalue,i.value_type,i.units,i.valuemapid '.
+ ' FROM items i,items_applications ia'.
+ ' WHERE ia.applicationid='.$db_app['applicationid'].
+ ' AND i.itemid=ia.itemid'.
+ ' AND i.status='.ITEM_STATUS_ACTIVE.
+ order_by('i.description,i.itemid,i.lastclock'));
$app_rows = array();
$item_cnt = 0;
Comment