diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-09-14 12:44:51 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-09-14 12:44:51 +0000 |
| commit | 3a131834335bf51798f2283f48f1aa002821bf44 (patch) | |
| tree | b252f7946f8956743783b838e427352fe4a1b0f0 | |
| parent | 8755f9643aba3cffc5320321618fbe8e7b78b73b (diff) | |
| download | zabbix-3a131834335bf51798f2283f48f1aa002821bf44.tar.gz zabbix-3a131834335bf51798f2283f48f1aa002821bf44.tar.xz zabbix-3a131834335bf51798f2283f48f1aa002821bf44.zip | |
- 'sql' fixes in 'trunk/frontends/php/popup.php' (Eugene)
- minor fix of 'trunk/src/libs/zbxcommon/misc.c' (Eugene)
- developed SLA calculation periods (Eugene)
- developed flexible update intervals for items (Eugene)
ported r3213 (fix for 'delay_flex' collumn) from 'branches/1.1-lk/'
ported r3202 (flexible update intervals) from 'branches/1.1-lk/'
ported r3207 (SLA calculation periods) from 'branches/1.1-lk/'
git-svn-id: svn://svn.zabbix.com/trunk@3307 97f52cf1-0a1b-0410-bd0e-c28be96e8082
| -rw-r--r-- | ChangeLog | 2 | ||||
| -rw-r--r-- | create/mysql/schema.sql | 16 | ||||
| -rw-r--r-- | create/oracle/schema.sql | 33 | ||||
| -rw-r--r-- | create/postgresql/schema.sql | 17 | ||||
| -rw-r--r-- | frontends/php/include/defines.inc.php | 4 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 54 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 28 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 15 | ||||
| -rw-r--r-- | frontends/php/include/services.inc.php | 281 | ||||
| -rw-r--r-- | frontends/php/items.php | 43 | ||||
| -rw-r--r-- | frontends/php/popup.php | 7 | ||||
| -rw-r--r-- | frontends/php/report3.php | 49 | ||||
| -rw-r--r-- | frontends/php/services.php | 143 | ||||
| -rw-r--r-- | include/common.h | 3 | ||||
| -rw-r--r-- | include/db.h | 3 | ||||
| -rw-r--r-- | src/libs/zbxcommon/misc.c | 108 | ||||
| -rw-r--r-- | src/libs/zbxdbhigh/db.c | 1 | ||||
| -rw-r--r-- | src/libs/zbxlog/log.c | 20 | ||||
| -rw-r--r-- | src/zabbix_server/actions.c | 65 | ||||
| -rw-r--r-- | src/zabbix_server/functions.c | 14 | ||||
| -rw-r--r-- | src/zabbix_server/server.c | 16 | ||||
| -rw-r--r-- | upgrades/dbpatches/1.1_1.3/mysql/patch.sql | 19 | ||||
| -rw-r--r-- | upgrades/dbpatches/1.1_1.3/oracle/patch.sql | 35 | ||||
| -rw-r--r-- | upgrades/dbpatches/1.1_1.3/postgresql/patch.sql | 20 |
24 files changed, 827 insertions, 169 deletions
@@ -1,5 +1,7 @@ Changes for 1.3: + - developed SLA calculation periods (Eugene) + - developed flexible update intervals for items (Eugene) - fixed reversed icons on maps (Eugene) - fixed trigger description substitution in action comporation (Eugene) - fixed trigger description substitution in message subject and body (Eugene) diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql index 2faa7e3d..753f4e46 100644 --- a/create/mysql/schema.sql +++ b/create/mysql/schema.sql @@ -84,6 +84,21 @@ CREATE TABLE services ( ) type=InnoDB; -- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid int(4) NOT NULL auto_increment, + serviceid int(4) DEFAULT '0' NOT NULL, + type int(2) DEFAULT '0' NOT NULL, + ts_from int(4) DEFAULT '0' NOT NULL, + ts_to int(4) DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (timeid), + UNIQUE (serviceid,type,ts_from,ts_to) +) type=InnoDB; + +-- -- Table structure for table 'services_links' -- @@ -429,6 +444,7 @@ CREATE TABLE items ( logtimefmt varchar(64) DEFAULT '' NOT NULL, templateid int(4) DEFAULT '0' NOT NULL, valuemapid int(4) DEFAULT '0' NOT NULL, + delay_flex varchar(255) DEFAULT "" NOT NULL, PRIMARY KEY (itemid), UNIQUE shortname (hostid,key_), diff --git a/create/oracle/schema.sql b/create/oracle/schema.sql index 5fed55e3..5d49033a 100644 --- a/create/oracle/schema.sql +++ b/create/oracle/schema.sql @@ -72,6 +72,38 @@ begin end; / +-- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid number(10) NOT NULL auto_increment, + serviceid number(10) DEFAULT '0' NOT NULL, + type number(3) DEFAULT '0' NOT NULL, + ts_from number(10) DEFAULT '0' NOT NULL, + ts_to number(10) DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT NULL, + CONSTRAINT services_times_pk PRIMARY KEY (timeid) +) type=InnoDB; + +CREATE INDEX services_times_servicid on services_times (serviceid); +CREATE UNIQUE INDEX services_times_uniq on services_times (serviceid,type,ts_from,ts_to); + +create sequence services_times_timeid +start with 20000 +increment by 1 +nomaxvalue; + +create trigger services_times +before insert on services_times +for each row +begin + if (:new.timeid is null or :new.timeid = 0) then + select services_times_timeid.nextval into :new.timeid from dual; + end if; +end; +/ + -- -- Table structure for table 'services_links' @@ -588,6 +620,7 @@ CREATE TABLE items ( logtimefmt varchar2(64) DEFAULT NULL, templateid number(10) DEFAULT '0' NOT NULL, valuemapid number(10) DEFAULT '0' NOT NULL, + delay_flex varchar(255) DEFAULT NULL, CONSTRAINT items_pk PRIMARY KEY (itemid) ); diff --git a/create/postgresql/schema.sql b/create/postgresql/schema.sql index 7db81d67..ff4e9860 100644 --- a/create/postgresql/schema.sql +++ b/create/postgresql/schema.sql @@ -84,6 +84,7 @@ CREATE TABLE items ( logtimefmt varchar(64) DEFAULT '' NOT NULL, templateid int4 DEFAULT '0' NOT NULL, valuemapid int4 DEFAULT '0' NOT NULL, + delay_flex varchar(255) DEFAULT "" NOT NULL, PRIMARY KEY (itemid) -- FOREIGN KEY (hostid) REFERENCES hosts ); @@ -521,6 +522,22 @@ CREATE TABLE services ( ); -- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid serial, + serviceid int4 DEFAULT '0' NOT NULL, + type int2 DEFAULT '0' NOT NULL, + ts_from int4 DEFAULT '0' NOT NULL, + ts_to int4 DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (timeid) +) type=InnoDB; + +CREATE UNIQUE INDEX services_times_uniq on services_times (serviceid,type,ts_from,ts_to); + +-- -- Table structure for table 'services_links' -- diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index b02009e7..7604be37 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -214,6 +214,10 @@ define("CALC_FNC_ALL", 7); + define("SERVICE_TIME_TYPE_UPTIME", 0); + define("SERVICE_TIME_TYPE_DOWNTIME", 1); + define("SERVICE_TIME_TYPE_ONETIME_DOWNTIME", 2); + /* Support for PHP5. PHP5 does not have $HTTP_..._VARS */ if (!function_exists('version_compare')) { diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index a5a82dad..a8b1044c 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -292,6 +292,7 @@ $delta = get_request("delta" ,0); $trends = get_request("trends" ,365); $applications = get_request("applications" ,array()); + $delay_flex = get_request("delay_flex" ,array()); $snmpv3_securityname = get_request("snmpv3_securityname" ,""); $snmpv3_securitylevel = get_request("snmpv3_securitylevel" ,0); @@ -339,6 +340,7 @@ $hostid = $row["hostid"]; $delta = $row["delta"]; $trends = $row["trends"]; + $db_delay_flex = $row["delay_flex"]; $snmpv3_securityname = $row["snmpv3_securityname"]; $snmpv3_securitylevel = $row["snmpv3_securitylevel"]; @@ -354,8 +356,48 @@ if(in_array($db_app["applicationid"],$applications)) continue; array_push($applications,$db_app["applicationid"]); } - + + if(isset($db_delay_flex)) + { + $arr_of_dellays = explode(";",$db_delay_flex); + foreach($arr_of_dellays as $one_db_delay) + { + @list($one_delay,$one_time_period) = explode("/",$one_db_delay); + if(!isset($one_delay) || !isset($one_time_period)) continue; + + array_push($delay_flex,array("delay"=>$one_delay,"period"=>$one_time_period)); + } + } } + + $delay_flex_el = array(); + $i = 0; + foreach($delay_flex as $val) + { + if(!isset($val["delay"]) && !isset($val["period"])) continue; + + array_push($delay_flex_el, + array( + new CCheckBox("rem_delay_flex[]", 'no', NULL,$i), + $val["delay"], + " sec at ", + $val["period"] + ), + BR); + $frmItem->AddVar("delay_flex[".$i."][delay]", $val['delay']); + $frmItem->AddVar("delay_flex[".$i."][period]", $val['period']); + $i++; + if($i >= 7) break; /* limit count of intervals + * 7 intervals by 30 symbols = 210 characters + * db storage field is 256 + */ + } + + if(count($delay_flex_el)==0) + array_push($delay_flex_el, "No flexible intervals"); + else + array_push($delay_flex_el, new CButton('del_delay_flex','delete selected')); + if(count($applications)==0) array_push($applications,0); if(isset($_REQUEST["itemid"])) { @@ -467,10 +509,20 @@ if($type != ITEM_TYPE_TRAPPER) { $frmItem->AddRow(S_UPDATE_INTERVAL_IN_SEC, new CTextBox("delay",$delay,5)); + $frmItem->AddRow("Flexible intervals (sec)", $delay_flex_el); + $frmItem->AddRow("New flexible interval", + array( + S_DELAY, SPACE, + new CTextBox("new_delay_flex[delay]","50",5), + S_PERIOD, SPACE, + new CTextBox("new_delay_flex[period]","1-7,00:00-23:59",27), BR, + new CButton("add_delay_flex",S_ADD) + )); } else { $frmItem->AddVar("delay",$delay); + $frmItem->AddVar("delay_flex[]",""); } $frmItem->AddRow(S_KEEP_HISTORY_IN_DAYS, array( diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 9acdeb93..ec0e48c5 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -21,13 +21,13 @@ <?php # Update Item definition for selected group - function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications) + function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications) { $sql="select i.itemid,i.hostid from hosts_groups hg,items i where hg.groupid=$groupid and i.key_=".zbx_dbstr($key)." and hg.hostid=i.hostid"; $result=DBexecute($sql); while($row=DBfetch($result)) { - update_item($row["itemid"],$description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications); + update_item($row["itemid"],$description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications); } return 1; } @@ -60,13 +60,13 @@ # Add Item definition to selected group - function add_item_to_group($groupid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications) + function add_item_to_group($groupid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications) { $sql="select hostid from hosts_groups where groupid=$groupid"; $result=DBexecute($sql); while($row=DBfetch($result)) { - add_item($description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$applications); + add_item($description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications); } return 1; } @@ -77,7 +77,7 @@ $description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid, $value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname, $snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt, - $valuemapid,$applications,$templateid=0) + $valuemapid,$delay_flex,$applications,$templateid=0) { $host=get_host_by_hostid($hostid); @@ -160,7 +160,7 @@ $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, $delta, $snmpv3_securityname, $snmpv3_securitylevel, $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, - $trends, $logtimefmt, $valuemapid, + $trends, $logtimefmt, $valuemapid, $delay_flex, get_same_applications_for_host($applications, $db_item["hostid"]), $templateid); @@ -173,13 +173,14 @@ " (itemid,description,key_,hostid,delay,history,nextcheck,status,type,". "snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,". "delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,". - "snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,templateid)". + "snmpv3_privpassphrase,formula,trends,logtimefmt,valuemapid,delay_flex,templateid)". " values ($itemid,".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0, $status,$type,".zbx_dbstr($snmp_community).",".zbx_dbstr($snmp_oid).",$value_type,". zbx_dbstr($trapper_hosts).",$snmp_port,".zbx_dbstr($units).",$multiplier,$delta,". zbx_dbstr($snmpv3_securityname).",$snmpv3_securitylevel,". zbx_dbstr($snmpv3_authpassphrase).",".zbx_dbstr($snmpv3_privpassphrase).",". - zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).",$valuemapid,$templateid)"); + zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).",$valuemapid,". + zbx_dbstr($delay_flex).",$templateid)"); if(!$result) @@ -204,7 +205,7 @@ $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, $delta, $snmpv3_securityname, $snmpv3_securitylevel, $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, - $trends, $logtimefmt, $valuemapid, + $trends, $logtimefmt, $valuemapid,$delay_flex, get_same_applications_for_host($applications, $db_host["hostid"]), $itemid); if(!$result) @@ -244,7 +245,7 @@ function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type, $snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta, $snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase, - $formula,$trends,$logtimefmt,$valuemapid,$applications,$templateid=0) + $formula,$trends,$logtimefmt,$valuemapid,$delay_flex,$applications,$templateid=0) { $host = get_host_by_hostid($hostid); @@ -295,7 +296,7 @@ $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, $delta, $snmpv3_securityname, $snmpv3_securitylevel, $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, - $trends, $logtimefmt, $valuemapid, + $trends, $logtimefmt, $valuemapid,$delay_flex, get_same_applications_for_host($applications, $db_tmp_item["hostid"]), $itemid); @@ -337,7 +338,8 @@ "snmpv3_authpassphrase=".zbx_dbstr($snmpv3_authpassphrase).",". "snmpv3_privpassphrase=".zbx_dbstr($snmpv3_privpassphrase).",". "formula=".zbx_dbstr($formula).",trends=$trends,logtimefmt=".zbx_dbstr($logtimefmt).",". - "valuemapid=$valuemapid,templateid=$templateid where itemid=$itemid"); + "valuemapid=$valuemapid,delay_flex=".zbx_dbstr($delay_flex).",". + "templateid=$templateid where itemid=$itemid"); if($result) { info("Item '".$host["host"].":$key' updated"); @@ -408,6 +410,7 @@ $db_tmp_item["trends"], $db_tmp_item["logtimefmt"], $db_tmp_item["valuemapid"], + $db_tmp_item["delay_flex"], get_same_applications_for_host($parrent_applications,$hostid), $copy_mode ? 0 : $db_tmp_item["itemid"]); } @@ -450,6 +453,7 @@ $db_tmp_item["trends"], $db_tmp_item["logtimefmt"], $db_tmp_item["valuemapid"], + $db_tmp_item["delay_flex"], get_same_applications_for_host($parrent_applications,$hostid), $copy_mode ? 0 : $db_tmp_item["itemid"]); } diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 82fcd6b8..a19ba777 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -828,6 +828,21 @@ "S_DELETE_SELECTED_LINKS"=> "Delete selected links?", "S_SERVICES_DELETED"=> "Services deleted", "S_CANNOT_DELETE_SERVICES"=> "Cannot delete services", + "S_UPTIME"=> "Uptime", + "S_DOWNTIME"=> "Downtime", + "S_ONE_TIME_DOWNTIME"=> "One-time downtime", + "S_NO_TIMES_DEFINED"=> "No times defined", + "S_SERVICE_TIMES"=> "Service times", + "S_NEW_SERVICE_TIME"=> "New service time", + "S_NOTE"=> "Note", + + "S_SUNDAY"=> "Sunday", + "S_MONDAY"=> "Monday", + "S_TUESDAY"=> "Tuesday", + "S_WEDNESDAY"=> "Wednesday", + "S_THURSDAY"=> "Thursday", + "S_FRIDAY"=> "Friday", + "S_SATURDAY"=> "Saturday", // srv_status.php "S_IT_SERVICES_BIG"=> "IT SERVICES", diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php index 96f35f2f..9be53611 100644 --- a/frontends/php/include/services.inc.php +++ b/frontends/php/include/services.inc.php @@ -19,28 +19,50 @@ **/ ?> <?php - function add_service($name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder) + function add_service($name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array()) { + +var_dump($service_times); + if(is_null($triggerid)) $triggerid = 'NULL'; $serviceid=get_dbid("services","serviceid"); - $sql="insert into services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)". - " values ($serviceid,".zbx_dbstr($name).",0,$triggerid,".zbx_dbstr($algorithm).",$showsla,".zbx_dbstr($goodsla).",$sortorder)"; - $result=DBexecute($sql); + $result=DBexecute("insert into services (serviceid,name,status,triggerid,algorithm,showsla,goodsla,sortorder)". + " values ($serviceid,".zbx_dbstr($name).",0,$triggerid,".zbx_dbstr($algorithm).",$showsla,".zbx_dbstr($goodsla).",$sortorder)"); if(!$result) { return FALSE; } + + foreach($service_times as $val) + { + $result = DBexecute('insert into services_times (serviceid, type, ts_from, ts_to, note)'. + ' values ('.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')'); + + if(!$result) + { + delete_service($serviceid); + return FALSE; + } + } return $serviceid; } - function update_service($serviceid,$name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder) + function update_service($serviceid,$name,$triggerid,$algorithm,$showsla,$goodsla,$sortorder,$service_times=array()) { if(is_null($triggerid)) $triggerid = 'NULL'; - $sql="update services set name=".zbx_dbstr($name).",triggerid=$triggerid,status=0,algorithm=$algorithm,showsla=$showsla,goodsla=$goodsla,sortorder=$sortorder where serviceid=$serviceid"; - return DBexecute($sql); + $result = DBexecute("update services set name=".zbx_dbstr($name).",triggerid=$triggerid,status=0,algorithm=$algorithm,showsla=$showsla,goodsla=$goodsla,sortorder=$sortorder where serviceid=$serviceid"); + + DBexecute('delete from services_times where serviceid='.$serviceid); + foreach($service_times as $val) + { + DBexecute('insert into services_times (serviceid, type, ts_from, ts_to, note)'. + ' values ('.$serviceid.','.$val['type'].','.$val['from'].','.$val['to'].','.zbx_dbstr($val['note']).')'); + } + + return $result; } function add_host_to_services($hostid,$serviceid) @@ -210,82 +232,229 @@ return $value; } + function expand_periodical_service_times(&$data, + $period_start, $period_end, + $ts_from, $ts_to, + $type='ut' /* 'ut' OR 'dt' */ + ) + { + /* calculate period from '-1 week' to know period name for $period_start */ + for($curr = ($period_start - (7*24*36000)); $curr<=$period_end; $curr += 6*3600) + { + $curr_date = getdate($curr); + $from_date = getdate($ts_from); + if($curr_date['wday'] == $from_date['wday']) + { + $curr_from = mktime( + $from_date['hours'],$from_date['minutes'],$from_date['seconds'], + $curr_date['mon'],$curr_date['mday'],$curr_date['year'] + ); + $curr_to = $curr_from + ($ts_to - $ts_from); + + $curr_from = max($curr_from, $period_start); + $curr_from = min($curr_from, $period_end); + $curr_to = max($curr_to, $period_start); + $curr_to = min($curr_to, $period_end); + + $curr = $curr_to; + + if(isset($data[$curr_from][$type.'_s'])) + $data[$curr_from][$type.'_s'] ++; + else + $data[$curr_from][$type.'_s'] = 1; + + if(isset($data[$curr_to][$type.'_e'])) + $data[$curr_to][$type.'_e'] ++; + else + $data[$curr_to][$type.'_e'] = 1; + + + } + } + } + function calculate_service_availability($serviceid,$period_start,$period_end) { - $sql="select count(*),min(clock),max(clock) from service_alarms where serviceid=$serviceid and clock>=$period_start and clock<=$period_end"; - - $sql="select clock,value from service_alarms where serviceid=$serviceid and clock>=$period_start and clock<=$period_end"; - $result=DBselect($sql); -// -1,0,1 - $state=get_last_service_value($serviceid,$period_start); - $problem_time=0; - $ok_time=0; - $time=$period_start; - while($row=DBfetch($result)) + +// $sql="select count(*),min(clock),max(clock) from service_alarms where serviceid=$serviceid and clock>=$period_start and clock<=$period_end"; + + /* FILL data */ + + /* structure of "$data" + * key - time stamp + * alarm - on/off status (0,1 - off; >1 - on) + * dt_s - count of downtime starts + * dt_e - count of downtime ends + * ut_s - count of uptime starts + * ut_e - count of uptime ends + */ + + $data[$period_start]['alarm'] = get_last_service_value($serviceid,$period_start); + + $service_alarms = DBselect("select clock,value from service_alarms". + " where serviceid=".$serviceid." and clock>=".$period_start." and clock<=".$period_end." order by clock"); + + /* add alarms */ + while($db_alarm_row = DBfetch($service_alarms)) { - $clock=$row["clock"]; - $value=$row["value"]; + $data[$db_alarm_row['clock']]['alarm'] = $db_alarm_row['value']; + } - $diff=$clock-$time; + /* add periodical downtimes */ + $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_UPTIME. + ' and serviceid='.$serviceid); + if($db_time_row = DBfetch($service_times)) + { + /* if exist any uptime - unmarked time is downtime */ + $unmarked_period_type = 'dt'; + do{ + expand_periodical_service_times($data, + $period_start, $period_end, + $db_time_row['ts_from'], $db_time_row['ts_to'], + 'ut'); + + }while($db_time_row = DBfetch($service_times)); + } + else + { + /* if missed any uptime - unmarked time is uptime */ + $unmarked_period_type = 'ut'; + } - $time=$clock; -#state=0,1 (OK), >1 PROBLEMS + /* add periodical downtimes */ + $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_DOWNTIME. + ' and serviceid='.$serviceid); + while($db_time_row = DBfetch($service_times)) + { + expand_periodical_service_times($data, + $period_start, $period_end, + $db_time_row['ts_from'], $db_time_row['ts_to'], + 'dt'); + } - if($state<=1) - { - $ok_time+=$diff; - $state=$value; - } + /* add one-time downtimes */ + $service_times = DBselect('select ts_from,ts_to from services_times where type='.SERVICE_TIME_TYPE_ONETIME_DOWNTIME. + ' and serviceid='.$serviceid); + while($db_time_row = DBfetch($service_times)) + { + if( ($db_time_row['ts_to'] < $period_start) || ($db_time_row['ts_from'] > $period_end)) continue; + + if($db_time_row['ts_from'] < $period_start) $db_time_row['ts_from'] = $period_start; + if($db_time_row['ts_to'] > $period_end) $db_time_row['ts_to'] = $period_end; + + if(isset($data[$db_time_row['ts_from']]['dt_s'])) + $data[$db_time_row['ts_from']]['dt_s'] ++; else - { - $problem_time+=$diff; - $state=$value; - } + $data[$db_time_row['ts_from']]['dt_s'] = 1; + + if(isset($data[$db_time_row['ts_to']]['dt_e'])) + $data[$db_time_row['ts_to']]['dt_e'] ++; + else + $data[$db_time_row['ts_to']]['dt_e'] = 1; + } + if(!isset($data[$period_end])) $data[$period_end] = array(); + +/* + print('From: '.date('l d M Y H:i',$period_start).' To: '.date('l d M Y H:i',$period_end).BR); +$ut = 0; +$dt = 0; + foreach($data as $ts => $val) + { + print($ts); + print(" - [".date('l d M Y H:i',$ts)."]"); + if(isset($val['ut_s'])) {print(' ut_s-'.$val['ut_s']); $ut+=$val['ut_s'];} + if(isset($val['ut_e'])) {print(' ut_e-'.$val['ut_e']); $ut-=$val['ut_e'];} + if(isset($val['dt_s'])) {print(' dt_s-'.$val['dt_s']); $dt+=$val['dt_s'];} + if(isset($val['dt_e'])) {print(' dt_e-'.$val['dt_e']); $dt-=$val['dt_e'];} + if(isset($val['alarm'])) {print(' alarm is '.$val['alarm']); } + print(' ut = '.$ut.' dt = '.$dt); + print(BR); } -// echo $problem_time,"-",$ok_time,"<br>"; +SDI('ut = '.$ut); +SDI('dt = '.$dt);/**/ + + /* calculate times */ - if(!DBfetch($result)) + ksort($data); /* sort by time stamp */ + + $dt_cnt = 0; + $ut_cnt = 0; + $sla_time = array( + 'dt' => array('problem_time' => 0, 'ok_time' => 0), + 'ut' => array('problem_time' => 0, 'ok_time' => 0) + ); + $prev_alarm = $data[$period_start]['alarm']; + $prev_time = $period_start; + +//print_r($data[$period_start]); print(BR); + + if(isset($data[$period_start]['ut_s'])) $ut_cnt += $data[$period_start]['ut_s']; + if(isset($data[$period_start]['ut_e'])) $ut_cnt -= $data[$period_start]['ut_e']; + if(isset($data[$period_start]['dt_s'])) $dt_cnt += $data[$period_start]['dt_s']; + if(isset($data[$period_start]['dt_e'])) $dt_cnt -= $data[$period_start]['dt_e']; + foreach($data as $ts => $val) { - if(get_last_service_value($serviceid,$period_start)<=1) + if($ts == $period_start) continue; /* skip first data [already readed] */ + + if($dt_cnt > 0) { - $ok_time=$period_end-$period_start; + $period_type = 'dt'; } - else + else if($ut_cnt > 0) { - $problem_time=$period_end-$period_start; + $period_type = 'ut'; } - } - else - { - if($state<=1) + else /* dt_cnt=0 && ut_cnt=0 */ { - $ok_time=$ok_time+$period_end-$time; + $period_type = $unmarked_period_type; + } + + /* state=0,1 [OK] (1 - information severity of trigger), >1 [PROBLEMS] (trigger severity) */ + if($prev_alarm > 1) + { + $sla_time[$period_type]['problem_time'] += $ts - $prev_time; } else { - $problem_time=$problem_time+$period_end-$time; + $sla_time[$period_type]['ok_time'] += $ts - $prev_time; } - } +//SDI($dt_cnt.'/'.$ut_cnt.' - '.$prev_alarm); +//print_r($val); print(BR); + if(isset($val['ut_s'])) $ut_cnt += $val['ut_s']; + if(isset($val['ut_e'])) $ut_cnt -= $val['ut_e']; + if(isset($val['dt_s'])) $dt_cnt += $val['dt_s']; + if(isset($val['dt_e'])) $dt_cnt -= $val['dt_e']; -// echo $problem_time,"-",$ok_time,"<br>"; + if(isset($val['alarm'])) $prev_alarm = $val['alarm']; - $total_time=$problem_time+$ok_time; - if($total_time==0) + $prev_time = $ts; + } + +/* +SDI( +'dt: '.$sla_time['dt']['ok_time'].'/'.$sla_time['dt']['problem_time'].' '. +'ut: '.$sla_time['ut']['ok_time'].'/'.$sla_time['ut']['problem_time'] +); +/**/ + + $sla_time['problem_time'] = &$sla_time['ut']['problem_time']; + $sla_time['ok_time'] = &$sla_time['ut']['ok_time']; + $sla_time['downtime_time'] = $sla_time['dt']['ok_time'] + $sla_time['dt']['problem_time']; + + $full_time = $sla_time['problem_time'] + $sla_time['ok_time']; + if($full_time > 0) { - $ret["problem_time"]=0; - $ret["ok_time"]=0; - $ret["problem"]=0; - $ret["ok"]=0; + $sla_time['problem'] = 100 * $sla_time['problem_time'] / $full_time; + $sla_time['ok'] = 100 * $sla_time['ok_time'] / $full_time; } else { - $ret["problem_time"]=$problem_time; - $ret["ok_time"]=$ok_time; - $ret["problem"]=(100*$problem_time)/$total_time; - $ret["ok"]=(100*$ok_time)/$total_time; + $sla_time['problem'] = 100; + $sla_time['ok'] = 100; } - return $ret; + + return $sla_time; } function get_service_status_description($status) diff --git a/frontends/php/items.php b/frontends/php/items.php index 6fe0c480..f943244e 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -55,6 +55,9 @@ "description"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY,'isset({save})'), "key"=> array(T_ZBX_STR, O_OPT, NULL, NOT_EMPTY,'isset({save})'), "delay"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,86400),'isset({save})&&{type}!=2'), + "new_delay_flex"=> array(T_ZBX_STR, O_OPT, NOT_EMPTY, "",'isset({add_delay_flex})&&{type}!=2'), + "rem_delay_flex"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,86400),NULL), + "delay_flex"=> array(T_ZBX_STR, O_OPT, NULL, "",NULL), "history"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'isset({save})'), "status"=> array(T_ZBX_INT, O_OPT, NULL, BETWEEN(0,65535),'isset({save})'), "type"=> array(T_ZBX_INT, O_OPT, NULL, IN("0,1,2,3,4,5,6,7,8"),'isset({save})'), @@ -85,6 +88,8 @@ "applications"=> array(T_ZBX_INT, O_OPT, NULL, DB_ID, NULL), "del_history"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + "add_delay_flex"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), + "del_delay_flex"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), "register"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), "group_task"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL), @@ -108,7 +113,19 @@ <?php $result = 0; - if(isset($_REQUEST["delete"])&&isset($_REQUEST["itemid"])) + if(isset($_REQUEST['del_delay_flex']) && isset($_REQUEST['rem_delay_flex'])) + { + $_REQUEST['delay_flex'] = get_request('delay_flex',array()); + foreach($_REQUEST['rem_delay_flex'] as $val){ + unset($_REQUEST['delay_flex'][$val]); + } + } + else if(isset($_REQUEST["add_delay_flex"])&&isset($_REQUEST["new_delay_flex"])) + { + $_REQUEST['delay_flex'] = get_request("delay_flex", array()); + array_push($_REQUEST['delay_flex'],$_REQUEST["new_delay_flex"]); + } + else if(isset($_REQUEST["delete"])&&isset($_REQUEST["itemid"])) { $result = delete_item($_REQUEST["itemid"]); show_messages($result, S_ITEM_DELETED, S_CANNOT_DELETE_ITEM); @@ -120,6 +137,12 @@ else if(isset($_REQUEST["save"])) { $applications = get_request("applications",array()); + $delay_flex = get_request('delay_flex',array()); + $db_delay_flex = ""; + foreach($delay_flex as $val) + $db_delay_flex .= $val['delay'].'/'.$val['period'].';'; + $db_delay_flex = trim($db_delay_flex,";"); + if(isset($_REQUEST["itemid"])) { $result=update_item($_REQUEST["itemid"], @@ -130,7 +153,7 @@ $_REQUEST["multiplier"],$_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"],$_REQUEST["trends"], - $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$applications); + $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$db_delay_flex,$applications); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); } @@ -144,7 +167,7 @@ $_REQUEST["multiplier"],$_REQUEST["delta"],$_REQUEST["snmpv3_securityname"], $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"],$_REQUEST["trends"], - $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$applications); + $_REQUEST["logtimefmt"],$_REQUEST["valuemapid"],$db_delay_flex,$applications); $result = $itemid; show_messages($result, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); @@ -211,6 +234,11 @@ if($_REQUEST["action"]=="add to group") { $applications = get_request("applications",array()); + $delay_flex = get_request('delay_flex',array()); + $db_delay_flex = ""; + foreach($delay_flex as $val) + $db_delay_flex .= $val['delay'].'/'.$val['period'].';'; + $db_delay_flex = trim($db_delay_flex,";"); $itemid=add_item_to_group( $_REQUEST["add_groupid"],$_REQUEST["description"],$_REQUEST["key"], $_REQUEST["hostid"],$_REQUEST["delay"],$_REQUEST["history"], @@ -221,7 +249,7 @@ $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"], $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"], - $applications); + $db_delay_flex, $applications); show_messages($itemid, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); if($itemid){ unset($_REQUEST["form"]); @@ -232,6 +260,11 @@ if($_REQUEST["action"]=="update in group") { $applications = get_request("applications",array()); + $delay_flex = get_request('delay_flex',array()); + $db_delay_flex = ""; + foreach($delay_flex as $val) + $db_delay_flex .= $val['delay'].'/'.$val['period'].';'; + $db_delay_flex = trim($db_delay_flex,";"); $result=update_item_in_group($_REQUEST["add_groupid"], $_REQUEST["itemid"],$_REQUEST["description"],$_REQUEST["key"], $_REQUEST["hostid"],$_REQUEST["delay"],$_REQUEST["history"], @@ -242,7 +275,7 @@ $_REQUEST["snmpv3_securitylevel"],$_REQUEST["snmpv3_authpassphrase"], $_REQUEST["snmpv3_privpassphrase"],$_REQUEST["formula"], $_REQUEST["trends"],$_REQUEST["logtimefmt"],$_REQUEST["valuemapid"], - $applications); + $db_delay_flex, $applications); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); if($result){ unset($_REQUEST["form"]); diff --git a/frontends/php/popup.php b/frontends/php/popup.php index 7087709c..da509127 100644 --- a/frontends/php/popup.php +++ b/frontends/php/popup.php @@ -115,7 +115,7 @@ $sql .= ",hosts_groups hg where mod(h.hostid,100)=$ZBX_CURNODEID and h.hostid=hg.hostid and hg.groupid=$groupid"; else { - $sql .= "where mod(h.hostid,100)=$ZBX_CURNODEID"; + $sql .= " where mod(h.hostid,100)=$ZBX_CURNODEID"; $cmbHosts->AddItem(0,S_ALL_SMALL); } @@ -161,7 +161,7 @@ if(isset($groupid)) $sql .= ",hosts_groups hg where mod(h.hostid,100)=$ZBX_CURNODEID and h.hostid=hg.hostid and hg.groupid=$groupid"; else - $sql .= "where mod(h.hostid,100)=$ZBX_CURNODEID"; + $sql .= " where mod(h.hostid,100)=$ZBX_CURNODEID"; $db_hosts = DBselect($sql); while($host = DBfetch($db_hosts)) @@ -365,8 +365,9 @@ function add_variable(formname,value) else { $sql = "select h.host,i.* from items i,hosts h". - " where i.value_type=".ITEM_VALUE_TYPE_LOG." and h.hostid=i.hostid order by i.description, i.key_". + " where i.value_type=".ITEM_VALUE_TYPE_LOG." and h.hostid=i.hostid". " and mod(i.itemid,100)=".$ZBX_CURNODEID. + " order by i.description, i.key_"; } $db_items = DBselect($sql); diff --git a/frontends/php/report3.php b/frontends/php/report3.php index 65d9003b..a2f696af 100644 --- a/frontends/php/report3.php +++ b/frontends/php/report3.php @@ -35,6 +35,33 @@ ?> <?php + + if(isset($_REQUEST["test"])) + { +/* if(DBexecute('insert into service_alarms (serviceid,clock,value) values (55,'.strtotime('-4 month').',0)')) + SDI('OK'); + else + SDI('NO'); +*/ + $tmp_arr = array( + array(10, "1"), + array(9, "2"), + array(8, "3"), + array(7, "4"), + array(6, "5"), + array(5, "6"), + array(4, "7"), + array(3, "8"), + array(2, "9"), + array(1, "10"), + ); + SDI("source"); + print_r($tmp_arr); + SDI("sorted"); + array_multisort($tmp_arr); + print_r($tmp_arr); + } + if(!isset($_REQUEST["serviceid"])) { show_table_header("<font color=\"AA0000\">Undefined serviceid !</font>"); @@ -81,7 +108,7 @@ $table = new CTableInfo(); if($_REQUEST["period"]=="yearly") { - $table->setHeader(array(S_YEAR,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA)); + $table->setHeader(array(S_YEAR,S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA)); for($year=date("Y")-5;$year<=date("Y");$year++) { $start=mktime(0,0,0,1,1,$year); @@ -96,6 +123,7 @@ $ok=new CSpan($f_time,"off"); $problems=new CSpan($t_time,"on"); $percentage=new CSpan($f,"off"); + $downtime = sprintf("%dd %dh %dm",$stat["downtime_time"]/(24*3600),($stat["downtime_time"]%(24*3600))/3600,($stat["downtime_time"]%(3600))/(60)); if($service["showsla"]==1) { @@ -116,6 +144,7 @@ $year, $ok, $problems, + $downtime, $percentage, $sla )); @@ -123,7 +152,7 @@ } else if($_REQUEST["period"]=="monthly") { - $table->setHeader(array(S_MONTH,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA)); + $table->setHeader(array(S_MONTH,S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA)); for($month=1;$month<=12;$month++) { $start=mktime(0,0,0,$month,1,$_REQUEST["year"]); @@ -141,6 +170,7 @@ $ok=new CSpan($f_time,"off"); $problems=new CSpan($t_time,"on"); $percentage=new CSpan($f,"off"); + $downtime = sprintf("%dd %dh %dm",$stat["downtime_time"]/(24*3600),($stat["downtime_time"]%(24*3600))/3600,($stat["downtime_time"]%(3600))/(60)); if($service["showsla"]==1) { @@ -161,6 +191,7 @@ date("M Y",$start), $ok, $problems, + $downtime, $percentage, $sla )); @@ -168,7 +199,7 @@ } else if($_REQUEST["period"]=="daily") { - $table->setHeader(array(S_DAY,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA)); + $table->setHeader(array(S_DAY,S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA)); $s=mktime(0,0,0,1,1,$_REQUEST["year"]); $e=mktime(0,0,0,1,1,$_REQUEST["year"]+1); for($day=$s;$day<$e;$day+=24*3600) @@ -188,6 +219,7 @@ $ok=new CSpan($f_time,"off"); $problems=new CSpan($t_time,"on"); $percentage=new CSpan($f,"off"); + $downtime = sprintf("%dd %dh %dm",$stat["downtime_time"]/(24*3600),($stat["downtime_time"]%(24*3600))/3600,($stat["downtime_time"]%(3600))/(60)); if($service["showsla"]==1) { @@ -208,6 +240,7 @@ date("d M Y",$start), $ok, $problems, + $downtime, $percentage, $sla )); @@ -216,7 +249,7 @@ else { //--------Weekly------------- - $table->setHeader(array(S_FROM,S_TILL,S_OK,S_PROBLEMS,S_PERCENTAGE,S_SLA)); + $table->setHeader(array(S_FROM,S_TILL,S_OK,S_PROBLEMS,S_DOWNTIME,S_PERCENTAGE,S_SLA)); $year=date("Y"); for($year=date("Y")-2;$year<=date("Y");$year++) { @@ -248,9 +281,10 @@ $f=sprintf("%2.2f%%",$stat["ok"]); $f_time=sprintf("%dd %dh %dm",$stat["ok_time"]/(24*3600),($stat["ok_time"]%(24*3600))/3600,($stat["ok_time"]%(3600))/(60)); - $ok=new CSpan($f_time,"off"); - $problems=new CSpan($t_time,"on"); - $percentage=new CSpan($f,"off"); + $ok = new CSpan($f_time,"off"); + $problems = new CSpan($t_time,"on"); + $percentage = new CSpan($f,"off"); + $downtime = sprintf("%dd %dh %dm",$stat["downtime_time"]/(24*3600),($stat["downtime_time"]%(24*3600))/3600,($stat["downtime_time"]%(3600))/(60)); if($service["showsla"]==1) { @@ -273,6 +307,7 @@ $till, $ok, $problems, + $downtime, $percentage, $sla )); diff --git a/frontends/php/services.php b/frontends/php/services.php index 5de908d9..52692c01 100644 --- a/frontends/php/services.php +++ b/frontends/php/services.php @@ -19,7 +19,7 @@ **/ ?> <?php - include "include/config.inc.php"; + include_once "include/config.inc.php"; $page["title"] = "S_IT_SERVICES"; $page["file"] = "services.php"; @@ -75,20 +75,24 @@ } elseif(isset($_REQUEST["save_service"])) { + $service_times = get_request('service_times',array()); + $showsla = isset($_REQUEST["showsla"]) ? 1 : 0; $triggerid = isset($_REQUEST["linktrigger"]) ? $_REQUEST["triggerid"] : NULL; if(isset($_REQUEST["serviceid"])) { $result = update_service($_REQUEST["serviceid"], $_REQUEST["name"],$triggerid,$_REQUEST["algorithm"], - $showsla,$_REQUEST["goodsla"],$_REQUEST["sortorder"]); + $showsla,$_REQUEST["goodsla"],$_REQUEST["sortorder"], + $service_times); show_messages($result, S_SERVICE_UPDATED, S_CANNOT_UPDATE_SERVICE); } else { $result = add_service( $_REQUEST["name"],$triggerid,$_REQUEST["algorithm"], - $showsla,$_REQUEST["goodsla"],$_REQUEST["sortorder"]); + $showsla,$_REQUEST["goodsla"],$_REQUEST["sortorder"], + $service_times); show_messages($result, S_SERVICE_ADDED, S_CANNOT_ADD_SERVICE); } } @@ -112,6 +116,41 @@ $result=add_host_to_services($_REQUEST["serverid"],$_REQUEST["serviceid"]); show_messages($result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER); } + elseif(isset($_REQUEST["add_service_time"]) && isset($_REQUEST["new_service_time"])) + { + $_REQUEST['service_times'] = get_request('service_times',array()); + + $new_service_time['type'] = $_REQUEST["new_service_time"]['type']; + + if($_REQUEST["new_service_time"]['type'] == SERVICE_TIME_TYPE_ONETIME_DOWNTIME) + { + $new_service_time['from'] = strtotime($_REQUEST["new_service_time"]['from']); + $new_service_time['to'] = strtotime($_REQUEST["new_service_time"]['to']); + $new_service_time['note'] = $_REQUEST["new_service_time"]['note']; + } + else + { + $new_service_time['from'] = strtotime( + $_REQUEST["new_service_time"]['from_week'].' '.$_REQUEST["new_service_time"]['from'] + ); + $new_service_time['to'] = strtotime( + $_REQUEST["new_service_time"]['to_week'].' '.$_REQUEST["new_service_time"]['to'] + ); + $new_service_time['note'] = $_REQUEST["new_service_time"]['note']; + } + + while($new_service_time['to'] <= $new_service_time['from']) $new_service_time['to'] += 7*24*3600; + + if(!in_array($_REQUEST['service_times'], $new_service_time)) + array_push($_REQUEST['service_times'],$new_service_time); + } + elseif(isset($_REQUEST["del_service_times"]) && isset($_REQUEST["rem_service_times"])) + { + $_REQUEST["service_times"] = get_request("service_times",array()); + foreach($_REQUEST["rem_service_times"] as $val){ + unset($_REQUEST["service_times"][$val]); + } + } ?> <?php @@ -252,6 +291,9 @@ $frmService->SetHelp("web.services.service.php"); $frmService->AddVar("parentid",$_REQUEST["parentid"]); + $service_times = get_request('service_times',array()); + $new_service_time = get_request('new_service_time',array('type' => SERVICE_TIME_TYPE_UPTIME)); + if(isset($_REQUEST["serviceid"])) { $frmService->AddVar("serviceid",$_REQUEST["serviceid"]); @@ -271,6 +313,19 @@ $triggerid =$service["triggerid"]; $linktrigger = isset($triggerid) ? 'yes' : 'no'; if(!isset($triggerid)) $triggerid = 0; + + $result = DBselect('select * from services_times where serviceid='.$_REQUEST['serviceid']); + while($db_stime = DBfetch($result)) + { + $stime = array( + 'type'=> $db_stime['type'], + 'from'=> $db_stime['ts_from'], + 'to'=> $db_stime['ts_to'], + 'note'=> $db_stime['note'] + ); + if(in_array($stime, $service_times)) continue; + array_push($service_times, $stime); + } } else { @@ -302,6 +357,88 @@ else $frmService->AddVar("goodsla",$goodsla); + $stime_el = array(); + $i = 0; + foreach($service_times as $val) + { + switch($val['type']) + { + case SERVICE_TIME_TYPE_UPTIME: + $type = new CSpan(S_UPTIME,'enabled'); + $from = date('l H:i', $val['from']); + $to = date('l H:i', $val['to']); + break; + case SERVICE_TIME_TYPE_DOWNTIME: + $type = new CSpan(S_DOWNTIME,'disabled'); + $from = date('l H:i', $val['from']); + $to = date('l H:i', $val['to']); + break; + case SERVICE_TIME_TYPE_ONETIME_DOWNTIME: + $type = new CSpan(S_ONE_TIME_DOWNTIME,'disabled'); + $from = date('d M Y H:i', $val['from']); + $to = date('d M Y H:i', $val['to']); + break; + } + array_push($stime_el, array(new CCheckBox("rem_service_times[]", 'no', NULL,$i), + $type,':'.SPACE, $from, SPACE.'-'.SPACE, $to, + (!empty($val['note']) ? BR.'['.htmlspecialchars($val['note']).']' : '' ),BR)); + + $frmService->AddVar('service_times['.$i.'][type]', $val['type']); + $frmService->AddVar('service_times['.$i.'][from]', $val['from']); + $frmService->AddVar('service_times['.$i.'][to]', $val['to']); + $frmService->AddVar('service_times['.$i.'][note]', $val['note']); + + $i++; + } + + if(count($stime_el)==0) + array_push($stime_el, S_NO_TIMES_DEFINED); + else + array_push($stime_el, new CButton('del_service_times','delete selected')); + + $frmService->AddRow(S_SERVICE_TIMES, $stime_el); + + $cmbTimeType = new CComboBox("new_service_time[type]",$new_service_time['type'],'submit()'); + $cmbTimeType->AddItem(SERVICE_TIME_TYPE_UPTIME, S_UPTIME); + $cmbTimeType->AddItem(SERVICE_TIME_TYPE_DOWNTIME, S_DOWNTIME); + $cmbTimeType->AddItem(SERVICE_TIME_TYPE_ONETIME_DOWNTIME, S_ONE_TIME_DOWNTIME); + + $time_param = new CTable(); + if($new_service_time['type'] == SERVICE_TIME_TYPE_ONETIME_DOWNTIME) + { + $time_param->AddRow(array(S_NOTE, new CTextBox('new_service_time[note]','<short description>',40))); + $time_param->AddRow(array(S_FROM, new CTextBox('new_service_time[from]','d M Y H:i',20))); + $time_param->AddRow(array(S_TILL, new CTextBox('new_service_time[to]','d M Y H:i',20))); + } + else + { + $cmbWeekFrom = new CComboBox('new_service_time[from_week]','Sunday'); + $cmbWeekTo = new CComboBox('new_service_time[to_week]','Sunday'); + foreach(array( + 'Sunday' =>S_SUNDAY, + 'Monday' =>S_MONDAY, + 'Tuesday' =>S_TUESDAY, + 'Wednesday'=>S_WEDNESDAY, + 'Thursday'=>S_THURSDAY, + 'Friday' =>S_FRIDAY, + 'Saturday' =>S_SATURDAY + ) as $day_num => $day_str) + { + $cmbWeekFrom->AddItem($day_num, $day_str); + $cmbWeekTo->AddItem($day_num, $day_str); + } + + $time_param->AddRow(array(S_FROM, $cmbWeekFrom, new CTextBox('new_service_time[from]','H:i',9))); + $time_param->AddRow(array(S_TILL, $cmbWeekTo, new CTextBox('new_service_time[to]','H:i',9))); + $frmService->AddVar('new_service_time[note]',''); + } + + $frmService->AddRow(S_NEW_SERVICE_TIME, array( + $cmbTimeType, BR, + $time_param, BR, + new CButton('add_service_time','add') + )); + $frmService->AddRow(S_LINK_TO_TRIGGER_Q, new CCheckBox("linktrigger",$linktrigger,"submit();")); if($linktrigger == 'yes') diff --git a/include/common.h b/include/common.h index 50849e28..03e1058e 100644 --- a/include/common.h +++ b/include/common.h @@ -407,7 +407,8 @@ void rtrim_spaces(char *c); void delete_reol(char *c); int get_param(const char *param, int num, char *buf, int maxlen); int num_param(const char *param); -int calculate_item_nextcheck(int itemid, int delay, int now); +int calculate_item_nextcheck(int itemid, int delay, char *delay_flex, time_t now); +int check_time_period(const char *period, time_t now); void zbx_setproctitle(const char *fmt, ...); #define ZBX_JAN_1970_IN_SEC 2208988800.0 /* 1970 - 1900 in seconds */ diff --git a/include/db.h b/include/db.h index 36b286bc..dfa9cc0f 100644 --- a/include/db.h +++ b/include/db.h @@ -136,7 +136,7 @@ void PG_DBfree_result(DB_RESULT result); #define ACTION_SUBJECT_LEN 255 #define ACTION_SUBJECT_LEN_MAX ACTION_SUBJECT_LEN+1 -#define ZBX_SQL_ITEM_SELECT "i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.errors_from,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available,i.status,i.trapper_hosts,i.logtimefmt,i.valuemapid from hosts h, items i" +#define ZBX_SQL_ITEM_SELECT "i.itemid,i.key_,h.host,h.port,i.delay,i.description,i.nextcheck,i.type,i.snmp_community,i.snmp_oid,h.useip,h.ip,i.history,i.lastvalue,i.prevvalue,i.hostid,h.status,i.value_type,h.errors_from,i.snmp_port,i.delta,i.prevorgvalue,i.lastclock,i.units,i.multiplier,i.snmpv3_securityname,i.snmpv3_securitylevel,i.snmpv3_authpassphrase,i.snmpv3_privpassphrase,i.formula,h.available,i.status,i.trapper_hosts,i.logtimefmt,i.valuemapid,i.delay_flex from hosts h, items i" #define ZBX_MAX_SQL_LEN 16384 @@ -227,6 +227,7 @@ DB_ITEM char *logtimefmt; int valuemapid; + char *delay_flex; }; DB_FUNCTION diff --git a/src/libs/zbxcommon/misc.c b/src/libs/zbxcommon/misc.c index f2c56bda..9fcdfbcf 100644 --- a/src/libs/zbxcommon/misc.c +++ b/src/libs/zbxcommon/misc.c @@ -18,6 +18,7 @@ **/ #include "common.h" +#include "log.h" /****************************************************************************** * * @@ -124,12 +125,51 @@ void zbx_setproctitle(const char *fmt, ...) * New one: preserve period, if delay==5, nextcheck = 0,5,10,15,... * * * ******************************************************************************/ -int calculate_item_nextcheck(int itemid, int delay, int now) +int calculate_item_nextcheck(int itemid, int delay, char *delay_flex, time_t now) { - int i; + int i; + char *p; + char delay_period[30]; + int delay_val; + + zabbix_log( LOG_LEVEL_DEBUG, "In calculate_item_nextcheck [%d, %d, %s, %d]",itemid,delay,delay_flex,now); + + if(delay_flex) + { + do + { + p = strchr(delay_flex, ';'); + if(p) *p = '\0'; + + zabbix_log( LOG_LEVEL_DEBUG, "Delay period [%s]", delay_flex); + + if(sscanf(delay_flex, "%d/%29s",&delay_val,delay_period) == 2) + { + zabbix_log( LOG_LEVEL_DEBUG, "%d sec at %s",delay_val,delay_period); + if(check_time_period(delay_period, now)) + { + delay = delay_val; + break; + } + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Delay period format is wrong [%s]",delay_flex); + } + if(p) + { + *p = ';'; /* restore source string */ + delay_flex = p+1; + } + }while(p); + + } /* Old algorithm */ /* i=delay*(int)(now/delay);*/ + + zabbix_log( LOG_LEVEL_DEBUG, "Delay is [%d]",delay); + i=delay*(int)(now/delay)+(itemid % delay); while(i<=now) i+=delay; @@ -139,6 +179,70 @@ int calculate_item_nextcheck(int itemid, int delay, int now) /****************************************************************************** * * + * Function: check_time_period * + * * + * Purpose: check if current time is within given period * + * * + * Parameters: period - time period in format [d1-d2,hh:mm-hh:mm]* * + * now - timestamp for comporation * + * if NULL - use current timestamp. * + * * + * Return value: 0 - out of period, 1 - within the period * + * * + * Author: Alexei Vladishev * + * * + * Comments: * + * * + ******************************************************************************/ +int check_time_period(const char *period, time_t now) +{ + //time_t now; + char tmp[MAX_STRING_LEN]; + char *s; + int d1,d2,h1,h2,m1,m2; + int day, hour, min; + struct tm *tm; + int ret = 0; + + + zabbix_log( LOG_LEVEL_DEBUG, "In check_time_period(%s)",period); + + if(now == (time_t)NULL) now = time(NULL); + + tm = localtime(&now); + + day=tm->tm_wday; + if(0 == day) day=7; + hour = tm->tm_hour; + min = tm->tm_min; + + strscpy(tmp,period); + s=(char *)strtok(tmp,";"); + while(s!=NULL) + { + zabbix_log( LOG_LEVEL_DEBUG, "Period [%s]",s); + + if(sscanf(s,"%d-%d,%d:%d-%d:%d",&d1,&d2,&h1,&m1,&h2,&m2) == 6) + { + zabbix_log( LOG_LEVEL_DEBUG, "%d-%d,%d:%d-%d:%d",d1,d2,h1,m1,h2,m2); + if( (day>=d1) && (day<=d2) && (60*hour+min>=60*h1+m1) && (60*hour+min<=60*h2+m2)) + { + ret = 1; + break; + } + } + else + { + zabbix_log( LOG_LEVEL_ERR, "Time period format is wrong [%s]",period); + } + + s=(char *)strtok(NULL,";"); + } + return ret; +} + +/****************************************************************************** + * * * Function: cmp_double * * * * Purpose: compares two float values * diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c index 9baa1f53..1e6bca69 100644 --- a/src/libs/zbxdbhigh/db.c +++ b/src/libs/zbxdbhigh/db.c @@ -1798,4 +1798,5 @@ void DBget_item_from_db(DB_ITEM *item,DB_ROW row) item->trapper_hosts=row[32]; item->logtimefmt=row[33]; item->valuemapid=atoi(row[34]); + item->delay_flex=row[35]; } diff --git a/src/libs/zbxlog/log.c b/src/libs/zbxlog/log.c index a84ceebe..4500acb6 100644 --- a/src/libs/zbxlog/log.c +++ b/src/libs/zbxlog/log.c @@ -152,7 +152,22 @@ void zabbix_set_log_level(int level) void zabbix_log(int level, const char *fmt, ...) { - FILE *log_file = NULL; +#ifdef TEST + time_t t; + struct tm *tm; + va_list ap; + + t=time(NULL); + tm=localtime(&t); + printf("%.6d:%.4d%.2d%.2d:%.2d%.2d%.2d ",(int)getpid(),tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday,tm->tm_hour,tm->tm_min,tm->tm_sec); + va_start(ap,fmt); + vprintf(fmt,ap); + va_end(ap); + + printf("\n"); +#else /* TEST */ + + FILE *log_file = NULL; char message[MAX_BUF_LEN]; @@ -297,6 +312,9 @@ void zabbix_log(int level, const char *fmt, ...) zbx_mutex_unlock(&log_file_access); } + +#endif /* TEST */ + } /* diff --git a/src/zabbix_server/actions.c b/src/zabbix_server/actions.c index bcc0a51d..b40e06f8 100644 --- a/src/zabbix_server/actions.c +++ b/src/zabbix_server/actions.c @@ -52,67 +52,6 @@ /****************************************************************************** * * - * Function: check_time_period * - * * - * Purpose: check if current time is within given period * - * * - * Parameters: period - time period in format [d1-d2,hh:mm-hh:mm]* * - * * - * Return value: 0 - out of period, 1 - within the period * - * * - * Author: Alexei Vladishev * - * * - * Comments: * - * * - ******************************************************************************/ -static int check_time_period(const char *period) -{ - time_t now; - char tmp[MAX_STRING_LEN]; - char *s; - int d1,d2,h1,h2,m1,m2; - int day, hour, min; - struct tm *tm; - int ret = 0; - - - zabbix_log( LOG_LEVEL_DEBUG, "In check_time_period(%s)",period); - - now = time(NULL); - tm = localtime(&now); - - day=tm->tm_wday; - if(0 == day) day=7; - hour = tm->tm_hour; - min = tm->tm_min; - - strscpy(tmp,period); - s=(char *)strtok(tmp,";"); - while(s!=NULL) - { - zabbix_log( LOG_LEVEL_DEBUG, "Period [%s]",s); - - if(sscanf(s,"%d-%d,%d:%d-%d:%d",&d1,&d2,&h1,&m1,&h2,&m2) == 6) - { - zabbix_log( LOG_LEVEL_DEBUG, "%d-%d,%d:%d-%d:%d",d1,d2,h1,m1,h2,m2); - if( (day>=d1) && (day<=d2) && (60*hour+min>=60*h1+m1) && (60*hour+min<=60*h2+m2)) - { - ret = 1; - break; - } - } - else - { - zabbix_log( LOG_LEVEL_ERR, "Time period format is wrong [%s]",period); - } - - s=(char *)strtok(NULL,";"); - } - return ret; -} - -/****************************************************************************** - * * * Function: send_to_user_medias * * * * Purpose: send notifications to user's medias (email, sms, whatever) * @@ -150,7 +89,7 @@ static void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int useri zabbix_log( LOG_LEVEL_DEBUG, "Won't send message"); continue; } - if(check_time_period(media.period) == 0) + if(check_time_period(media.period, (time_t)NULL) == 0) { zabbix_log( LOG_LEVEL_DEBUG, "Won't send message"); continue; @@ -567,7 +506,7 @@ static int check_action_condition(DB_TRIGGER *trigger,int alarmid,int new_trigge zabbix_log( LOG_LEVEL_ERR, "Condition type [CONDITION_TYPE_TRIGGER_VALUE] is supported"); if(condition->operator == CONDITION_OPERATOR_IN) { - if(check_time_period(condition->value)==1) + if(check_time_period(condition->value, (time_t)NULL)==1) { ret = SUCCEED; } diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c index 2262eb7e..88fabead 100644 --- a/src/zabbix_server/functions.c +++ b/src/zabbix_server/functions.c @@ -642,7 +642,7 @@ static int add_history(DB_ITEM *item, AGENT_RESULT *value, int now) * Comments: * * * ******************************************************************************/ -static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now) +static int update_item(DB_ITEM *item, AGENT_RESULT *value, time_t now) { char value_esc[MAX_STRING_LEN]; char value_str[MAX_STRING_LEN]; @@ -684,7 +684,7 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now) { DBescape_string(value_str,value_esc,MAX_STRING_LEN); /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value_esc,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),value_esc,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),value_esc,(int)now,item->itemid); item->prevvalue=item->lastvalue; item->lastvalue=value_double; @@ -697,7 +697,7 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now) else { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",now+item->delay,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay, item->delay_flex, now),(int)now,item->itemid); } } /* Logic for delta as speed of change */ @@ -706,12 +706,12 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now) if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",now+item->delay,value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),(int)now,item->itemid); } else { /* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);*/ - DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),value_double,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(int)now,item->itemid); } item->prevvalue=item->lastvalue; @@ -727,11 +727,11 @@ static int update_item(DB_ITEM *item, AGENT_RESULT *value, int now) { if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) { - DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex,now),value_double,(value_double - item->prevorgvalue),(int)now,item->itemid); } else { - DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,now),value_double,(int)now,item->itemid); + DBexecute("update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->itemid, item->delay,item->delay_flex, now),value_double,(int)now,item->itemid); } item->prevvalue=item->lastvalue; diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index 2757a1b6..b26f4b60 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -302,21 +302,23 @@ int tcp_listen(const char *host, int port, socklen_t *addrlenp) * Comments: * * * ******************************************************************************/ -/* -#define USE_TEST_FUNCTION 1 -*/ -#ifdef USE_TEST_FUNCTION +#ifdef TEST void run_commands(DB_TRIGGER *trigger,DB_ACTION *action); void test() { + time_t now = time(NULL); + char delay_flex[] = "10/1-3,07:00-20:00;15/1-7,20:01-22:00;5/4-4,11:00-11:40"; + printf("-= Test Started =-\n"); + printf("Next check: %d (%d)\n", calculate_item_nextcheck(1000, 20, delay_flex,now),now); + printf("-= Test completed =-\n"); } -#endif +#endif /* TEST */ /****************************************************************************** * * @@ -402,7 +404,7 @@ int main(int argc, char **argv) init_config(); -#ifdef USE_TEST_FUNCTION +#ifdef TEST if(CONFIG_LOG_FILE == NULL) { zabbix_open_log(LOG_TYPE_SYSLOG,CONFIG_LOG_LEVEL,NULL); @@ -417,7 +419,7 @@ int main(int argc, char **argv) test(); DBclose(); return 0; -#endif +#endif /* TEST */ return daemon_start(CONFIG_ALLOW_ROOT_PERMISSION); } diff --git a/upgrades/dbpatches/1.1_1.3/mysql/patch.sql b/upgrades/dbpatches/1.1_1.3/mysql/patch.sql index 81e19973..544879ee 100644 --- a/upgrades/dbpatches/1.1_1.3/mysql/patch.sql +++ b/upgrades/dbpatches/1.1_1.3/mysql/patch.sql @@ -120,3 +120,22 @@ alter table users_groups_tmp rename users_groups; -- Ger rid of NULLs alter table sysmaps_elements modify label_location int(1) DEFAULT '0' NOT NULL; + +alter table graphs add graphtype int(2) DEFAULT '0' NOT NULL; +alter table items add delay_flex varchar(255) DEFAULT "" NOT NULL; + +-- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid int(4) NOT NULL auto_increment, + serviceid int(4) DEFAULT '0' NOT NULL, + type int(2) DEFAULT '0' NOT NULL, + ts_from int(4) DEFAULT '0' NOT NULL, + ts_to int(4) DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (timeid), + UNIQUE (serviceid,type,ts_from,ts_to) +) type=InnoDB; + diff --git a/upgrades/dbpatches/1.1_1.3/oracle/patch.sql b/upgrades/dbpatches/1.1_1.3/oracle/patch.sql index e69de29b..159b427e 100644 --- a/upgrades/dbpatches/1.1_1.3/oracle/patch.sql +++ b/upgrades/dbpatches/1.1_1.3/oracle/patch.sql @@ -0,0 +1,35 @@ + +alter table graphs add graphtype number(2) DEFAULT '0' NOT NULL; +alter table items add delay_flex varchar(255) DEFAULT NULL; + +-- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid number(10) NOT NULL auto_increment, + serviceid number(10) DEFAULT '0' NOT NULL, + type number(3) DEFAULT '0' NOT NULL, + ts_from number(10) DEFAULT '0' NOT NULL, + ts_to number(10) DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT NULL, + CONSTRAINT services_times_pk PRIMARY KEY (timeid) +) type=InnoDB; + +CREATE INDEX services_times_servicid on services_times (serviceid); +CREATE UNIQUE INDEX services_times_uniq on services_times (serviceid,type,ts_from,ts_to); + +create sequence services_times_timeid +start with 20000 +increment by 1 +nomaxvalue; + +create trigger services_times +before insert on services_times +for each row +begin + if (:new.timeid is null or :new.timeid = 0) then + select services_times_timeid.nextval into :new.timeid from dual; + end if; +end; +/ diff --git a/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql b/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql index e69de29b..b705ba6c 100644 --- a/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql +++ b/upgrades/dbpatches/1.1_1.3/postgresql/patch.sql @@ -0,0 +1,20 @@ + +alter table graphs add graphtype int2 DEFAULT '0' NOT NULL; +alter table items add delay_flex varchar(255) DEFAULT "" NOT NULL; + +-- +-- Table structure for table 'services_times' +-- + +CREATE TABLE services_times ( + timeid serial, + serviceid int4 DEFAULT '0' NOT NULL, + type int2 DEFAULT '0' NOT NULL, + ts_from int4 DEFAULT '0' NOT NULL, + ts_to int4 DEFAULT '0' NOT NULL, + note varchar(255) DEFAULT '' NOT NULL, + PRIMARY KEY (timeid) +) type=InnoDB; + +CREATE UNIQUE INDEX services_times_uniq on services_times (serviceid,type,ts_from,ts_to); + |
