summaryrefslogtreecommitdiffstats
path: root/frontends/php/include
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-04-28 10:03:56 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-04-28 10:03:56 +0000
commit55d8804ff83518a46e6742ebd0ba6e0fa6df2d8b (patch)
tree497b1375f551fd74294265a401b95a2c093d297b /frontends/php/include
parent55963f6c918d2503019875cac9307091b908eaaa (diff)
- improved graphs, added 'Working time' displaying (Eugene)
- added 'Working time' configuration (Eugene) git-svn-id: svn://svn.zabbix.com/trunk@2786 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
-rw-r--r--frontends/php/include/classes/graph.inc.php70
-rw-r--r--frontends/php/include/config.inc.php178
-rw-r--r--frontends/php/include/forms.inc.php25
-rw-r--r--frontends/php/include/graphs.inc.php20
-rw-r--r--frontends/php/include/locales/en_gb.inc.php2
5 files changed, 281 insertions, 14 deletions
diff --git a/frontends/php/include/classes/graph.inc.php b/frontends/php/include/classes/graph.inc.php
index 583152f8..da894065 100644
--- a/frontends/php/include/classes/graph.inc.php
+++ b/frontends/php/include/classes/graph.inc.php
@@ -31,6 +31,8 @@
var $shiftY;
var $border;
+ var $m_showWorkPeriod;
+
var $yaxistype;
var $yaxismin;
var $yaxismax;
@@ -132,6 +134,8 @@
$this->yaxistype=GRAPH_YAXIS_TYPE_CALCULATED;
$this->yaxisright=0;
$this->yaxisleft=0;
+
+ $this->m_showWorkPeriod = 1;
$this->count=array();
$this->min=array();
@@ -153,6 +157,11 @@
}
+ function ShowWorkPeriod($value)
+ {
+ $this->m_showWorkPeriod = $value;
+ }
+
function addItem($itemid, $axis)
{
$this->items[$this->num]=get_item_by_itemid($itemid);
@@ -341,6 +350,62 @@
}
}
+ function drawWorkPeriod()
+ {
+ if($this->m_showWorkPeriod != 1) return;
+ if($this->period > 2678400) return; // > 31*24*3600 (month)
+
+ $workPeriodColor = ImageColorAllocate($this->im,230,230,230);
+
+ $db_work_period = DBselect("select work_period from config");
+ $work_period = DBfetch($db_work_period);
+ if(!$work_period)
+ return;
+
+ $periods = parse_period($work_period['work_period']);
+ if(!$periods)
+ return;
+
+ $now = time();
+ if(isset($this->stime))
+ {
+# $this->to_time=$this->stime+24*3600;
+# $this->from_time=$this->stime;
+ $this->from_time=$this->stime;
+ $this->to_time=$this->stime+$this->period;
+ }
+ else
+ {
+ $this->to_time=$now-3600*$this->from;
+ $this->from_time=$this->to_time-$this->period;
+ }
+ $from = $this->from_time;
+ $max_time = $this->to_time;
+
+ $start = find_period_start($periods,$from);
+ $end = -1;
+
+ while($start < $max_time && $start > 0)
+ {
+ $end = find_period_end($periods,$start);
+ if($end >= ($max_time) || $end < 0) $end = $max_time;
+
+ $x1 = round((($start-$from)*$this->sizeX)/$this->period) + $this->shiftXleft;
+ $x2 = round((($end-$from)*$this->sizeX)/$this->period) + $this->shiftXleft;
+
+ //draw rectangle
+ ImageFilledRectangle(
+ $this->im,
+ $x1,
+ $this->shiftY,
+ $x2,
+ $this->sizeY+$this->shiftY,
+ $workPeriodColor);
+
+ $start = find_period_start($periods,$end+60);
+ }
+ }
+
function checkPermissions()
{
if(!check_right("Item","R",$this->items[0]["itemid"]))
@@ -624,9 +689,11 @@
// $this->im = imagecreate($this->sizeX+$this->shiftX+61,$this->sizeY+2*$this->shiftY+40);
-// Header( "Content-type: text/html");
+ Header( "Content-type: text/html");
+/*
Header( "Content-type: image/png");
Header( "Expires: Mon, 17 Aug 1998 12:51:50 GMT");
+/**/
check_authorisation();
@@ -654,6 +721,7 @@
$this->selectData();
+ $this->drawWorkPeriod();
$this->drawGrid();
// ImageString($this->im, 0, 100, 100, $this->shiftXright, $this->colors["Red"]);
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php
index 6b5c5e83..5cbc23ac 100644
--- a/frontends/php/include/config.inc.php
+++ b/frontends/php/include/config.inc.php
@@ -687,6 +687,162 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } // DEBUG INFO!!!
show_messages(FALSE,'',$msg);
}
+ function parse_period($str)
+ {
+ $out = NULL;
+ $str = trim($str,';');
+ $periods = split(';',$str);
+ foreach($periods as $preiod)
+ {
+ if(!ereg('^([1-7])-([1-7]),([0-9]{1,2}):([0-9]{1,2})-([0-9]{1,2}):([0-9]{1,2})$', $preiod, $arr))
+ return NULL;
+ for($i = $arr[1]; $i <= $arr[2]; $i++)
+ {
+ if(!isset($out[$i])) $out[$i] = array();
+ array_push($out[$i],
+ array(
+ 'start_h' => $arr[3],
+ 'start_m' => $arr[4],
+ 'end_h' => $arr[5],
+ 'end_m' => $arr[6]
+ ));
+ }
+ }
+//print_r($out);
+ return $out;
+ }
+
+ function find_period_start($periods,$time)
+ {
+ $date = getdate($time);
+ $wday = $date['wday'] == 0 ? 7 : $date['wday'];
+ $curr = $date['hours']*100+$date['minutes'];
+//$debug = 1;
+ if(isset($periods[$wday]))
+ {
+ $next_h = -1;
+ $next_m = -1;
+ foreach($periods[$wday] as $period)
+ {
+ $per_start = $period['start_h']*100+$period['start_m'];
+ if($per_start > $curr)
+ {
+ if(($next_h == -1 && $next_m == -1) || ($per_start < ($next_h*100 + $next_m)))
+ {
+ $next_h = $period['start_h'];
+ $next_m = $period['start_m'];
+ }
+ continue;
+ }
+ $per_end = $period['end_h']*100+$period['end_m'];
+ if($per_end < $curr) continue;
+ return $time;
+ }
+ if($next_h >= 0 && $next_m >= 0)
+ {
+ return mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']);
+ }
+ }
+ for($days=1; $days < 7 ; ++$days)
+ {
+ $new_wday = (($wday + $days - 1)%7 + 1);
+ if(isset($periods[$new_wday ]))
+ {
+ $next_h = -1;
+ $next_m = -1;
+ foreach($periods[$new_wday] as $period)
+ {
+ $per_start = $period['start_h']*100+$period['start_m'];
+ if(($next_h == -1 && $next_m == -1) || ($per_start < ($next_h*100 + $next_m)))
+ {
+ $next_h = $period['start_h'];
+ $next_m = $period['start_m'];
+ }
+ }
+ if($next_h >= 0 && $next_m >= 0)
+ {
+ return mktime($next_h, $next_m, 0, $date['mon'], $date['mday'] + $days, $date['year']);
+ }
+ }
+ }
+ return -1;
+ }
+
+ function find_period_end($periods,$time)
+ {
+ $date = getdate($time);
+ $wday = $date['wday'] == 0 ? 7 : $date['wday'];
+ $curr = $date['hours']*100+$date['minutes'];
+
+ if(isset($periods[$wday]))
+ {
+ $next_h = -1;
+ $next_m = -1;
+ foreach($periods[$wday] as $period)
+ {
+ $per_start = $period['start_h']*100+$period['start_m'];
+ $per_end = $period['end_h']*100+$period['end_m'];
+ if($per_start > $curr) continue;
+ if($per_end < $curr) continue;
+
+ if(($next_h == -1 && $next_m == -1) || ($per_end > ($next_h*100 + $next_m)))
+ {
+ $next_h = $period['end_h'];
+ $next_m = $period['end_m'];
+ }
+ }
+ if($next_h >= 0 && $next_m >= 0)
+ {
+ $new_time = mktime($next_h, $next_m, 0, $date['mon'], $date['mday'], $date['year']);
+
+ if($new_time == $time)
+ return $time;
+
+ $next_time = find_period_end($periods,$new_time);
+ if($next_time < 0)
+ return $new_time;
+ else
+ return $next_time;
+ }
+ }
+ return -1;
+ }
+
+ function validate_period(&$str)
+ {
+/* // simple check
+ $per_expr = '[1-7]-[1-7],[0-9]{1,2}:[0-9]{1,2}-[0-9]{1,2}:[0-9]{1,2}';
+ $regexp = '^'.$per_expr.'(;'.$per_expr.')*[;]?$';
+ if(!ereg($regexp, $str, $arr))
+ return -1;
+
+ return 0;
+*/
+ $str = trim($str,';');
+ $out = "";
+ $periods = split(';',$str);
+ foreach($periods as $preiod)
+ {
+ // arr[idx] 1 2 3 4 5 6
+ if(!ereg('^([1-7])-([1-7]),([0-9]{1,2}):([0-9]{1,2})-([0-9]{1,2}):([0-9]{1,2})$', $preiod, $arr))
+ return -1;
+
+ if($arr[1] > $arr[2]) // check week day
+ return -1;
+ if($arr[3] > 23 || $arr[5] > 23) // check hour
+ return -1;
+ if($arr[4] > 59 || $arr[6] > 59) // check min
+ return -1;
+ if(($arr[3] * 100 + $arr[4]) >= ($arr[5] * 100 + $arr[6])) // check time period
+ return -1;
+
+ $out .= sprintf("%d-%d,%02d:%02d-%02d:%02d",$arr[1],$arr[2],$arr[3],$arr[4],$arr[5],$arr[6]).';';
+ }
+ $str = $out;
+//parse_period($str);
+ return 0;
+ }
+
function validate_float($str)
{
// echo "Validating float:$str<br>";
@@ -1481,6 +1637,12 @@ COpt::profiling_start("page");
function add_media( $userid, $mediatypeid, $sendto, $severity, $active, $period)
{
+ if(validate_period($period) != 0)
+ {
+ error("Icorrect time period");
+ return NULL;
+ }
+
$c=count($severity);
$s=0;
for($i=0;$i<$c;$i++)
@@ -1495,6 +1657,12 @@ COpt::profiling_start("page");
function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active, $period)
{
+ if(validate_period($period) != 0)
+ {
+ error("Icorrect time period");
+ return NULL;
+ }
+
$c=count($severity);
$s=0;
for($i=0;$i<$c;$i++)
@@ -1530,17 +1698,23 @@ COpt::profiling_start("page");
# Update configuration
// function update_config($smtp_server,$smtp_helo,$smtp_email,$alarm_history,$alert_history)
- function update_config($alarm_history,$alert_history,$refresh_unsupported)
+ function update_config($alarm_history,$alert_history,$refresh_unsupported,$work_period)
{
if(!check_right("Configuration of Zabbix","U",0))
{
error("Insufficient permissions");
return 0;
}
+ if(validate_period($work_period) != 0)
+ {
+ error("Icorrect work period");
+ return NULL;
+ }
// $sql="update config set smtp_server='$smtp_server',smtp_helo='$smtp_helo',smtp_email='$smtp_email',alarm_history=$alarm_history,alert_history=$alert_history";
- $sql="update config set alarm_history=$alarm_history,alert_history=$alert_history,refresh_unsupported=$refresh_unsupported";
+ $sql="update config set alarm_history=$alarm_history,alert_history=$alert_history,refresh_unsupported=$refresh_unsupported,".
+ "work_period=".zbx_dbstr($work_period);
return DBexecute($sql);
}
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index b876bce4..04bc9ab3 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -703,8 +703,7 @@
{
$frmGraph->AddVar("graphid",$_REQUEST["graphid"]);
- $result=DBselect("select g.graphid,g.name,g.width,g.height,g.yaxistype,".
- "g.yaxismin,g.yaxismax from graphs g where graphid=".$_REQUEST["graphid"]);
+ $result=DBselect("select * from graphs where graphid=".$_REQUEST["graphid"]);
$row=DBfetch($result);
$frmGraph->SetTitle(S_GRAPH." \"".$row["name"]."\"");
}
@@ -717,6 +716,7 @@
$yaxistype =$row["yaxistype"];
$yaxismin =$row["yaxismin"];
$yaxismax =$row["yaxismax"];
+ $showworkperiod = $row["show_work_period"];
} else {
$name =get_request("name" ,"");
$width =get_request("width" ,900);
@@ -724,11 +724,14 @@
$yaxistype =get_request("yaxistype",GRAPH_YAXIS_TYPE_CALCULATED);
$yaxismin =get_request("yaxismin" ,0.00);
$yaxismax =get_request("yaxismax" ,100.00);
+ $showworkperiod = get_request("show_work_period",1);
+
}
$frmGraph->AddRow(S_NAME,new CTextBox("name",$name,32));
$frmGraph->AddRow(S_WIDTH,new CTextBox("width",$width,5));
$frmGraph->AddRow(S_HEIGHT,new CTextBox("height",$height,5));
+ $frmGraph->AddRow(S_SHOW_WORKING_TIME,new CCheckBox("showworkperiod",$showworkperiod,NULL,NULL,1));
$cmbYType = new CComboBox("yaxistype",$yaxistype,"submit()");
$cmbYType->AddItem(GRAPH_YAXIS_TYPE_CALCULATED,S_CALCULATED);
@@ -1870,6 +1873,7 @@
$frmHouseKeep->SetHelp("web.config.housekeeper.php");
$frmHouseKeep->AddVar("config",get_request("config",0));
$frmHouseKeep->AddVar("refresh_unsupported",$config["refresh_unsupported"]);
+ $frmHouseKeep->AddVar("work_period",$config["work_period"]);
$frmHouseKeep->AddRow(S_DO_NOT_KEEP_ACTIONS_OLDER_THAN,
new CTextBox("alert_history",$config["alert_history"],8));
$frmHouseKeep->AddRow(S_DO_NOT_KEEP_EVENTS_OLDER_THAN,
@@ -1878,6 +1882,22 @@
$frmHouseKeep->Show();
}
+ function insert_work_period_form()
+ {
+ $config=select_config();
+
+ $frmHouseKeep = new CFormTable(S_WORKING_TIME,"config.php");
+ $frmHouseKeep->SetHelp("web.config.workperiod.php");
+ $frmHouseKeep->AddVar("config",get_request("config",7));
+ $frmHouseKeep->AddVar("alert_history",$config["alert_history"]);
+ $frmHouseKeep->AddVar("alarm_history",$config["alarm_history"]);
+ $frmHouseKeep->AddVar("refresh_unsupported",$config["refresh_unsupported"]);
+ $frmHouseKeep->AddRow(S_WORKING_TIME,
+ new CTextBox("work_period",$config["work_period"],35));
+ $frmHouseKeep->AddItemToBottomRow(new CButton("save",S_SAVE));
+ $frmHouseKeep->Show();
+ }
+
function insert_other_parameters_form()
{
$config=select_config();
@@ -1887,6 +1907,7 @@
$frmHouseKeep->AddVar("config",get_request("config",5));
$frmHouseKeep->AddVar("alert_history",$config["alert_history"]);
$frmHouseKeep->AddVar("alarm_history",$config["alarm_history"]);
+ $frmHouseKeep->AddVar("work_period",$config["work_period"]);
$frmHouseKeep->AddRow(S_REFRESH_UNSUPPORTED_ITEMS,
new CTextBox("refresh_unsupported",$config["refresh_unsupported"],8));
$frmHouseKeep->AddItemToBottomRow(new CButton("save",S_SAVE));
diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php
index 98eb8462..f50fad40 100644
--- a/frontends/php/include/graphs.inc.php
+++ b/frontends/php/include/graphs.inc.php
@@ -94,7 +94,7 @@
# Add Graph
- function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$templateid=0)
+ function add_graph($name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$templateid=0)
{
if(!check_right("Graph","A",0))
{
@@ -103,9 +103,9 @@
}
$result=DBexecute("insert into graphs".
- " (name,width,height,yaxistype,yaxismin,yaxismax,templateid)".
+ " (name,width,height,yaxistype,yaxismin,yaxismax,templateid,show_work_period)".
" values (".zbx_dbstr($name).",$width,$height,$yaxistype,$yaxismin,".
- " $yaxismax,$templateid)");
+ " $yaxismax,$templateid,$showworkperiod)");
$graphid = DBinsert_id($result,"graphs","graphid");
if($graphid)
{
@@ -116,7 +116,7 @@
# Update Graph
- function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$templateid=0)
+ function update_graph($graphid,$name,$width,$height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$templateid=0)
{
if(!check_right("Graph","U",0))
{
@@ -130,14 +130,15 @@
while($graph = DBfetch($graphs))
{
$result = update_graph($graph["graphid"],$name,$width,
- $height,$yaxistype,$yaxismin,$yaxismax,$graphid);
+ $height,$yaxistype,$yaxismin,$yaxismax,$showworkperiod,$graphid);
if(!$result)
return $result;
}
$result = DBexecute("update graphs set name=".zbx_dbstr($name).",width=$width,height=$height,".
- "yaxistype=$yaxistype,yaxismin=$yaxismin,yaxismax=$yaxismax,templateid=$templateid".
- " where graphid=$graphid");
+ "yaxistype=$yaxistype,yaxismin=$yaxismin,yaxismax=$yaxismax,templateid=$templateid,".
+ "show_work_period=$showworkperiod ".
+ "where graphid=$graphid");
if($result)
{
info("Graph '".$g_graph["name"]."' updated");
@@ -214,7 +215,7 @@
while($chd_host = DBfetch($chd_hosts))
{
$new_graphid = add_graph($graph["name"],$graph["width"],$graph["height"],
- $graph["yaxistype"],$graph["yaxismin"],$graph["yaxismax"],
+ $graph["yaxistype"],$graph["yaxismin"],$graph["yaxismax"],$graph["show_work_period"],
$graph["graphid"]);
if(!$new_graphid)
@@ -449,7 +450,8 @@
{
$db_graph = get_graph_by_graphid($graphid);
$new_graphid = add_graph($db_graph["name"],$db_graph["width"],$db_graph["height"],
- $db_graph["yaxistype"],$db_graph["yaxismin"],$db_graph["yaxismax"],$graphid);
+ $db_graph["yaxistype"],$db_graph["yaxismin"],$db_graph["yaxismax"],$graph["show_work_period"],
+ $graphid);
if(!$new_graphid)
return $new_graphid;
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index f6053e80..0e12bc89 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -263,6 +263,7 @@
"S_CREATE_MEDIA_TYPE"=> "Create Media Type",
"S_CREATE_IMAGE"=> "Create Image",
"S_CREATE_RULE"=> "Create Rule",
+ "S_WORKING_TIME"=> "Working time",
// Latest values
"S_LATEST_VALUES"=> "Latest values",
@@ -317,6 +318,7 @@
"S_CALCULATED"=> "Calculated",
"S_FIXED"=> "Fixed",
"S_CREATE_GRAPH"=> "Create Graph",
+ "S_SHOW_WORKING_TIME"=> "Show working time",
// history.php
"S_LAST_HOUR_GRAPH"=> "Last hour graph",