summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authoralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-10-21 11:05:00 +0000
committeralex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-10-21 11:05:00 +0000
commit469010ebdf4c1d779e41eacfcdc4f7c479cbb334 (patch)
tree265c3d34fd2e950b6f6cdbd5e1ebc23c4771bc23 /frontends/php/include
parent381c6742533757053481569ae11496f8528cd37c (diff)
downloadzabbix-469010ebdf4c1d779e41eacfcdc4f7c479cbb334.tar.gz
zabbix-469010ebdf4c1d779e41eacfcdc4f7c479cbb334.tar.xz
zabbix-469010ebdf4c1d779e41eacfcdc4f7c479cbb334.zip
- [DEV-43] support of new macros {ITEM.VALUE}, {ITEM.VALUE1}, etc (Alexei)
[svn merge -r4874:4876 svn://svn.zabbix.com/branches/1.4.j] git-svn-id: svn://svn.zabbix.com/trunk@4877 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/defines.inc.php3
-rw-r--r--frontends/php/include/events.inc.php2
-rw-r--r--frontends/php/include/items.inc.php68
-rw-r--r--frontends/php/include/triggers.inc.php174
4 files changed, 243 insertions, 4 deletions
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 733362ea..55bf5699 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -352,6 +352,9 @@
define('ZBX_NODE_LOCAL', 1);
define('ZBX_NODE_MASTER', 2);
+ define('ZBX_FLAG_TRIGGER', 0);
+ define('ZBX_FLAG_EVENT', 1);
+
define('HTTPTEST_STATUS_ACTIVE', 0);
define('HTTPTEST_STATUS_DISABLED', 1);
diff --git a/frontends/php/include/events.inc.php b/frontends/php/include/events.inc.php
index 2d31ab0a..459b58e0 100644
--- a/frontends/php/include/events.inc.php
+++ b/frontends/php/include/events.inc.php
@@ -101,7 +101,7 @@
get_node_name_by_elid($row['triggerid']),
$hostid == 0 ? $row['host'] : null,
new CLink(
- expand_trigger_description_by_data($row),
+ expand_trigger_description_by_data($row, ZBX_FLAG_EVENT),
"tr_events.php?triggerid=".$row["triggerid"],"action"
),
$value,
diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php
index 3eea2f4b..f44fa2cf 100644
--- a/frontends/php/include/items.inc.php
+++ b/frontends/php/include/items.inc.php
@@ -1111,4 +1111,72 @@ COpt::profiling_stop('prepare table');
}
return $lastvalue;
}
+
+ /*
+ * Function: item_get_history
+ *
+ * Description:
+ * Get value from history
+ *
+ * Peremeters:
+ * itemid - item ID
+ * index - 0 - last value, 1 - prev value, 2 - prev prev, and so on
+ * if index=0, clock is used
+ *
+ * Author:
+ * Alexei Vladishev
+ *
+ * Comments:
+ *
+ */
+ function item_get_history($db_item,$index = 1, $clock = 0)
+ {
+ $value = NULL;
+
+ switch($db_item["value_type"])
+ {
+ case ITEM_VALUE_TYPE_FLOAT:
+ $table = "history";
+ break;
+ case ITEM_VALUE_TYPE_UINT64:
+ $table = "history_uint";
+ break;
+ case ITEM_VALUE_TYPE_TEXT:
+ $table = "history_text";
+ break;
+ case ITEM_VALUE_TYPE_STR:
+ $table = "history_str";
+ break;
+ case ITEM_VALUE_TYPE_LOG:
+ default:
+ $table = "history_log";
+ break;
+ }
+ if($index == 0)
+ {
+ $sql="select value from $table where itemid=".$db_item["itemid"]." and clock<=$clock order by clock desc";
+ $result = DBselect($sql, 1);
+ $row = DBfetch(DBselect($sql, 1));
+ if($row)
+ {
+ $value = $row["value"];
+ }
+ }
+ else
+ {
+ $sql="select value from $table where itemid=".$db_item["itemid"]." order by clock desc";
+ $result = DBselect($sql, $index);
+ $num=1;
+ while($row = DBfetch($result))
+ {
+ if($num == $index)
+ {
+ $value = $row["value"];
+ break;
+ }
+ $num++;
+ }
+ }
+ return $value;
+ }
?>
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index d9879044..cc955c55 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -1094,7 +1094,7 @@
* Comments: !!! Don't forget sync code with C !!!
*
*/
- function expand_trigger_description_by_data($row)
+ function expand_trigger_description_by_data($row, $flag = ZBX_FLAG_TRIGGER)
{
if($row)
{
@@ -1109,8 +1109,109 @@
' where i.itemid=f.itemid and f.triggerid=t.triggerid and '.
' t.triggerid='.$row["triggerid"]));
- if(is_null($row2["lastvalue"])) $row["lastvalue"] = "{ITEM.LASTVALUE}";
- $description = str_replace("{ITEM.LASTVALUE}", $row2["lastvalue"],$description);
+ if($row2["value_type"]!=ITEM_VALUE_TYPE_LOG)
+ {
+ $description = str_replace("{ITEM.LASTVALUE}", $row2["lastvalue"],$description);
+ }
+ else
+ {
+ $row3=DBfetch(DBselect("select max(clock) as max from history_log where itemid=".$row2["itemid"]));
+ if($row3 && !is_null($row3["max"]))
+ {
+ $row4=DBfetch(DBselect("select value from history_log where itemid=".$row2["itemid"]." and clock=".$row3["max"]));
+ $description = str_replace("{ITEM.LASTVALUE}", $row4["value"],$description);
+ }
+ }
+ }
+ if(strstr($description,'{ITEM.VALUE}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,1,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,1,$row['clock']);
+ $description = str_replace("{ITEM.VALUE}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE1}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,1,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,1,$row['clock']);
+ $description = str_replace("{ITEM.VALUE1}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE2}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,2,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,2,$row['clock']);
+ $description = str_replace("{ITEM.VALUE2}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE3}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,3,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,3,$row['clock']);
+ $description = str_replace("{ITEM.VALUE3}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE4}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,4,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,4,$row['clock']);
+ $description = str_replace("{ITEM.VALUE4}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE5}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,5,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,5,$row['clock']);
+ $description = str_replace("{ITEM.VALUE5}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE6}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,6,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,6,$row['clock']);
+ $description = str_replace("{ITEM.VALUE6}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE7}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,7,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,7,$row['clock']);
+ $description = str_replace("{ITEM.VALUE7}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE8}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,8,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,8,$row['clock']);
+ $description = str_replace("{ITEM.VALUE8}",
+ $value,
+ $description);
+ }
+ if(strstr($description,'{ITEM.VALUE9}'))
+ {
+ $value=($flag==ZBX_FLAG_TRIGGER)?
+ trigger_get_func_value($row["expression"],ZBX_FLAG_TRIGGER,9,1):
+ trigger_get_func_value($row["expression"],ZBX_FLAG_EVENT,9,$row['clock']);
+ $description = str_replace("{ITEM.VALUE9}",
+ $value,
+ $description);
}
}
else
@@ -2039,4 +2140,71 @@
$level = 0;
return trigger_dependent_rec($triggerid, $level);
}
+
+ /*
+ * Function: trigger_get_N_functionid
+ *
+ * Description:
+ * get functionid of Nth function of trigger expression
+ *
+ * Author:
+ * Alexei Vladishev
+ *
+ * Comments:
+ *
+ */
+ function trigger_get_N_functionid($expression, $function)
+ {
+ $result = NULL;
+
+ $arr=split('[\{\}]',$expression);
+ $num=1;
+ foreach($arr as $id)
+ {
+ if(is_numeric($id))
+ {
+ if($num == $function)
+ {
+ $result = $id;
+ break;
+ }
+ $num++;
+ }
+ }
+ return $result;
+ }
+
+ /*
+ * Function: trigger_get_func_value
+ *
+ * Description:
+ * get historical value of Nth function of trigger expression
+ * flag: ZBX_FLAG_EVENT - get value by clock, ZBX_FLAG_TRIGGR - get value by index
+ * ZBX_FLAG_TRIGGER, param: 0 - last value, 1 - prev, 2 - prev prev, etc
+ * ZBX_FLAG_EVENT, param: event timestamp
+ *
+ * Author:
+ * Alexei Vladishev
+ *
+ * Comments:
+ *
+ */
+ function trigger_get_func_value($expression, $flag, $function, $param)
+ {
+ $result = NULL;
+
+ $functionid=trigger_get_N_functionid($expression,$function);
+ if(isset($functionid))
+ {
+ $row=DBfetch(DBselect('select i.* from items i, functions f '.
+ ' where i.itemid=f.itemid and f.functionid='.$functionid));
+ if($row)
+ {
+ $result=($flag == ZBX_FLAG_TRIGGER)?
+ item_get_history($row, $param):
+ item_get_history($row, 0, $param);
+ }
+ }
+ return $result;
+ }
?>