'select distinct t.triggerid, t.priority, t.value, t.description, h.host '. 'from triggers t, items i, functions f, hosts h where t.triggerid='.$db_element['elementid']. ' and h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid '. ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE, SYSMAP_ELEMENT_TYPE_HOST_GROUP => 'select distinct t.triggerid, t.priority, t.value,'. ' t.description, h.host, g.name as el_name '. ' from items i,functions f,triggers t,hosts h,hosts_groups hg,groups g '. ' where h.hostid=i.hostid and hg.groupid=g.groupid and g.groupid='.$db_element['elementid']. ' and hg.hostid=h.hostid and i.itemid=f.itemid'. ' and f.triggerid=t.triggerid and t.status='.TRIGGER_STATUS_ENABLED. ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE, SYSMAP_ELEMENT_TYPE_HOST => 'select distinct t.triggerid, t.priority, t.value,'. ' t.description, h.host, h.host as el_name'. ' from items i,functions f,triggers t,hosts h where h.hostid=i.hostid'. ' and i.hostid='.$db_element['elementid'].' and i.itemid=f.itemid'. ' and f.triggerid=t.triggerid and t.status='.TRIGGER_STATUS_ENABLED. ' and h.status='.HOST_STATUS_MONITORED.' and i.status='.ITEM_STATUS_ACTIVE ); if( isset($sql[$el_type]) ) { $db_triggers = DBselect($sql[$el_type]); $trigger = DBfetch($db_triggers); if($trigger) { if(isset($trigger['el_name'])) { $el_name = $trigger['el_name']; } else { $el_name = expand_trigger_description_by_data($trigger); } do { $type =& $trigger['value']; if(!isset($tr_info[$type])) $tr_info[$type] = array('count' => 0); $tr_info[$type]['count']++; if(!isset($tr_info[$type]['priority']) || $tr_info[$type]['priority'] < $trigger["priority"]) { $tr_info[$type]['priority'] = $trigger["priority"]; if($el_type != SYSMAP_ELEMENT_TYPE_TRIGGER && $type!=TRIGGER_VALUE_UNKNOWN) $tr_info[$type]['info'] = expand_trigger_description_by_data($trigger); } } while ($trigger = DBfetch($db_triggers)); } elseif($el_type == SYSMAP_ELEMENT_TYPE_HOST) { $host = get_host_by_hostid($db_element["elementid"]); $el_name = $host['host']; if($host["status"] == HOST_STATUS_TEMPLATE) { $tr_info[TRIGGER_VALUE_UNKNOWN]['count'] = 1; $tr_info[TRIGGER_VALUE_UNKNOWN]['priority'] = 0; $tr_info[TRIGGER_VALUE_UNKNOWN]['info'] = S_TEMPLATE_SMALL; } else { $tr_info[TRIGGER_VALUE_FALSE]['count'] = 0; $tr_info[TRIGGER_VALUE_FALSE]['priority'] = 0; $tr_info[TRIGGER_VALUE_FALSE]['info'] = S_OK_BIG; } } } elseif($el_type==SYSMAP_ELEMENT_TYPE_MAP) { $db_map = DBfetch(DBselect('select name from sysmaps where sysmapid='.$db_element["elementid"])); $el_name = $db_map['name']; $db_subelements = DBselect("select selementid from sysmaps_elements". " where sysmapid=".$db_element["elementid"]); while($db_subelement = DBfetch($db_subelements)) {// recursion $inf = get_info_by_selementid($db_subelement["selementid"]); $type = $inf['type']; if(!isset($tr_info[$type]['count'])) $tr_info[$type]['count'] = 0; $tr_info[$type]['count'] += isset($inf['count']) ? $inf['count'] : 1; if(!isset($tr_info[$type]['priority']) || $tr_info[$type]['priority'] < $inf["priority"]) { $tr_info[$type]['priority'] = $inf['priority']; $tr_info[$type]['info'] = $inf['info']; } } } if(isset($tr_info[TRIGGER_VALUE_TRUE])) { $inf =& $tr_info[TRIGGER_VALUE_TRUE]; $out['type'] = TRIGGER_VALUE_TRUE; $out['info'] = S_TRUE_BIG; if($inf['count'] > 1) $out['info'] = $inf['count']." ".S_PROBLEMS_SMALL; else if(isset($inf['info'])) $out['info'] = $inf['info']; if($inf['priority'] > 3) $out['color'] = $colors['Red']; else $out['color'] = $colors['Dark Red']; $out['iconid'] = $db_element['iconid_on']; } elseif(isset($tr_info[TRIGGER_VALUE_UNKNOWN]) && !isset($tr_info[TRIGGER_VALUE_FALSE])) { $inf =& $tr_info[TRIGGER_VALUE_UNKNOWN]; $out['type'] = TRIGGER_VALUE_UNKNOWN; $out['info'] = S_UNKNOWN_BIG; /* if($inf['count'] > 1) $out['info'] = $inf['count']." ".S_UNKNOWN; else */ if(isset($inf['info'])) $out['info'] = $inf['info']; $out['color'] = $colors['Gray']; $out['iconid'] = $db_element['iconid_unknown']; } else { $inf =& $tr_info[TRIGGER_VALUE_FALSE]; $out['type'] = TRIGGER_VALUE_FALSE; $out['info'] = S_FALSE_BIG; if(isset($inf['info'])) $out['info'] = S_OK_BIG; $out['color'] = $colors['Dark Green']; $out['iconid'] = $db_element['iconid_off']; } $out['count'] = $inf['count']; $out['priority'] = $inf['priority']; $out['name'] = $el_name; return $out; } function get_action_map_by_sysmapid($sysmapid) { $action_map = new CMap("links$sysmapid"); $db_elements=DBselect("select * from sysmaps_elements where sysmapid=$sysmapid"); while($db_element = DBfetch($db_elements)) { $url = $db_element["url"]; $alt = "Label: ".$db_element["label"]; if($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST) { $host = get_host_by_hostid($db_element["elementid"]); if($host["status"] != HOST_STATUS_MONITORED) continue; if($url=="") $url="tr_status.php?hostid=".$db_element["elementid"]. "&noactions=true&onlytrue=true&compact=true"; $alt = "Host: ".$host["host"]." ".$alt; } elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_MAP) { $map = get_sysmap_by_sysmapid($db_element["elementid"]); if($url=="") $url="maps.php?sysmapid=".$db_element["elementid"]; $alt = "Host: ".$map["name"]." ".$alt; } elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_TRIGGER) { if($url=="" && $db_element["elementid"]!=0) $url="tr_events.php?triggerid=".$db_element["elementid"]; } elseif($db_element["elementtype"] == SYSMAP_ELEMENT_TYPE_HOST_GROUP) { if($url=="" && $db_element["elementid"]!=0) $url="events.php?hostid=0&groupid=".$db_element["elementid"]; } if($url=="") continue; $back = get_png_by_selementid($db_element["selementid"]); if(!$back) continue; $x1_ = $db_element["x"]; $y1_ = $db_element["y"]; $x2_ = $db_element["x"] + imagesx($back); $y2_ = $db_element["y"] + imagesy($back); $action_map->AddRectArea($x1_,$y1_,$x2_,$y2_, $url, $alt); } return $action_map; } function get_icon_center_by_selementid($selementid) { $element = get_sysmaps_element_by_selementid($selementid); $x = $element["x"]; $y = $element["y"]; $image = get_png_by_selementid($selementid); if($image) { $x += imagesx($image) / 2; $y += imagesy($image) / 2; } return array($x, $y); } function MyDrawLine($image,$x1,$y1,$x2,$y2,$color,$drawtype) { if($drawtype == GRAPH_DRAW_TYPE_BOLDLINE) { ImageLine($image,$x1,$y1,$x2,$y2,$color); if(($x1-$x2) < ($y1-$y2)) { $x1++; $x2++; } else { $y1++; $y2++; } ImageLine($image,$x1,$y1,$x2,$y2,$color); } else if($drawtype == GRAPH_DRAW_TYPE_DASHEDLINE) { if(function_exists("imagesetstyle")) { /* Use ImageSetStyle+ImageLIne instead of bugged ImageDashedLine */ $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT); ImageSetStyle($image, $style); ImageLine($image,$x1,$y1,$x2,$y2,IMG_COLOR_STYLED); } else { ImageDashedLine($image,$x1,$y1,$x2,$y2,$color); } } else { ImageLine($image,$x1,$y1,$x2,$y2,$color); } } ?>