summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-05-10 14:27:36 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2007-05-10 14:27:36 +0000
commitfa0fcc207fcc36a40bfc3b31685e0b96a8a46550 (patch)
tree77979ff64a6ce0bad8662d8bca07363a297002ba /frontends/php/include
parent5dbc4c82d74ab518d0993d7164bc34b926d9ced6 (diff)
downloadzabbix-fa0fcc207fcc36a40bfc3b31685e0b96a8a46550.tar.gz
zabbix-fa0fcc207fcc36a40bfc3b31685e0b96a8a46550.tar.xz
zabbix-fa0fcc207fcc36a40bfc3b31685e0b96a8a46550.zip
- added availability to yse ')(' characters in item keys (Eugene)
- improved management of trigger (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@4119 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/classes/ccheckbox.inc.php6
-rw-r--r--frontends/php/include/config.inc.php109
-rw-r--r--frontends/php/include/forms.inc.php13
-rw-r--r--frontends/php/include/locales/en_gb.inc.php2
-rw-r--r--frontends/php/include/triggers.inc.php278
5 files changed, 165 insertions, 243 deletions
diff --git a/frontends/php/include/classes/ccheckbox.inc.php b/frontends/php/include/classes/ccheckbox.inc.php
index 2d616da8..84bf8eb3 100644
--- a/frontends/php/include/classes/ccheckbox.inc.php
+++ b/frontends/php/include/classes/ccheckbox.inc.php
@@ -66,8 +66,7 @@
foreach($this->object_name as $obj_name)
{
if(empty($obj_name)) continue;
- $action .= 'visibility_status_changeds(this.checked, \''.$obj_name.'\','.
- ' \''.zbx_jsstr($this->replace_to).'\'); ';
+ $action .= 'visibility_status_changeds(this.checked, '.zbx_jsvalue($obj_name).','.zbx_jsvalue($this->replace_to).');';
}
parent::CCheckBox($name, $value, $action, '1');
@@ -84,8 +83,7 @@
foreach($this->object_name as $obj_name)
{
if(empty($obj_name)) continue;
- zbx_add_post_js('visibility_status_changeds(false, "'.$obj_name.'", "'.
- zbx_jsstr($this->replace_to).'");');
+ zbx_add_post_js('visibility_status_changeds(false,'.zbx_jsvalue($obj_name).','.zbx_jsvalue($this->replace_to).');');
}
}
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 0badb8c4..855ba764 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -218,20 +218,6 @@ function TODO($msg) { echo "TODO: ".$msg.BR; } // DEBUG INFO!!!
/* function:
- * zbx_jsstr
- *
- * description:
- * convert PHP string variable to string
- * for using in JavaScrip block.
- *
- * author: Eugene Grigorjev
- */
- function zbx_jsstr($str)
- {
- return htmlspecialchars(str_replace("\n", '\n', str_replace("\r", '', $str)));
- }
-
- /* function:
* zbx_jsvalue
*
* description:
@@ -245,7 +231,11 @@ function TODO($msg) { echo "TODO: ".$msg.BR; } // DEBUG INFO!!!
if(!is_array($value))
{
if(is_object($value)) return unpack_object($value);
- if(is_string($value)) return '\''.str_replace('\'','\\\'',str_replace("\n", '\n', str_replace("\r", '', ($value)))).'\'';
+ if(is_string($value)) return '\''.str_replace('\'','\\\'', /* ' => \' */
+ str_replace("\n", '\n', /* LF => \n */
+ str_replace("\\", "\\\\", /* \ => \\ */
+ str_replace("\r", '', /* CR => remove */
+ ($value))))).'\'';
if(is_null($value)) return 'null';
return strval($value);
}
@@ -901,95 +891,6 @@ else
else return validate_float($str);
}
-// Does expression match server:key.function(param) ?
- function validate_simple_expression($expression)
- {
- global $ZBX_CURNODEID;
-
-// echo "Validating simple:$expression<br>";
- if (eregi('^\{([0-9a-zA-Z\_\.[.-.]\$]+)\:([]\[0-9a-zA-Z\_\*\/\.\,\:\(\)\+ [.-.]\$]+)\.([a-z]{3,11})\(([#0-9a-zA-Z\_\/\.\,[:space:]]+)\)\}$', $expression, $arr))
- {
- $host=$arr[1];
- $key=$arr[2];
- $function=$arr[3];
- $parameter=$arr[4];
-
-//SDI($host);
-//SDI($key);
-//SDI($function);
-//SDI($parameter);
-
- $sql="select count(*) as cnt from hosts h,items i where h.host=".zbx_dbstr($host).
- " and i.key_=".zbx_dbstr($key)." and h.hostid=i.hostid ".
- " and ".DBid2nodeid('h.hostid').'='.$ZBX_CURNODEID;
-//SDI($sql);
- $row=DBfetch(DBselect($sql));
- if($row["cnt"]==0)
- {
- error("No such host ($host) or monitored parameter ($key)");
- return -1;
- }
- elseif($row["cnt"]!=1)
- {
- error("Too many hosts ($host) with parameter ($key)");
- return -1;
- }
-
- if( ($function!="last")&&
- ($function!="diff")&&
- ($function!="min") &&
- ($function!="max") &&
- ($function!="avg") &&
- ($function!="sum") &&
- ($function!="count") &&
- ($function!="prev")&&
- ($function!="delta")&&
- ($function!="change")&&
- ($function!="abschange")&&
- ($function!="nodata")&&
- ($function!="time")&&
- ($function!="dayofweek")&&
- ($function!="date")&&
- ($function!="now")&&
- ($function!="str")&&
- ($function!="fuzzytime")&&
- ($function!="logseverity")&&
- ($function!="logsource")&&
- ($function!="regexp")
- )
- {
- error("Unknown function [$function]");
- return -1;
- }
-
-
- if(in_array($function,array("last","diff","count",
- "prev","change","abschange","nodata","time","dayofweek",
- "date","now","fuzzytime"))
- && (validate_float($parameter)!=0) )
- {
- error("[$parameter] is not a float");
- return -1;
- }
-
- if(in_array($function,array("min","max","avg","sum",
- "delta"))
- && (validate_ticks($parameter)!=0) )
- {
- error("[$parameter] is not a float");
- return -1;
- }
- }
- # Process macros
- else if($expression!="{TRIGGER.VALUE}")
-
- {
- error("Expression [$expression] does not match to [server:key.func(param)]");
- return -1;
- }
- return 0;
- }
-
# Show screen cell containing plain text values
function& get_screen_plaintext($itemid,$elements)
{
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 162dacb4..c78b14f7 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -2244,10 +2244,10 @@
$frmTrig->AddRow(S_NAME, new CTextBox("description",$description,90, $limited));
$frmTrig->AddRow(S_EXPRESSION, array(
new CTextBox("expression",$expression,75, $limited),
- new CButton('insert',S_INSERT,
+ ($limited ? null : new CButton('insert',S_INSERT,
"return PopUp('popup_trexpr.php?dstfrm=".$frmTrig->GetName().
"&dstfld1=expression&srctbl=expression".
- "&srcfld1=expression&expression=' + escape(GetSelectedText(this.form.elements['expression'])),700,200);")
+ "&srcfld1=expression&expression=' + escape(GetSelectedText(this.form.elements['expression'])),700,200);"))
));
/* dependences */
@@ -2304,9 +2304,12 @@
$frmTrig->AddItemToBottomRow(SPACE);
$frmTrig->AddItemToBottomRow(new CButton("clone",S_CLONE));
$frmTrig->AddItemToBottomRow(SPACE);
- $frmTrig->AddItemToBottomRow(new CButtonDelete("Delete trigger?",
- url_param("form").url_param("groupid").url_param("hostid").
- url_param("triggerid")));
+ if( !$limited )
+ {
+ $frmTrig->AddItemToBottomRow(new CButtonDelete("Delete trigger?",
+ url_param("form").url_param("groupid").url_param("hostid").
+ url_param("triggerid")));
+ }
}
$frmTrig->AddItemToBottomRow(SPACE);
$frmTrig->AddItemToBottomRow(new CButtonCancel(url_param("groupid").url_param("hostid")));
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index c6993331..c091964c 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -465,7 +465,7 @@
'S_COMPARE'=> 'Compare',
// Footer
- 'S_ZABBIX_VER'=> 'ZABBIX 1.3.7',
+ 'S_ZABBIX_VER'=> 'ZABBIX 1.3.8',
'S_COPYRIGHT_BY'=> 'Copyright 2001-2007 by ',
'S_CONNECTED_AS'=> 'Connected as',
'S_SIA_ZABBIX'=> 'SIA Zabbix',
diff --git a/frontends/php/include/triggers.inc.php b/frontends/php/include/triggers.inc.php
index 1d4850b8..d88b45ea 100644
--- a/frontends/php/include/triggers.inc.php
+++ b/frontends/php/include/triggers.inc.php
@@ -168,6 +168,97 @@
' and host in ('.implode(',',$hosts).')');
}
+define('ZBX_EREG_SIMPLE_EXPRESSION_FORMAT',
+ '^\{([0-9a-zA-Z\_\.[.-.]\$]+)\:([]\[0-9a-zA-Z\_\*\/\.\,\:\(\)\+ [.-.]\$]+)\.([a-z]{3,11})\(([#0-9a-zA-Z\_\/\.\,[:space:]]+)\)\}$');
+
+define('ZBX_SIMPLE_EXPRESSION_HOST_ID', 1);
+define('ZBX_SIMPLE_EXPRESSION_KEY_ID', 2);
+define('ZBX_SIMPLE_EXPRESSION_FUNCTION_ID', 3);
+define('ZBX_SIMPLE_EXPRESSION_PARAMETER_ID', 4);
+// Does expression match server:key.function(param) ?
+ function validate_simple_expression($expression)
+ {
+ global $ZBX_CURNODEID;
+
+// echo "Validating simple:$expression<br>";
+ if (eregi(ZBX_EREG_SIMPLE_EXPRESSION_FORMAT, $expression, $arr))
+ {
+ $host = &$arr[ZBX_SIMPLE_EXPRESSION_HOST_ID];
+ $key = &$arr[ZBX_SIMPLE_EXPRESSION_KEY_ID];
+ $function = &$arr[ZBX_SIMPLE_EXPRESSION_FUNCTION_ID];
+ $parameter = &$arr[ZBX_SIMPLE_EXPRESSION_PARAMETER_ID];
+
+ $sql="select count(*) as cnt from hosts h,items i where h.host=".zbx_dbstr($host).
+ " and i.key_=".zbx_dbstr($key)." and h.hostid=i.hostid ".
+ " and ".DBid2nodeid('h.hostid').'='.$ZBX_CURNODEID;
+//SDI($sql);
+ $row=DBfetch(DBselect($sql));
+ if($row["cnt"]==0)
+ {
+ error("No such host ($host) or monitored parameter ($key)");
+ return -1;
+ }
+ elseif($row["cnt"]!=1)
+ {
+ error("Too many hosts ($host) with parameter ($key)");
+ return -1;
+ }
+
+ if( ($function!="last")&&
+ ($function!="diff")&&
+ ($function!="min") &&
+ ($function!="max") &&
+ ($function!="avg") &&
+ ($function!="sum") &&
+ ($function!="count") &&
+ ($function!="prev")&&
+ ($function!="delta")&&
+ ($function!="change")&&
+ ($function!="abschange")&&
+ ($function!="nodata")&&
+ ($function!="time")&&
+ ($function!="dayofweek")&&
+ ($function!="date")&&
+ ($function!="now")&&
+ ($function!="str")&&
+ ($function!="fuzzytime")&&
+ ($function!="logseverity")&&
+ ($function!="logsource")&&
+ ($function!="regexp")
+ )
+ {
+ error("Unknown function [$function]");
+ return -1;
+ }
+
+
+ if(in_array($function,array("last","diff","count",
+ "prev","change","abschange","nodata","time","dayofweek",
+ "date","now","fuzzytime"))
+ && (validate_float($parameter)!=0) )
+ {
+ error("[$parameter] is not a float");
+ return -1;
+ }
+
+ if(in_array($function,array("min","max","avg","sum",
+ "delta"))
+ && (validate_ticks($parameter)!=0) )
+ {
+ error("[$parameter] is not a float");
+ return -1;
+ }
+ }
+ # Process macros
+ else if($expression!="{TRIGGER.VALUE}")
+
+ {
+ error("Expression [$expression] does not match to [server:key.func(param)]");
+ return -1;
+ }
+ return 0;
+ }
+
function validate_expression($expression)
{
// echo "Validating expression: $expression<br>";
@@ -181,11 +272,6 @@
$arr="";
if (eregi('^((.)*)[ ]*(\{((.)*)\})[ ]*((.)*)$', $expression, $arr))
{
-// for($i=0;$i<20;$i++)
-// {
-// if($arr[$i])
-// echo " $i: ",$arr[$i],"<br>";
-// }
if(validate_simple_expression($arr[3])!=0)
{
return -1;
@@ -316,15 +402,21 @@
add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
- $expression = implode_exp($expression,$triggerid);
+ if( null == ($expression = implode_exp($expression,$triggerid)) )
+ {
+ $result = false;
+ }
- DBexecute("update triggers set expression=".zbx_dbstr($expression)." where triggerid=$triggerid");
+ if($result)
+ {
+ DBexecute("update triggers set expression=".zbx_dbstr($expression)." where triggerid=$triggerid");
- reset_items_nextcheck($triggerid);
+ reset_items_nextcheck($triggerid);
- foreach($deps as $val)
- {
- $result = add_trigger_dependency($triggerid, $val);
+ foreach($deps as $val)
+ {
+ $result = add_trigger_dependency($triggerid, $val);
+ }
}
$trig_hosts = get_hosts_by_triggerid($triggerid);
@@ -344,15 +436,17 @@
$child_hosts = get_hosts_by_templateid($trig_host["hostid"]);
while($child_host = DBfetch($child_hosts))
{
- $result = copy_trigger_to_host($triggerid, $child_host["hostid"]);
- if(!$result){
- if($templateid == 0)
- { // delete main trigger (and recursively childs)
- delete_trigger($triggerid);
- }
- return $result;
- }
+ if( !($result = copy_trigger_to_host($triggerid, $child_host["hostid"])))
+ break;
+ }
+ }
+
+ if(!$result){
+ if($templateid == 0)
+ { // delete main trigger (and recursively childs)
+ delete_trigger($triggerid);
}
+ return $result;
}
return $triggerid;
@@ -499,7 +593,7 @@
{
$exp .= "{".$functionid."}";
}
- else if($function_data = DBfetch(DBselect('select h.host,i.key_,f.function,f.parameter,i.itemid,i.value_type'.
+ else if(is_numeric($functionid) && $function_data = DBfetch(DBselect('select h.host,i.key_,f.function,f.parameter,i.itemid,i.value_type'.
' from items i,functions f,hosts h'.
' where functionid='.$functionid.' and i.itemid=f.itemid and h.hostid=i.hostid')))
{
@@ -541,119 +635,44 @@
function implode_exp ($expression, $triggerid)
# Translate localhost:procload.last(0)>10 to {12}>10
{
-// echo "Expression:$expression<br>";
- $exp='';
- $state="";
- for($i=0,$max=strlen($expression); $i<$max; $i++)
+ $short_exp = $expression;
+
+ for($pos=0,$max=strlen($expression); $pos<$max; )
{
- if($expression[$i] == '{')
- {
- if($state=="")
- {
- $host='';
- $key='';
- $function='';
- $parameter='';
- $state='HOST';
- continue;
- }
- }
-// Processing of macros {TRIGGER.VALUE}
- if( ($expression[$i] == '}')&&($state=="HOST") )
- {
- $exp = $exp."{".$host."}";
- $state="";
- continue;
- }
- if( ($expression[$i] == '}')&&($state=="") )
- {
-// echo "HOST:$host<BR>";
-// echo "KEY:$key<BR>";
-// echo "FUNCTION:$function<BR>";
-// echo "PARAMETER:$parameter<BR>";
- $state='';
-
- $res=DBselect("select i.itemid from items i,hosts h".
- " where i.key_=".zbx_dbstr($key).
- " and h.host=".zbx_dbstr($host).
- " and h.hostid=i.hostid");
- $row=DBfetch($res);
+ if ( false === ($simple_start = strpos($expression, '{', $pos)) ) break;
+ if ( false === ($simple_end = strpos($expression, '}', $simple_start)) ) break;
+
+ $pos = $simple_end;
- $itemid=$row["itemid"];
-
- $functionid = get_dbid("functions","functionid");
- $res=DBexecute("insert into functions (functionid,itemid,triggerid,function,parameter)".
- " values ($functionid,$itemid,$triggerid,".zbx_dbstr($function).",".
- zbx_dbstr($parameter).")");
- if(!$res)
- {
- return $res;
- }
+ $simple_exp = substr($expression, $simple_start, $simple_end - $simple_start + 1);
- $exp=$exp.'{'.$functionid.'}';
+ if (!eregi(ZBX_EREG_SIMPLE_EXPRESSION_FORMAT, $simple_exp, $arr)) continue;
- continue;
- }
- if($expression[$i] == '(')
- {
- if($state == "FUNCTION")
- {
- $state='PARAMETER';
- continue;
- }
- }
- if($expression[$i] == ')')
- {
- if($state == "PARAMETER")
- {
- $state='';
- continue;
- }
- }
- if(($expression[$i] == ':') && ($state == "HOST"))
- {
- $state="KEY";
- continue;
- }
- if($expression[$i] == '.')
- {
- if($state == "KEY")
- {
- $state="FUNCTION";
- continue;
- }
- // Support for '.' in KEY
- if($state == "FUNCTION")
- {
- $state="FUNCTION";
- $key=$key.".".$function;
- $function="";
- continue;
- }
- }
- if($state == "HOST")
- {
- $host=$host.$expression[$i];
- continue;
- }
- if($state == "KEY")
- {
- $key=$key.$expression[$i];
- continue;
- }
- if($state == "FUNCTION")
- {
- $function=$function.$expression[$i];
- continue;
- }
- if($state == "PARAMETER")
- {
- $parameter=$parameter.$expression[$i];
- continue;
- }
- $exp=$exp.$expression[$i];
+ $host = &$arr[ZBX_SIMPLE_EXPRESSION_HOST_ID];
+ $key = &$arr[ZBX_SIMPLE_EXPRESSION_KEY_ID];
+ $function = &$arr[ZBX_SIMPLE_EXPRESSION_FUNCTION_ID];
+ $parameter = &$arr[ZBX_SIMPLE_EXPRESSION_PARAMETER_ID];
+
+ $row=DBfetch(DBselect("select i.itemid from items i,hosts h".
+ " where i.key_=".zbx_dbstr($key).
+ " and h.host=".zbx_dbstr($host).
+ " and h.hostid=i.hostid"));
+
+ $itemid=$row["itemid"];
+
+ unset($row);
+
+ $functionid = get_dbid("functions","functionid");
+ if ( !DBexecute("insert into functions (functionid,itemid,triggerid,function,parameter)".
+ " values ($functionid,$itemid,$triggerid,".zbx_dbstr($function).",".
+ zbx_dbstr($parameter).")")) return NULL;
+
+ $short_exp = str_replace($simple_exp, '{'.$functionid.'}', $short_exp);
+
+ unset($simple_exp);
}
- return $exp;
+
+ return $short_exp;
}
function update_trigger_comments($triggerid,$comments)
@@ -881,7 +900,8 @@
return $result;
}
- $expression = implode_exp($expression,$triggerid);
+ $expression = implode_exp($expression,$triggerid); /* errors can be ignored cose function must return NULL */
+
add_event($triggerid,TRIGGER_VALUE_UNKNOWN);
reset_items_nextcheck($triggerid);