"; } else if($operator == CONDITION_OPERATOR_LIKE) { $op="like"; } else if($operator == CONDITION_OPERATOR_NOT_LIKE) { $op="not like"; } else if($operator == CONDITION_OPERATOR_IN) { $op="in"; } else if($operator == CONDITION_OPERATOR_MORE_EQUAL) { $op=">="; } else if($operator == CONDITION_OPERATOR_LESS_EQUAL) { $op="<="; } $desc=S_UNKNOWN; if($conditiontype==CONDITION_TYPE_GROUP) { $group=get_hostgroup_by_groupid($value); if($group) $desc=S_HOST_GROUP." $op "."\"".$group["name"]."\""; } if($conditiontype==CONDITION_TYPE_TRIGGER) { $desc=S_TRIGGER." $op "."\"".expand_trigger_description($value)."\""; } else if($conditiontype==CONDITION_TYPE_HOST) { $host=get_host_by_hostid($value); if($host) $desc=S_HOST." $op "."\"".$host["host"]."\""; } else if($conditiontype==CONDITION_TYPE_TRIGGER_NAME) { $desc=S_TRIGGER_DESCRIPTION." $op "."\"".$value."\""; } else if($conditiontype==CONDITION_TYPE_TRIGGER_VALUE) { if($value==0) $desc=S_TRIGGER_VALUE." $op "."\"OFF\""; if($value==1) $desc=S_TRIGGER_VALUE." $op "."\"ON\""; } else if($conditiontype==CONDITION_TYPE_TRIGGER_SEVERITY) { $desc=S_TRIGGER_SEVERITY." $op "."\"".get_severity_description($value)."\""; } else if($conditiontype==CONDITION_TYPE_TIME_PERIOD) { $desc=S_TIME." $op "."\"".$value."\""; } else { } return $desc; } # Add Action's condition function add_action_condition($actionid, $conditiontype, $operator, $value) { $conditionid=get_dbid("conditions","conditionid"); $sql="insert into conditions (conditionid,actionid,conditiontype,operator,value)". " values ($conditionid,$actionid,$conditiontype,$operator,".zbx_dbstr($value).")"; $result=DBexecute($sql); if(!$result) return $result; return $conditionid; } function update_action_status($actionid, $status) { return DBexecute("update actions set status=$status where actionid=$actionid"); } function check_commands($commands) { $cmd_list = split("\n",$commands); foreach($cmd_list as $cmd) { $cmd = trim($cmd, "\x00..\x1F"); if(!ereg("^([0-9a-zA-Z\_\.[.-.]]{1,})(:|#)[[:print:]]*$",$cmd,$cmd_items)){ error("incorrect command: '$cmd'"); return FALSE; } if($cmd_items[2] == "#") { // group if(!DBfetch(DBselect("select groupid from groups where name=".zbx_dbstr($cmd_items[1])))) { error("Uncnown group name: '".$cmd_items[1]."' in command ".$cmd."'"); return FALSE; } } elseif($cmd_items[2] == ":") { // host if(!DBfetch(DBselect("select hostid from hosts where host=".zbx_dbstr($cmd_items[1])))) { error("Uncnown host name '".$cmd_items[1]."' in command '".$cmd."'"); return FALSE; } } } return TRUE; } function get_history_of_actions($start,$num) { global $USER_DETAILS; $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY, PERM_MODE_LT); $result=DBselect("select distinct a.alertid,a.clock,mt.description,a.sendto,a.subject,a.message,a.status,a.retries,". "a.error from alerts a,media_type mt,functions f,items i ". " where mt.mediatypeid=a.mediatypeid and a.triggerid=f.triggerid and f.itemid=i.itemid ". " and i.hostid not in (".$denyed_hosts.")". " order by a.clock". " desc", 10*$start+$num); $table = new CTableInfo(S_NO_ACTIONS_FOUND); $table->SetHeader(array(S_TIME, S_TYPE, S_STATUS, S_RECIPIENTS, S_MESSAGE, S_ERROR)); $col=0; $skip=$start; while(($row=DBfetch($result))&&($col<$num)) { if($skip > 0) { $skip--; continue; } $time=date("Y.M.d H:i:s",$row["clock"]); if($row["status"] == 1) { $status=new CSpan(S_SENT,"off"); } else { $status=new CSpan(S_NOT_SENT,"on"); } $sendto=htmlspecialchars($row["sendto"]); $subject = empty($row["subject"]) ? '' : "
".bold(S_SUBJECT.': ').htmlspecialchars($row["subject"])."
"; $message = array($subject,"
".htmlspecialchars($row["message"])."
"); if($row["error"] == "") { $error=new CSpan(SPACE,"off"); } else { $error=new CSpan($row["error"],"on"); } $table->AddRow(array( new CCol($time, 'top'), new CCol($row["description"], 'top'), new CCol($status, 'top'), new CCol($sendto, 'top'), new CCol($message, 'top'), new CCol($error, 'top'))); $col++; } return $table; } ?>