"; $result=DBexecute($sql); if(!$result) { return $result; } $triggerid=DBinsert_id($result,"triggers","triggerid"); # echo $triggerid,"
"; add_alarm($triggerid,2); $expression=implode_exp($expression,$triggerid); $sql="update triggers set expression='$expression' where triggerid=$triggerid"; # echo $sql,"
"; DBexecute($sql); reset_items_nextcheck($triggerid); return $triggerid; } # Delete Trigger definition function delete_trigger($triggerid) { $sql="select count(*) from trigger_depends where triggerid_down=$triggerid or triggerid_up=$triggerid"; $result=DBexecute($sql); if(DBget_field($result,0,0)>0) { error("Delete dependencies first"); return FALSE; } $result=delete_function_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_alarms_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_actions_by_triggerid($triggerid); if(!$result) { return $result; } $result=delete_services_by_triggerid($triggerid); if(!$result) { return $result; } $sql="update sysmaps_links set triggerid=NULL where triggerid=$triggerid"; DBexecute($sql); $sql="delete from triggers where triggerid=$triggerid"; return DBexecute($sql); } # Update Trigger definition function update_trigger($triggerid,$expression,$description,$priority,$status,$comments,$url) { if(!check_right_on_trigger("U",$triggerid)) { error("Insufficient permissions"); return 0; } $result=delete_function_by_triggerid($triggerid); if(!$result) { return $result; } $expression=implode_exp($expression,$triggerid); add_alarm($triggerid,2); // $sql="update triggers set expression='$expression',description='$description',priority=$priority,status=$status,comments='$comments',url='$url' where triggerid=$triggerid"; reset_items_nextcheck($triggerid); $sql="update triggers set expression='$expression',description='$description',priority=$priority,status=$status,comments='$comments',url='$url',value=2 where triggerid=$triggerid"; return DBexecute($sql); } function check_right_on_trigger($permission,$triggerid) { $sql="select distinct h.hostid from functions f,items i,hosts h where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=$triggerid"; $result=DBselect($sql); $ok=0; while($row=DBfetch($result)) { if(check_right("Host",$permission,$row["hostid"])) { $ok=1; } } return $ok; } function get_trigger_by_triggerid($triggerid) { $sql="select triggerid,expression,description,status,priority,lastchange,dep_level,comments,url,value from triggers where triggerid=$triggerid"; $result=DBselect($sql); if(DBnum_rows($result) == 1) { return DBfetch($result); } else { error("No trigger with triggerid=[$triggerid]"); } return $trigger; } function delete_trigger_dependency($triggerid_down,$triggerid_up) { // Why this was here? // $sql="select count(*) from trigger_depends where triggerid_down=$triggerid_up and triggerid_up=$triggerid_down"; // $result=DBexecute($sql); // if(DBget_field($result,0,0)>0) // { // return FALSE; // } $sql="select triggerid_down,triggerid_up from trigger_depends where triggerid_up=$triggerid_up and triggerid_down=$triggerid_down"; $result=DBexecute($sql); for($i=0;$i3 function add_additional_dependencies($triggerid_down,$triggerid_up) { $sql="select triggerid_down from trigger_depends where triggerid_up=$triggerid_down"; $result=DBselect($sql); for($i=0;$i