diff options
36 files changed, 268 insertions, 3535 deletions
@@ -1,5 +1,12 @@ Changes for 1.1alpha10: + - improved monitoring of log files (Alexei) + - removed all pthread code (Alexei) + - added column items.lastlogsize (Alexei) + - added column screens_items.colspan (Alexei) + - support of colspan in screens (Alexei) + - added column media.period (Alexei) + - activity period for medias (Alexei) - updated startup scripts for SuSE 9.2 and 9.3. Thanks to Andre. (Alexei) - added selection of hosts for event history (Alexei) - new item type - 'log' (Alexei) @@ -1,9 +1,8 @@ -1.1alpha9: +1.1alpha10: - finish hard-linked templates - escalations and repeated notifications - add encryption between server and agents - - monitoring of log files - more supported parameters under FreeBSD, HP-UX and Solaris (cpu times, network stats) - disk stats under Linux 2.6.x @@ -32,7 +31,6 @@ TKOM: TELECENTRS: - - hard-linked templates (graphs for new hosts to be added automatically) - clickable map in map configuration - rus/lat characters for graphs <? @@ -157,7 +155,6 @@ forum Open Discussion for more info. - rewrite validation and evaluation of expressions (i.e. make >-1 work) - support for 'Clone' (graphs and screens) - add support of interface statistics under Solaris and FreeBSD - - add screens and graphs to host templates - calculate MIN value for graphs (do not use '0') - infrastructure for reports - stacked graphs @@ -165,19 +162,15 @@ forum Open Discussion for more info. - disk size is not correct after evaluating macros in the message - fix evaluation of complex trigger expressions (diskpercentage) - check if alert and service alert is added after host become reachable again - - navigation bar for all graphs and screens LATER: - Oracle support - - zabbix to write log to the item (for example: log when item becomes unsupported) - support for UDP-based checks (DNS, etc) - preserve selected host group between different screens (trigger maintenance, host maintenance) - add zabbix[unixtime] and lastupdate() and tick() to get rid of nodata() - check return code for alert scripts - zabbix_agentd to support processor load, swap[*] and memory[*] onder AIX - - make possible passing of parameters to user script for UserParameters - like param[*] - make session expiration time configurable in config.php - mess with user groups when running under root - support for PREFIX/zabbix/etc (configuration files) @@ -336,8 +329,6 @@ HB: - personalisation (refresh rate, graph size, default graph period, etc) - LDAP authorisation (should work with MSWindows LDAP) - - Reports: - - more customizable (graphs time range: 1 mont, etc) WIN32 Agent: diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql index f6a3571e..4aba06d1 100644 --- a/create/mysql/schema.sql +++ b/create/mysql/schema.sql @@ -318,6 +318,8 @@ CREATE TABLE items ( formula varchar(255) DEFAULT '0' NOT NULL, error varchar(128) DEFAULT '' NOT NULL, + lastlogsize int(4) DEFAULT '0' NOT NULL, + PRIMARY KEY (itemid), UNIQUE shortname (hostid,key_), -- KEY (hostid), @@ -337,6 +339,7 @@ CREATE TABLE media ( sendto varchar(100) DEFAULT '' NOT NULL, active int(4) DEFAULT '0' NOT NULL, severity int(4) DEFAULT '63' NOT NULL, + period varchar(100) DEFAULT '1-7,00:00-23:59' NOT NULL, PRIMARY KEY (mediaid), KEY (userid), KEY (mediatypeid) @@ -542,6 +545,7 @@ CREATE TABLE screens_items ( height int(4) DEFAULT '200' NOT NULL, x int(4) DEFAULT '0' NOT NULL, y int(4) DEFAULT '0' NOT NULL, + colspan int(4) DEFAULT '0' NOT NULL, PRIMARY KEY (screenitemid) ) TYPE=InnoDB; diff --git a/create/postgresql/schema.sql b/create/postgresql/schema.sql index 6c1f7131..cac5d9ac 100644 --- a/create/postgresql/schema.sql +++ b/create/postgresql/schema.sql @@ -75,6 +75,7 @@ CREATE TABLE items ( snmpv3_privpassphrase varchar(64) DEFAULT '' NOT NULL, formula varchar(255) DEFAULT '{.last(0)}' NOT NULL, error varchar(128) DEFAULT '' NOT NULL, + lastlogsize int4 DEFAULT '0' NOT NULL, PRIMARY KEY (itemid), FOREIGN KEY (hostid) REFERENCES hosts ); @@ -357,6 +358,7 @@ CREATE TABLE media ( sendto varchar(100) DEFAULT '' NOT NULL, active int4 DEFAULT '0' NOT NULL, severity int4 DEFAULT '63' NOT NULL, + period varchar(100) DEFAULT '1-7,00:00-23:59' NOT NULL, PRIMARY KEY (mediaid), FOREIGN KEY (userid) REFERENCES users, FOREIGN KEY (mediatypeid) REFERENCES media_type @@ -556,6 +558,7 @@ CREATE TABLE screens_items ( height int4 DEFAULT '200' NOT NULL, x int4 DEFAULT '0' NOT NULL, y int4 DEFAULT '0' NOT NULL, + colspan int4 DEFAULT '0' NOT NULL, PRIMARY KEY (screenitemid) ); diff --git a/frontends/php/config.php b/frontends/php/config.php index 4fb41c14..d5c00d86 100644 --- a/frontends/php/config.php +++ b/frontends/php/config.php @@ -436,27 +436,32 @@ show_table_header(S_ESCALATION_DETAILS_BIG); table_begin(); - table_header(array(S_STEP,S_DESCRIPTION_SMALL,S_ACTIONS)); + table_header(array(S_LEVEL,S_DELAY_BEFORE_ACTION,S_TIME,S_ACTIONS)); table_row(array( 1, - "30 seconds on this level", - "Increase escalation level"),$col++); + "30", + "1-5,09:00-18:00", + "Execute action"),$col++); table_row(array( 2, - "60 seconds on this level", - "Increase escalation level"),$col++); + "30", + "2-7,00:00-23:59", + "Execute action"),$col++); table_row(array( - 1, - "", - "Increase severity"),$col++); + 3, + "30", + "09:00-18:00", + "Execute action"),$col++); table_row(array( - 1, - "", - "Set escalation level to 5"),$col++); + 4, + "0", + "09:00-18:00", + "Increase severity"),$col++); table_row(array( - 1, - "", + 5, + "300", + "09:00-18:00", "Increase administrative hierarcy"),$col++); $result=DBselect("select escalationid, name from escalations order by name"); diff --git a/frontends/php/history.php b/frontends/php/history.php index 93451b1c..b0fc6bc1 100644 --- a/frontends/php/history.php +++ b/frontends/php/history.php @@ -162,7 +162,7 @@ } else if($item["value_type"]==ITEM_VALUE_TYPE_LOG) { - $sql="select clock,value from history_log where itemid=".$_GET["itemid"]." and clock>$time and clock<$till order by id,clock desc"; + $sql="select clock,value from history_log where itemid=".$_GET["itemid"]." and clock>$time and clock<$till order by id desc, clock desc"; } else { diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 0a94db27..321f0058 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -1957,7 +1957,7 @@ echo "</head>"; # Add Media definition - function add_media( $userid, $mediatypeid, $sendto, $severity, $active) + function add_media( $userid, $mediatypeid, $sendto, $severity, $active, $period) { $c=count($severity); $s=0; @@ -1965,13 +1965,13 @@ echo "</head>"; { $s=$s|pow(2,(int)$severity[$i]); } - $sql="insert into media (userid,mediatypeid,sendto,active,severity) values ($userid,'$mediatypeid','$sendto',$active,$s)"; + $sql="insert into media (userid,mediatypeid,sendto,active,severity,period) values ($userid,'$mediatypeid','$sendto',$active,$s,'$period')"; return DBexecute($sql); } # Update Media definition - function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active) + function update_media($mediaid, $userid, $mediatypeid, $sendto, $severity, $active, $period) { $c=count($severity); $s=0; @@ -1979,7 +1979,7 @@ echo "</head>"; { $s=$s|pow(2,(int)$severity[$i]); } - $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto='$sendto', active=$active,severity=$s where mediaid=$mediaid"; + $sql="update media set userid=$userid, mediatypeid=$mediatypeid, sendto='$sendto', active=$active,severity=$s,period=`$period` where mediaid=$mediaid"; return DBexecute($sql); } diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index 348f38fd..796bb2b2 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -118,6 +118,9 @@ $snmpv3_authpassphrase=addslashes($snmpv3_authpassphrase); $snmpv3_privpassphrase=addslashes($snmpv3_privpassphrase); + $sql="update items set lastlogsize=0 where itemid=$itemid and key_<>'$key'"; + DBexecute($sql); + $sql="update items set description='$description',key_='$key',hostid=$hostid,delay=$delay,history=$history,nextcheck=0,status=$status,type=$type,snmp_community='$snmp_community',snmp_oid='$snmp_oid',value_type=$value_type,trapper_hosts='$trapper_hosts',snmp_port=$snmp_port,units='$units',multiplier=$multiplier,delta=$delta,snmpv3_securityname='$snmpv3_securityname',snmpv3_securitylevel=$snmpv3_securitylevel,snmpv3_authpassphrase='$snmpv3_authpassphrase',snmpv3_privpassphrase='$snmpv3_privpassphrase',formula='$formula',trends=$trends where itemid=$itemid"; $result=DBexecute($sql); if($result) diff --git a/frontends/php/include/local_en.inc.php b/frontends/php/include/local_en.inc.php index 5170b98c..87efa7f8 100644 --- a/frontends/php/include/local_en.inc.php +++ b/frontends/php/include/local_en.inc.php @@ -25,7 +25,7 @@ // about.php define("S_ABOUT_ZABBIX", "About ZABBIX"); - define("S_INFORMATION_ABOUT_ZABBIX", "Information about ZABBIX (v1.1alpha9)"); + define("S_INFORMATION_ABOUT_ZABBIX", "Information about ZABBIX (v1.1alpha10)"); define("S_HOMEPAGE_OF_ZABBIX", "Homepage of ZABBIX"); define("S_HOMEPAGE_OF_ZABBIX_DETAILS", "This is home page of ZABBIX."); define("S_LATEST_ZABBIX_MANUAL", "Latest ZABBIX Manual"); @@ -168,7 +168,8 @@ define("S_NO_ESCALATION_RULES_DEFINED", "No escalation rules defined"); define("S_NO_ESCALATION_DETAILS", "No escalation details"); define("S_ESCALATION_DETAILS_BIG", "ESCALATION DETAILS"); - define("S_STEP", "Step"); + define("S_LEVEL", "Level"); + define("S_DELAY_BEFORE_ACTION", "Delay before action"); define("S_IMAGES", "Images"); define("S_IMAGE", "Image"); define("S_IMAGES_BIG", "IMAGES"); @@ -192,7 +193,7 @@ define("S_COMPARE", "Compare"); // Footer - define("S_ZABBIX_VER", "ZABBIX 1.1alpha9"); + define("S_ZABBIX_VER", "ZABBIX 1.1alpha10"); define("S_COPYRIGHT_BY", "Copyright 2001-2005 by "); define("S_CONNECTED_AS", "Connected as"); define("S_SIA_ZABBIX", "SIA Zabbix"); @@ -404,6 +405,7 @@ define("S_MEDIA_DELETED", "Media deleted"); define("S_CANNOT_DELETE_MEDIA", "Cannot delete media"); define("S_SEND_TO", "Send to"); + define("S_WHEN_ACTIVE", "When active"); define("S_NO_MEDIA_DEFINED", "No media defined"); define("S_NEW_MEDIA", "New media"); define("S_USE_IF_SEVERITY", "Use if severity"); @@ -515,6 +517,7 @@ // screenedit.php define("S_MAP", "Map"); define("S_PLAIN_TEXT", "Plain text"); + define("S_COLSPAN", "Colspan"); // screens.php define("S_CUSTOM_SCREENS", "Custom screens"); diff --git a/frontends/php/include/screens.inc.php b/frontends/php/include/screens.inc.php index 1439e45e..6f2f955c 100644 --- a/frontends/php/include/screens.inc.php +++ b/frontends/php/include/screens.inc.php @@ -55,17 +55,17 @@ return DBexecute($sql); } - function add_screen_item($resource,$screenid,$x,$y,$resourceid,$width,$height) + function add_screen_item($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan) { $sql="delete from screens_items where screenid=$screenid and x=$x and y=$y"; DBexecute($sql); - $sql="insert into screens_items (resource,screenid,x,y,resourceid,width,height) values ($resource,$screenid,$x,$y,$resourceid,$width,$height)"; + $sql="insert into screens_items (resource,screenid,x,y,resourceid,width,height,colspan) values ($resource,$screenid,$x,$y,$resourceid,$width,$height,$colspan)"; return DBexecute($sql); } - function update_screen_item($screenitemid,$resource,$resourceid,$width,$height) + function update_screen_item($screenitemid,$resource,$resourceid,$width,$height,$colspan) { - $sql="update screens_items set resource=$resource,resourceid=$resourceid,width=$width,height=$height where screenitemid=$screenitemid"; + $sql="update screens_items set resource=$resource,resourceid=$resourceid,width=$width,height=$height,colspan=$colspan where screenitemid=$screenitemid"; return DBexecute($sql); } diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php index 23e68379..bbaabf5d 100644 --- a/frontends/php/include/services.inc.php +++ b/frontends/php/include/services.inc.php @@ -31,6 +31,11 @@ } if( isset($linktrigger)&&($linktrigger=="on") ) { + if(!isset($triggerid)) + { + error("Choose trigger first"); + return false; + } // $trigger=get_trigger_by_triggerid($triggerid); // $description=$trigger["description"]; // if( strstr($description,"%s")) diff --git a/frontends/php/latestalarms.php b/frontends/php/latestalarms.php index b8205b76..409905d0 100644 --- a/frontends/php/latestalarms.php +++ b/frontends/php/latestalarms.php @@ -97,6 +97,7 @@ $h2=$h2.form_select("hostid",$row["hostid"],$row["host"]); } $h2=$h2."</select> "; + if(isset($_GET["start"])) { $h2=$h2."<input class=\"biginput\" name=\"start\" type=hidden value=".$_GET["start"]." size=8>"; diff --git a/frontends/php/media.php b/frontends/php/media.php index e68cdb41..50d11ee4 100644 --- a/frontends/php/media.php +++ b/frontends/php/media.php @@ -60,7 +60,7 @@ if(isset($_GET["3"])) $severity=array_merge($severity,array(3)); if(isset($_GET["4"])) $severity=array_merge($severity,array(4)); if(isset($_GET["5"])) $severity=array_merge($severity,array(5)); - $result=add_media( $_GET["userid"], $_GET["mediatypeid"], $_GET["sendto"],$severity,$_GET["active"]); + $result=add_media( $_GET["userid"], $_GET["mediatypeid"], $_GET["sendto"],$severity,$_GET["active"],$_GET["period"]); show_messages($result, S_MEDIA_ADDED, S_CANNOT_ADD_MEDIA); } elseif($_GET["register"]=="update") @@ -72,7 +72,7 @@ if(isset($_GET["3"])) $severity=array_merge($severity,array(3)); if(isset($_GET["4"])) $severity=array_merge($severity,array(4)); if(isset($_GET["5"])) $severity=array_merge($severity,array(5)); - $result=update_media($_GET["mediaid"], $_GET["userid"], $_GET["mediatypeid"], $_GET["sendto"],$severity,$_GET["active"]); + $result=update_media($_GET["mediaid"], $_GET["userid"], $_GET["mediatypeid"], $_GET["sendto"],$severity,$_GET["active"],$_GET["period"]); show_messages($result,S_MEDIA_UPDATED,S_CANNOT_UPDATE_MEDIA); } elseif($_GET["register"]=="delete") @@ -89,11 +89,11 @@ ?> <?php - $sql="select m.mediaid,mt.description,m.sendto,m.active from media m,media_type mt where m.mediatypeid=mt.mediatypeid and m.userid=".$_GET["userid"]." order by mt.type,m.sendto"; + $sql="select m.mediaid,mt.description,m.sendto,m.active,m.period from media m,media_type mt where m.mediatypeid=mt.mediatypeid and m.userid=".$_GET["userid"]." order by mt.type,m.sendto"; $result=DBselect($sql); table_begin(); - table_header(array(S_TYPE, S_SEND_TO,S_STATUS,S_ACTIONS)); + table_header(array(S_TYPE,S_SEND_TO,S_WHEN_ACTIVE,S_STATUS,S_ACTIONS)); $col=0; while($row=DBfetch($result)) @@ -110,6 +110,7 @@ table_row(array( $row["description"], $row["sendto"], + $row["period"], $status, $actions ),$col++); @@ -126,12 +127,13 @@ <?php if(isset($_GET["mediaid"])) { - $sql="select m.severity,m.sendto,m.active,m.mediatypeid from media m where m.mediaid=".$_GET["mediaid"]; + $sql="select m.severity,m.sendto,m.active,m.mediatypeid,m.period from media m where m.mediaid=".$_GET["mediaid"]; $result=DBselect($sql); $severity=DBget_field($result,0,0); $sendto=DBget_field($result,0,1); $active=DBget_field($result,0,2); $mediatypeid=DBget_field($result,0,3); + $period=DBget_field($result,0,4); } else { @@ -139,6 +141,7 @@ $severity=63; $mediatypeid=-1; $active=0; + $period="1-7,00:00-23:59"; } show_form_begin("media.media"); @@ -178,23 +181,11 @@ echo "<input class=\"biginput\" name=\"sendto\" size=20 value='$sendto'>"; show_table2_v_delimiter($col++); -/* echo nbsp(S_USE_IF_SEVERITY); + echo nbsp(S_WHEN_ACTIVE); show_table2_h_delimiter(); - echo "<select multiple class=\"biginput\" name=\"severity[]\" size=\"5\">"; - $selected=iif( (1&$severity) == 1,"selected",""); - echo "<option value=\"0\" $selected>".S_NOT_CLASSIFIED; - $selected=iif( (2&$severity) == 2,"selected",""); - echo "<option value=\"1\" $selected>".S_INFORMATION; - $selected=iif( (4&$severity) == 4,"selected",""); - echo "<option value=\"2\" $selected>".S_WARNING; - $selected=iif( (8&$severity) == 8,"selected",""); - echo "<option value=\"3\" $selected>".S_AVERAGE; - $selected=iif( (16&$severity) ==16,"selected",""); - echo "<option value=\"4\" $selected>".S_HIGH; - $selected=iif( (32&$severity) ==32,"selected",""); - echo "<option value=\"5\" $selected>".S_DISASTER; - echo "</select>";*/ + echo "<input class=\"biginput\" name=\"period\" size=48 value='$period'>"; + show_table2_v_delimiter($col++); echo nbsp(S_USE_IF_SEVERITY); show_table2_h_delimiter(); $checked=iif( (1&$severity) == 1,"checked",""); diff --git a/frontends/php/screenedit.php b/frontends/php/screenedit.php index 1fa1ebb3..f418deef 100644 --- a/frontends/php/screenedit.php +++ b/frontends/php/screenedit.php @@ -49,7 +49,7 @@ // delete_screen_item($_GET["screenitemid"]); // unset($_GET["screenitemid"]); // } - $result=add_screen_item($_GET["resource"],$_GET["screenid"],$_GET["x"],$_GET["y"],$_GET["resourceid"],$_GET["width"],$_GET["height"]); + $result=add_screen_item($_GET["resource"],$_GET["screenid"],$_GET["x"],$_GET["y"],$_GET["resourceid"],$_GET["width"],$_GET["height"],$_GET["colspan"]); unset($_GET["x"]); show_messages($result, S_ITEM_ADDED, S_CANNOT_ADD_ITEM); } @@ -61,7 +61,7 @@ } if($_GET["register"]=="update") { - $result=update_screen_item($_GET["screenitemid"],$_GET["resource"],$_GET["resourceid"],$_GET["width"],$_GET["height"]); + $result=update_screen_item($_GET["screenitemid"],$_GET["resource"],$_GET["resourceid"],$_GET["width"],$_GET["height"],$_GET["colspan"]); show_messages($result, S_ITEM_UPDATED, S_CANNOT_UPDATE_ITEM); unset($_GET["x"]); } @@ -81,11 +81,6 @@ echo "<TR>"; for($c=0;$c<$row["cols"];$c++) { - echo "<TD align=\"center\" valign=\"top\">\n"; - - echo "<a name=\"form\"></a>"; - echo "<form method=\"get\" action=\"screenedit.php\">"; - $iresult=DBSelect("select * from screens_items where screenid=$screenid and x=$c and y=$r"); if(DBnum_rows($iresult)>0) { @@ -95,6 +90,7 @@ $resourceid=$irow["resourceid"]; $width=$irow["width"]; $height=$irow["height"]; + $colspan=$irow["colspan"]; } else { @@ -103,7 +99,19 @@ $resourceid=0; $width=500; $height=100; + $colspan=0; + } + if($colspan==0) + { + echo "<TD align=\"center\" valign=\"top\">\n"; + } + else + { + echo "<TD align=\"center\" valign=\"top\" colspan=\"$colspan\">\n"; + $c=$c+$colspan-1; } + echo "<a name=\"form\"></a>"; + echo "<form method=\"get\" action=\"screenedit.php\">"; if(isset($_GET["x"])&&($_GET["x"]==$c)&&($_GET["y"]==$r)) { @@ -112,6 +120,7 @@ $screenitemid=@iif(isset($_GET["screenitemid"]),$_GET["screenitemid"],$screenitemid); $width=@iif(isset($_GET["width"]),$_GET["width"],$width); $height=@iif(isset($_GET["height"]),$_GET["height"],$height); + $colspan=@iif(isset($_GET["colspan"]),$_GET["colspan"],$colspan); show_form_begin("screenedit.cell"); echo S_SCREEN_CELL_CONFIGURATION; @@ -225,6 +234,11 @@ echo "<input class=\"biginput\" name=\"height\" type=\"hidden\" size=5 value=\"$height\">"; } + show_table2_v_delimiter(); + echo S_COLSPAN; + show_table2_h_delimiter(); + echo "<input class=\"biginput\" name=\"colspan\" size=2 value=\"$colspan\">"; + show_table2_v_delimiter2(); echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"add\">"; if($resourceid!=0) diff --git a/frontends/php/screens.php b/frontends/php/screens.php index 7799a665..a93a4dfe 100644 --- a/frontends/php/screens.php +++ b/frontends/php/screens.php @@ -104,10 +104,10 @@ echo "<TR>"; for($c=0;$c<$row["cols"];$c++) { - echo "<TD align=\"center\" valign=\"top\">\n"; $sql="select * from screens_items where screenid=$screenid and x=$c and y=$r"; $iresult=DBSelect($sql); + $colspan=0; if(DBnum_rows($iresult)>0) { $irow=DBfetch($iresult); @@ -116,8 +116,18 @@ $resourceid=$irow["resourceid"]; $width=$irow["width"]; $height=$irow["height"]; + $colspan=$irow["colspan"]; } + if($colspan==0) + { + echo "<TD align=\"center\" valign=\"top\">\n"; + } + else + { + echo "<TD align=\"center\" valign=\"top\" colspan=\"$colspan\">\n"; + $c=$c+$colspan-1; + } if(DBnum_rows($iresult)>0) { if($resource == 0) diff --git a/frontends/php/services.php b/frontends/php/services.php index 3057bd88..1d41c498 100644 --- a/frontends/php/services.php +++ b/frontends/php/services.php @@ -52,7 +52,7 @@ } if($_GET["register"]=="add server") { - $result=add_host_to_services($_GET["hostid"],$_GET["serviceid"]); + $result=add_host_to_services($_GET["serverid"],$_GET["serviceid"]); show_messages($result, S_TRIGGER_ADDED, S_CANNOT_ADD_TRIGGER); } if($_GET["register"]=="add link") @@ -229,6 +229,11 @@ echo S_SERVICE; $col=0; + if(isset($_GET["groupid"])&&($_GET["groupid"]==0)) + { + unset($_GET["groupid"]); + } + show_table2_v_delimiter($col++); echo "<form method=\"get\" action=\"services.php\">"; if(isset($_GET["serviceid"])) @@ -308,27 +313,80 @@ show_table2_v_delimiter($col++); echo S_TRIGGER; show_table2_h_delimiter(); - $result=DBselect("select triggerid,description from triggers order by description"); - echo "<select class=\"biginput\" name=\"triggerid\" size=1>"; - for($i=0;$i<DBnum_rows($result);$i++) - { - $triggerid_=DBget_field($result,$i,0); + $h2="<select class=\"biginput\" name=\"groupid\" onChange=\"submit()\">"; + $h2=$h2.form_select("groupid",0,S_ALL_SMALL); + $result=DBselect("select groupid,name from groups order by name"); + while($row=DBfetch($result)) + { +// Check if at least one host with read permission exists for this group + $result2=DBselect("select h.hostid,h.host from hosts h,items i,hosts_groups hg where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$row["groupid"]." and hg.hostid=h.hostid group by h.hostid,h.host order by h.host"); + $cnt=0; + while($row2=DBfetch($result2)) + { + if(!check_right("Host","R",$row2["hostid"])) + { + continue; + } + $cnt=1; break; + } + if($cnt!=0) + { + $h2=$h2.form_select("groupid",$row["groupid"],$row["name"]); + } + } + $h2=$h2."</select> "; + + $h2=$h2."<select class=\"biginput\" name=\"hostid\" onChange=\"submit()\">"; + $h2=$h2.form_select("hostid",0,S_SELECT_HOST_DOT_DOT_DOT); + + if(isset($_GET["groupid"])) + { + $sql="select h.hostid,h.host from hosts h,items i,hosts_groups hg where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid and hg.groupid=".$_GET["groupid"]." and hg.hostid=h.hostid group by h.hostid,h.host order by h.host"; + } + else + { + $sql="select h.hostid,h.host from hosts h,items i where h.status=".HOST_STATUS_MONITORED." and h.hostid=i.hostid group by h.hostid,h.host order by h.host"; + } + + $result=DBselect($sql); + while($row=DBfetch($result)) + { + if(!check_right("Host","R",$row["hostid"])) + { + continue; + } + $h2=$h2.form_select("hostid",$row["hostid"],$row["host"]); + } + $h2=$h2."</select> "; + echo $h2; + + if(isset($_GET["hostid"])) + { + show_table2_v_delimiter($col++); + echo " "; + show_table2_h_delimiter(); + $result=DBselect("select t.triggerid,t.description from triggers t,functions f, hosts h, items i where h.hostid=i.hostid and f.itemid=i.itemid and t.triggerid=f.triggerid and h.hostid=".$_GET["hostid"]." order by t.description"); + echo "<select class=\"biginput\" name=\"triggerid\" size=1>"; + for($i=0;$i<DBnum_rows($result);$i++) + { + $triggerid_=DBget_field($result,$i,0); // $description_=DBget_field($result,$i,1); // if( strstr($description_,"%s")) // { - $description_=expand_trigger_description($triggerid_); + $description_=expand_trigger_description($triggerid_); // } // if(isset($_GET["triggerid"]) && ($_GET["triggerid"]==$triggerid_)) - if(isset($triggerid) && ($triggerid==$triggerid_)) - { - echo "<OPTION VALUE='$triggerid_' SELECTED>$description_"; - } - else - { - echo "<OPTION VALUE='$triggerid_'>$description_"; - } - } - echo "</SELECT>"; + if(isset($triggerid) && ($triggerid==$triggerid_)) + { + echo "<OPTION VALUE='$triggerid_' SELECTED>$description_"; + } + else + { + echo "<OPTION VALUE='$triggerid_'>$description_"; + } + } + echo "</SELECT>"; + } show_table2_v_delimiter($col++); echo nbsp(S_SORT_ORDER_0_999); @@ -433,7 +491,7 @@ echo S_SERVER; show_table2_h_delimiter(); $result=DBselect("select hostid,host from hosts order by host"); - echo "<select class=\"biginput\" name=\"hostid\" size=1>"; + echo "<select class=\"biginput\" name=\"serverid\" size=1>"; while($row=DBfetch($result)) { echo "<OPTION VALUE='".$row["hostid"]."'>".$row["host"]; diff --git a/include/common.h b/include/common.h index 7f932c6c..e5ba2c52 100644 --- a/include/common.h +++ b/include/common.h @@ -20,13 +20,10 @@ /*#define TESTTEST*/ -/* -#define ZABBIX_THREADS -*/ -#define IT_HELPDESK - #ifndef ZABBIX_COMMON_H #define ZABBIX_COMMON_H + +#define ZABBIX_VERSION "1.1alpha10" #define SUCCEED 0 #define FAIL (-1) diff --git a/include/db.c b/include/db.c index dd9349fa..f036cc79 100644 --- a/include/db.c +++ b/include/db.c @@ -41,18 +41,6 @@ PGconn *conn; #endif -#ifdef ZABBIX_THREADS -void DBclose_thread(MYSQL *database) -{ -#ifdef HAVE_MYSQL - mysql_close(database); -#endif -#ifdef HAVE_PGSQL - PQfinish(conn); -#endif -} -#endif - void DBclose(void) { #ifdef HAVE_MYSQL @@ -67,70 +55,6 @@ void DBclose(void) * Connect to the database. * If fails, program terminates. */ -#ifdef ZABBIX_THREADS -void DBconnect_thread(MYSQL *database) -{ - for(;;) - { - /* zabbix_log(LOG_LEVEL_ERR, "[%s] [%s] [%s]\n",dbname, dbuser, dbpassword ); */ -#ifdef HAVE_MYSQL - /* For MySQL >3.22.00 */ - /* if( ! mysql_connect( &mysql, NULL, dbuser, dbpassword ) )*/ - mysql_init(database); - if( ! mysql_real_connect( database, CONFIG_DBHOST, CONFIG_DBUSER, CONFIG_DBPASSWORD, CONFIG_DBNAME, 3306, CONFIG_DBSOCKET,0 ) ) - { - fprintf(stderr, "Failed to connect to database: Error: %s\n",mysql_error(database) ); - zabbix_log(LOG_LEVEL_ERR, "Failed to connect to database: Error: %s",mysql_error(database) ); - if( (ER_SERVER_SHUTDOWN != mysql_errno(database)) && (CR_SERVER_GONE_ERROR != mysql_errno(database))) - { - exit(FAIL); - } - } - else - { - if( mysql_select_db( database, CONFIG_DBNAME ) != 0 ) - - { - fprintf(stderr, "Failed to select database: Error: %s\n",mysql_error(database) ); - zabbix_log(LOG_LEVEL_ERR, "Failed to select database: Error: %s",mysql_error(database) ); - exit( FAIL ); - } - else - { - break; - } - } -#endif -#ifdef HAVE_PGSQL -/* conn = PQsetdb(pghost, pgport, pgoptions, pgtty, dbName); */ -/* conn = PQsetdb(NULL, NULL, NULL, NULL, dbname);*/ - conn = PQsetdbLogin(CONFIG_DBHOST, NULL, NULL, NULL, CONFIG_DBNAME, CONFIG_DBUSER, CONFIG_DBPASSWORD ); - -/* check to see that the backend connection was successfully made */ - if (PQstatus(conn) != CONNECTION_OK) - { - fprintf(stderr, "Connection to database '%s' failed.\n", CONFIG_DBNAME); - zabbix_log(LOG_LEVEL_ERR, "Connection to database '%s' failed.\n", CONFIG_DBNAME); - fprintf(stderr, "%s\n", PQerrorMessage(conn)); - zabbix_log(LOG_LEVEL_ERR, "%s", PQerrorMessage(conn)); - exit(FAIL); - } - else - { - break; - } -#endif - fprintf(stderr, "Will retry to connect to the database after 30 seconds\n"); - zabbix_log(LOG_LEVEL_ERR, "Will retry to connect to the database after 30 seconds"); - sleep(30); - } -} -#endif - -/* - * Connect to the database. - * If fails, program terminates. - */ void DBconnect(void) { for(;;) @@ -189,99 +113,6 @@ void DBconnect(void) } } -#ifdef ZABBIX_THREADS -/* - * Execute SQL statement. For non-select statements only. - * If fails, program terminates. - */ -int DBexecute_thread(MYSQL *database, char *query) -{ -/* Do not include any code here. Will break HAVE_PGSQL section */ -#ifdef HAVE_MYSQL - zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s",query); - while( mysql_query(database,query) != 0) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s [%d]", mysql_error(database), mysql_errno(database) ); - if( (ER_SERVER_SHUTDOWN != mysql_errno(database)) && (CR_SERVER_GONE_ERROR != mysql_errno(database))) - { - return FAIL; - } - sleep(30); - } -#endif -#ifdef HAVE_PGSQL - PGresult *result; - - zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s",query); - result = PQexec(conn,query); - - if( result==NULL) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", "Result is NULL" ); - PQclear(result); - return FAIL; - } - if( PQresultStatus(result) != PGRES_COMMAND_OK) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", PQresStatus(PQresultStatus(result)) ); - PQclear(result); - return FAIL; - } - PQclear(result); -#endif -/* zabbix_set_log_level(LOG_LEVEL_WARNING);*/ - return SUCCEED; -} -#endif - -#ifdef ZABBIX_THREADS -/* - * Execute SQL statement. For select statements only. - * If fails, program terminates. - */ -DB_RESULT *DBselect_thread(MYSQL *database, char *query) -{ -/* Do not include any code here. Will break HAVE_PGSQL section */ -#ifdef HAVE_MYSQL - zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s",query); - while(mysql_query(database,query) != 0) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s [%d]", mysql_error(database), mysql_errno(database) ); - if( (ER_SERVER_SHUTDOWN != mysql_errno(database)) && (CR_SERVER_GONE_ERROR != mysql_errno(database))) - { - exit(FAIL); - } - sleep(30); - } -/* zabbix_set_log_level(LOG_LEVEL_WARNING);*/ - return mysql_store_result(database); -#endif -#ifdef HAVE_PGSQL - PGresult *result; - - zabbix_log( LOG_LEVEL_DEBUG, "Executing query:%s",query); - result = PQexec(conn,query); - - if( result==NULL) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", "Result is NULL" ); - exit( FAIL ); - } - if( PQresultStatus(result) != PGRES_TUPLES_OK) - { - zabbix_log( LOG_LEVEL_ERR, "Query::%s",query); - zabbix_log(LOG_LEVEL_ERR, "Query failed:%s", PQresStatus(PQresultStatus(result)) ); - exit( FAIL ); - } -#endif -} -#endif - /* * Execute SQL statement. For non-select statements only. * If fails, program terminates. @@ -454,42 +285,6 @@ int DBnum_rows(DB_RESULT *result) #endif } -#ifdef ZABBIX_THREADS -/* - * Get function value. - */ -int DBget_function_result_thread(MYSQL *database, double *result,char *functionid) -{ - DB_RESULT *dbresult; - int res = SUCCEED; - - char sql[MAX_STRING_LEN]; - -/* 0 is added to distinguish between lastvalue==NULL and empty result */ - snprintf( sql, sizeof(sql)-1, "select 0,lastvalue from functions where functionid=%s", functionid ); - dbresult = DBselect_thread(database, sql); - - if(DBnum_rows(dbresult) == 0) - { - zabbix_log(LOG_LEVEL_WARNING, "No function for functionid:[%s]", functionid ); - zabbix_syslog("No function for functionid:[%s]", functionid ); - res = FAIL; - } - else if(DBget_field(dbresult,0,1) == NULL) - { - zabbix_log(LOG_LEVEL_DEBUG, "function.lastvalue==NULL [%s]", functionid ); - res = FAIL; - } - else - { - *result=atof(DBget_field(dbresult,0,1)); - } - DBfree_result(dbresult); - - return res; -} -#endif - /* * Get function value. */ @@ -524,64 +319,6 @@ int DBget_function_result(double *result,char *functionid) return res; } -#ifdef ZABBIX_THREADS -/* Returns previous trigger value. If not value found, return TRIGGER_VALUE_FALSE */ -int DBget_prev_trigger_value_thread(MYSQL *database, int triggerid) -{ - char sql[MAX_STRING_LEN]; - int clock; - int value; - - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_prev_trigger_value[%d]", triggerid); - - snprintf(sql,sizeof(sql)-1,"select max(clock) from alarms where triggerid=%d",triggerid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - DBfree_result(result); - return TRIGGER_VALUE_UNKNOWN; - } - clock=atoi(DBget_field(result,0,0)); - DBfree_result(result); - - snprintf(sql,sizeof(sql),"select max(clock) from alarms where triggerid=%d and clock<%d",triggerid,clock); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database,sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - DBfree_result(result); -/* Assume that initially Trigger value is False. Otherwise alarms will not be generated when -status changes to TRUE for te first time */ - return TRIGGER_VALUE_FALSE; -/* return TRIGGER_VALUE_UNKNOWN;*/ - } - clock=atoi(DBget_field(result,0,0)); - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"select value from alarms where triggerid=%d and clock=%d",triggerid,clock); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database,sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result of [%s] is empty", sql ); - DBfree_result(result); - return TRIGGER_VALUE_UNKNOWN; - } - value=atoi(DBget_field(result,0,0)); - DBfree_result(result); - - return value; -} -#endif - /* Returns previous trigger value. If not value found, return TRIGGER_VALUE_FALSE */ int DBget_prev_trigger_value(int triggerid) { @@ -638,51 +375,6 @@ status changes to TRUE for te first time */ return value; } -#ifdef ZABBIX_THREADS -/* SUCCEED if latest alarm with triggerid has this status */ -/* Rewrite required to simplify logic ?*/ -int latest_alarm_thread(MYSQL *database,int triggerid, int status) -{ - char sql[MAX_STRING_LEN]; - int clock; - DB_RESULT *result; - int ret = FAIL; - - - zabbix_log(LOG_LEVEL_DEBUG,"In latest_alarm()"); - - snprintf(sql,sizeof(sql)-1,"select max(clock) from alarms where triggerid=%d",triggerid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - ret = FAIL; - } - else - { - clock=atoi(DBget_field(result,0,0)); - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"select value from alarms where triggerid=%d and clock=%d",triggerid,clock); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - if(DBnum_rows(result)==1) - { - if(atoi(DBget_field(result,0,0)) == status) - { - ret = SUCCEED; - } - } - } - - DBfree_result(result); - - return ret; -} -#endif - /* SUCCEED if latest alarm with triggerid has this status */ /* Rewrite required to simplify logic ?*/ int latest_alarm(int triggerid, int status) @@ -726,51 +418,6 @@ int latest_alarm(int triggerid, int status) return ret; } -#ifdef ZABBIX_THREADS -/* SUCCEED if latest service alarm has this status */ -/* Rewrite required to simplify logic ?*/ -int latest_service_alarm_thread(MYSQL *database, int serviceid, int status) -{ - char sql[MAX_STRING_LEN]; - int clock; - DB_RESULT *result; - int ret = FAIL; - - - zabbix_log(LOG_LEVEL_DEBUG,"In latest_service_alarm()"); - - snprintf(sql,sizeof(sql)-1,"select max(clock) from service_alarms where serviceid=%d",serviceid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - ret = FAIL; - } - else - { - clock=atoi(DBget_field(result,0,0)); - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"select value from service_alarms where serviceid=%d and clock=%d",serviceid,clock); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - if(DBnum_rows(result)==1) - { - if(atoi(DBget_field(result,0,0)) == status) - { - ret = SUCCEED; - } - } - } - - DBfree_result(result); - - return ret; -} -#endif - /* SUCCEED if latest service alarm has this status */ /* Rewrite required to simplify logic ?*/ int latest_service_alarm(int serviceid, int status) @@ -814,28 +461,6 @@ int latest_service_alarm(int serviceid, int status) return ret; } -#ifdef ZABBIX_THREADS -int add_alarm_thread(MYSQL *database, int triggerid,int status,int clock) -{ - char sql[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_alarm()"); - - if(latest_alarm_thread(database, triggerid,status) == SUCCEED) - { - return SUCCEED; - } - - snprintf(sql,sizeof(sql)-1,"insert into alarms(triggerid,clock,value) values(%d,%d,%d)", triggerid, clock, status); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - DBexecute_thread(database, sql); - - zabbix_log(LOG_LEVEL_DEBUG,"End of add_alarm()"); - - return SUCCEED; -} -#endif - int add_alarm(int triggerid,int status,int clock) { char sql[MAX_STRING_LEN]; @@ -856,28 +481,6 @@ int add_alarm(int triggerid,int status,int clock) return SUCCEED; } -#ifdef ZABBIX_THREADS -int DBadd_service_alarm_thread(MYSQL *database, int serviceid,int status,int clock) -{ - char sql[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_service_alarm()"); - - if(latest_service_alarm_thread(database, serviceid,status) == SUCCEED) - { - return SUCCEED; - } - - snprintf(sql,sizeof(sql)-1,"insert into service_alarms(serviceid,clock,value) values(%d,%d,%d)", serviceid, clock, status); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - DBexecute_thread(database, sql); - - zabbix_log(LOG_LEVEL_DEBUG,"End of add_service_alarm()"); - - return SUCCEED; -} -#endif - int DBadd_service_alarm(int serviceid,int status,int clock) { char sql[MAX_STRING_LEN]; @@ -898,34 +501,6 @@ int DBadd_service_alarm(int serviceid,int status,int clock) return SUCCEED; } -#ifdef IT_HELPDESK -void update_problems(int triggerid, int value, int clock) -{ -} -#endif - -#ifdef ZABBIX_THREADS -int DBupdate_trigger_value_thread(MYSQL *database,int triggerid,int value,int clock) -{ - char sql[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In update_trigger_value[%d,%d,%d]", triggerid, value, clock); - add_alarm_thread(database, triggerid,value,clock); - - snprintf(sql,sizeof(sql)-1,"update triggers set value=%d,lastchange=%d where triggerid=%d",value,clock,triggerid); - DBexecute_thread(database,sql); - - if(TRIGGER_VALUE_UNKNOWN == value) - { - snprintf(sql,sizeof(sql)-1,"update functions set lastvalue=NULL where triggerid=%d",triggerid); - DBexecute_thread(database,sql); - } - - zabbix_log(LOG_LEVEL_DEBUG,"End of update_trigger_value()"); - return SUCCEED; -} -#endif - int DBupdate_trigger_value(int triggerid,int value,int clock) { char sql[MAX_STRING_LEN]; @@ -942,42 +517,10 @@ int DBupdate_trigger_value(int triggerid,int value,int clock) DBexecute(sql); } -#ifdef IT_HELPDESK - update_problems(triggerid,value,clock); -#endif - zabbix_log(LOG_LEVEL_DEBUG,"End of update_trigger_value()"); return SUCCEED; } -#ifdef ZABBIX_THREADS -void update_triggers_status_to_unknown_thread(MYSQL *database, int hostid,int clock) -{ - int i; - char sql[MAX_STRING_LEN]; - int triggerid; - - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In update_triggers_status_to_unknown()"); - - snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid from hosts h,items i,triggers t,functions f where f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and h.hostid=%d and i.key_ not in ('%s','%s','%s')",hostid,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - triggerid=atoi(DBget_field(result,i,0)); - DBupdate_trigger_value_thread(database, triggerid,TRIGGER_VALUE_UNKNOWN,clock); - } - - DBfree_result(result); - zabbix_log(LOG_LEVEL_DEBUG,"End of update_triggers_status_to_unknown()"); - - return; -} -#endif - void update_triggers_status_to_unknown(int hostid,int clock) { int i; @@ -1005,18 +548,6 @@ void update_triggers_status_to_unknown(int hostid,int clock) return; } -#ifdef ZABBIX_THREADS -void DBdelete_service_thread(MYSQL *database, int serviceid) -{ - char sql[MAX_STRING_LEN]; - - snprintf(sql,sizeof(sql)-1,"delete from services_links where servicedownid=%d or serviceupid=%d", serviceid, serviceid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from services where serviceid=%d", serviceid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_service(int serviceid) { char sql[MAX_STRING_LEN]; @@ -1027,28 +558,6 @@ void DBdelete_service(int serviceid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_services_by_triggerid_thread(MYSQL *database, int triggerid) -{ - int i, serviceid; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_services_by_triggerid(%d)", triggerid); - snprintf(sql,sizeof(sql)-1,"select serviceid from services where triggerid=%d", triggerid); - result = DBselect_thread(database,sql); - - for(i=0;i<DBnum_rows(result);i++) - { - serviceid=atoi(DBget_field(result,i,0)); - DBdelete_service_thread(database, serviceid); - } - DBfree_result(result); - - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_services_by_triggerid(%d)", triggerid); -} -#endif - void DBdelete_services_by_triggerid(int triggerid) { int i, serviceid; @@ -1069,29 +578,6 @@ void DBdelete_services_by_triggerid(int triggerid) zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_services_by_triggerid(%d)", triggerid); } -#ifdef ZABBIX_THREADS -void DBdelete_trigger_thread(MYSQL *database, int triggerid) -{ - char sql[MAX_STRING_LEN]; - - snprintf(sql,sizeof(sql)-1,"delete from trigger_depends where triggerid_down=%d or triggerid_up=%d", triggerid, triggerid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from functions where triggerid=%d", triggerid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from alarms where triggerid=%d", triggerid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from actions where triggerid=%d and scope=%d", triggerid, ACTION_SCOPE_TRIGGER); - DBexecute_thread(database, sql); - - DBdelete_services_by_triggerid_thread(database, triggerid); - - snprintf(sql,sizeof(sql)-1,"update sysmaps_links set triggerid=NULL where triggerid=%d", triggerid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from triggers where triggerid=%d", triggerid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_trigger(int triggerid) { char sql[MAX_STRING_LEN]; @@ -1113,31 +599,6 @@ void DBdelete_trigger(int triggerid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_triggers_by_itemid_thread(MYSQL *database, int itemid) -{ - int i, triggerid; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_triggers_by_itemid(%d)", itemid); - snprintf(sql,sizeof(sql)-1,"select triggerid from functions where itemid=%d", itemid); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - triggerid=atoi(DBget_field(result,i,0)); - DBdelete_trigger_thread(database, triggerid); - } - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"delete from functions where itemid=%d", itemid); - DBexecute_thread(database, sql); - - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_triggers_by_itemid(%d)", itemid); -} -#endif - void DBdelete_triggers_by_itemid(int itemid) { int i, triggerid; @@ -1161,16 +622,6 @@ void DBdelete_triggers_by_itemid(int itemid) zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_triggers_by_itemid(%d)", itemid); } -#ifdef ZABBIX_THREADS -void DBdelete_trends_by_itemid_thread(MYSQL *database, int itemid) -{ - char sql[MAX_STRING_LEN]; - - snprintf(sql,sizeof(sql)-1,"delete from trends where itemid=%d", itemid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_trends_by_itemid(int itemid) { char sql[MAX_STRING_LEN]; @@ -1179,18 +630,6 @@ void DBdelete_trends_by_itemid(int itemid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_history_by_itemid_thread(MYSQL *database, int itemid) -{ - char sql[MAX_STRING_LEN]; - - snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d", itemid); - DBexecute_thread(database, sql); - snprintf(sql,sizeof(sql)-1,"delete from history_str where itemid=%d", itemid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_history_by_itemid(int itemid) { char sql[MAX_STRING_LEN]; @@ -1201,23 +640,6 @@ void DBdelete_history_by_itemid(int itemid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_item_thread(MYSQL *database, int itemid) -{ - char sql[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_item(%d)", itemid); - - DBdelete_triggers_by_itemid_thread(database, itemid); - DBdelete_history_by_itemid_thread(database, itemid); - DBdelete_trends_by_itemid_thread(database, itemid); - - snprintf(sql,sizeof(sql)-1,"delete from items where itemid=%d", itemid); - DBexecute_thread(database, sql); - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_item(%d)", itemid); -} -#endif - void DBdelete_item(int itemid) { char sql[MAX_STRING_LEN]; @@ -1234,16 +656,6 @@ void DBdelete_item(int itemid) zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_item(%d)", itemid); } -#ifdef ZABBIX_THREADS -void DBdelete_sysmaps_links_by_shostid_thread(MYSQL *database, int shostid) -{ - char sql[MAX_STRING_LEN]; - - snprintf(sql,sizeof(sql)-1,"delete from sysmaps_links where shostid1=%d or shostid2=%d", shostid, shostid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_sysmaps_links_by_shostid(int shostid) { char sql[MAX_STRING_LEN]; @@ -1252,29 +664,6 @@ void DBdelete_sysmaps_links_by_shostid(int shostid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_sysmaps_hosts_by_hostid_thread(MYSQL *database, int hostid) -{ - int i, shostid; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_sysmaps_hosts(%d)", hostid); - snprintf(sql,sizeof(sql)-1,"select shostid from sysmaps_hosts where hostid=%d", hostid); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - shostid=atoi(DBget_field(result,i,0)); - DBdelete_sysmaps_links_by_shostid_thread(database, shostid); - } - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"delete from sysmaps_hosts where hostid=%d", hostid); - DBexecute_thread(database, sql); -} -#endif - void DBdelete_sysmaps_hosts_by_hostid(int hostid) { int i, shostid; @@ -1296,39 +685,6 @@ void DBdelete_sysmaps_hosts_by_hostid(int hostid) DBexecute(sql); } -#ifdef ZABBIX_THREADS -void DBdelete_host_thread(MYSQL *database, int hostid) -{ - int i, itemid; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBdelete_host(%d)", hostid); - snprintf(sql,sizeof(sql)-1,"select itemid from items where hostid=%d", hostid); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - itemid=atoi(DBget_field(result,i,0)); - DBdelete_item_thread(database, itemid); - } - DBfree_result(result); - - DBdelete_sysmaps_hosts_by_hostid_thread(database, hostid); - - snprintf(sql,sizeof(sql)-1,"delete from actions where triggerid=%d and scope=%d", hostid, ACTION_SCOPE_HOST); - DBexecute_thread(database,sql); - - snprintf(sql,sizeof(sql)-1,"delete from hosts_groups where hostid=%d", hostid); - DBexecute_thread(database,sql); - - snprintf(sql,sizeof(sql)-1,"delete from hosts where hostid=%d", hostid); - DBexecute_thread(database,sql); - - zabbix_log(LOG_LEVEL_DEBUG,"End of DBdelete_host(%d)", hostid); -} -#endif - void DBdelete_host(int hostid) { int i, itemid; @@ -1404,81 +760,6 @@ void DBupdate_triggers_status_after_restart(void) return; } -#ifdef ZABBIX_THREADS -void DBupdate_host_availability_thread(MYSQL *database, int hostid,int available,int clock,char *error) -{ - DB_RESULT *result; - char sql[MAX_STRING_LEN]; - char error_esc[MAX_STRING_LEN]; - int disable_until; - - zabbix_log(LOG_LEVEL_DEBUG,"In update_host_availability()"); - - DBescape_string(error,error_esc,MAX_STRING_LEN); - - snprintf(sql,sizeof(sql)-1,"select available,disable_until from hosts where hostid=%d",hostid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot select host with hostid [%d]",hostid); - zabbix_syslog("Cannot select host with hostid [%d]",hostid); - DBfree_result(result); - return; - } - - disable_until = atoi(DBget_field(result,0,1)); - - if(available == atoi(DBget_field(result,0,0))) - { - if((availability==HOST_AVAILABLE_FALSE) - &&(clock+DELAY_ON_NETWORK_FAILURE>disable_until) ) - { - } - else - { - zabbix_log(LOG_LEVEL_DEBUG, "Host already has availability [%d]", available); - DBfree_result(result); - return; - } - } - - DBfree_result(result); - - if(available==HOST_AVAILABLE_TRUE) - { - snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,error='' where hostid=%d",HOST_AVAILABLE_TRUE,hostid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - DBexecute_thread(database,sql); - } - else if(available==HOST_AVAILABLE_FALSE) - { - if(disable_until+DELAY_ON_NETWORK_FAILURE>clock) - { - snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,disable_until=disable_until+%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,DELAY_ON_NETWORK_FAILURE,error_esc,hostid); - } - else - { - snprintf(sql,sizeof(sql)-1,"update hosts set available=%d,disable_until=%d,error='%s' where hostid=%d",HOST_AVAILABLE_FALSE,clock+DELAY_ON_NETWORK_FAILURE,error_esc,hostid); - } - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - DBexecute_thread(database,sql); - } - else - { - zabbix_log( LOG_LEVEL_ERR, "Unknown host availability [%d] for hostid [%d]", availability, hostid); - zabbix_syslog("Unknown host availability [%d] for hostid [%d]", availability, hostid); - return; - } - - update_triggers_status_to_unknown_thread(database,hostid,clock); - zabbix_log(LOG_LEVEL_DEBUG,"End of update_host_availability()"); - - return; -} -#endif - void DBupdate_host_availability(int hostid,int available,int clock, char *error) { DB_RESULT *result; @@ -1552,24 +833,6 @@ void DBupdate_host_availability(int hostid,int available,int clock, char *error) return; } -#ifdef ZABBIX_THREADS -int DBupdate_item_status_to_notsupported_thread(MYSQL *database, int itemid, char *error) -{ - char sql[MAX_STRING_LEN]; - char error_esc[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBupdate_item_status_to_notsupported()"); - - DBescape_string(error,error_esc,MAX_STRING_LEN); - - snprintf(sql,sizeof(sql)-1,"update items set status=%d,error='%s' where itemid=%d",ITEM_STATUS_NOTSUPPORTED,error_esc,itemid); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - DBexecute_thread(database, sql); - - return SUCCEED; -} -#endif - int DBupdate_item_status_to_notsupported(int itemid, char *error) { char sql[MAX_STRING_LEN]; @@ -1586,49 +849,6 @@ int DBupdate_item_status_to_notsupported(int itemid, char *error) return SUCCEED; } -#ifdef ZABBIX_THREADS -int DBadd_trend_thread(MYSQL *database, int itemid, double value, int clock) -{ - DB_RESULT *result; - char sql[MAX_STRING_LEN]; - int hour; - int num; - double value_min, value_avg, value_max; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_trend()"); - - hour=clock-clock%3600; - - snprintf(sql,sizeof(sql)-1,"select num,value_min,value_avg,value_max from trends where itemid=%d and clock=%d", itemid, hour); - zabbix_log(LOG_LEVEL_DEBUG,"SQL [%s]",sql); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 1) - { - num=atoi(DBget_field(result,0,0)); - value_min=atof(DBget_field(result,0,1)); - value_avg=atof(DBget_field(result,0,2)); - value_max=atof(DBget_field(result,0,3)); - if(value<value_min) value_min=value; -/* Unfortunate mistake... */ -/* if(value>value_avg) value_max=value;*/ - if(value>value_max) value_max=value; - value_avg=(num*value_avg+value)/(num+1); - num++; - snprintf(sql,sizeof(sql)-1,"update trends set num=%d, value_min=%f, value_avg=%f, value_max=%f where itemid=%d and clock=%d", num, value_min, value_avg, value_max, itemid, hour); - } - else - { - snprintf(sql,sizeof(sql)-1,"insert into trends (clock,itemid,num,value_min,value_avg,value_max) values (%d,%d,%d,%f,%f,%f)", hour, itemid, 1, value, value, value); - } - DBexecute_thread(database, sql); - - DBfree_result(result); - - return SUCCEED; -} -#endif - int DBadd_trend(int itemid, double value, int clock) { DB_RESULT *result; @@ -1670,22 +890,6 @@ int DBadd_trend(int itemid, double value, int clock) return SUCCEED; } -#ifdef ZABBIX_THREADS -int DBadd_history_thread(MYSQL *database, int itemid, double value, int clock) -{ - char sql[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_history()"); - - snprintf(sql,sizeof(sql)-1,"insert into history (clock,itemid,value) values (%d,%d,%f)",clock,itemid,value); - DBexecute_thread(database, sql); - - DBadd_trend_thread(database, itemid, value, clock); - - return SUCCEED; -} -#endif - int DBadd_history(int itemid, double value, int clock) { char sql[MAX_STRING_LEN]; @@ -1700,22 +904,6 @@ int DBadd_history(int itemid, double value, int clock) return SUCCEED; } -#ifdef ZABBIX_THREADS -int DBadd_history_str_thread(MYSQL *database, int itemid, char *value, int clock) -{ - char sql[MAX_STRING_LEN]; - char value_esc[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_history_str()"); - - DBescape_string(value,value_esc,MAX_STRING_LEN); - snprintf(sql,sizeof(sql)-1,"insert into history_str (clock,itemid,value) values (%d,%d,'%s')",clock,itemid,value_esc); - DBexecute_thread(database, sql); - - return SUCCEED; -} -#endif - int DBadd_history_str(int itemid, char *value, int clock) { char sql[MAX_STRING_LEN]; @@ -1772,64 +960,6 @@ int DBget_items_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_items_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_items_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from items"); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - -#ifdef ZABBIX_THREADS -int DBget_triggers_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_triggers_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from triggers"); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_triggers_count(void) { int res; @@ -1857,35 +987,6 @@ int DBget_triggers_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_items_unsupported_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_items_unsupported_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from items where status=%d", ITEM_STATUS_NOTSUPPORTED); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_items_unsupported_count(void) { int res; @@ -1913,35 +1014,6 @@ int DBget_items_unsupported_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_history_str_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_history_str_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from history_str"); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_history_str_count(void) { int res; @@ -1969,35 +1041,6 @@ int DBget_history_str_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_history_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_history_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from history"); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_history_count(void) { int res; @@ -2025,35 +1068,6 @@ int DBget_history_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_trends_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_trends_count()"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from trends"); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_trends_count(void) { int res; @@ -2081,38 +1095,6 @@ int DBget_trends_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBget_queue_count_thread(MYSQL *database) -{ - int res; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - int now; - - zabbix_log(LOG_LEVEL_DEBUG,"In DBget_queue_count()"); - - now=time(NULL); -/* snprintf(sql,sizeof(sql)-1,"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and h.status=%d and i.hostid=h.hostid and i.nextcheck<%d and i.key_<>'status'", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, now);*/ - snprintf(sql,sizeof(sql)-1,"select count(*) from items i,hosts h where i.status=%d and i.type not in (%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and i.hostid=h.hostid and i.nextcheck<%d and i.key_ not in ('%s','%s','%s','%s')", ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, SERVER_ZABBIXLOG_KEY); - - result=DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_ERR, "Cannot execute query [%s]", sql); - zabbix_syslog("Cannot execute query [%s]", sql); - DBfree_result(result); - return 0; - } - - res = atoi(DBget_field(result,0,0)); - - DBfree_result(result); - - return res; -} -#endif - int DBget_queue_count(void) { int res; @@ -2143,30 +1125,6 @@ int DBget_queue_count(void) return res; } -#ifdef ZABBIX_THREADS -int DBadd_alert_thread(MYSQL *database, int actionid, int mediatypeid, char *sendto, char *subject, char *message) -{ - int now; - char sql[MAX_STRING_LEN]; - char sendto_esc[MAX_STRING_LEN]; - char subject_esc[MAX_STRING_LEN]; - char message_esc[MAX_STRING_LEN]; - - zabbix_log(LOG_LEVEL_DEBUG,"In add_alert()"); - - now = time(NULL); -/* Does not work on PostgreSQL */ -/* snprintf(sql,sizeof(sql)-1,"insert into alerts (alertid,actionid,clock,mediatypeid,sendto,subject,message,status,retries) values (NULL,%d,%d,%d,'%s','%s','%s',0,0)",actionid,now,mediatypeid,sendto,subject,message);*/ - DBescape_string(sendto,sendto_esc,MAX_STRING_LEN); - DBescape_string(subject,subject_esc,MAX_STRING_LEN); - DBescape_string(message,message_esc,MAX_STRING_LEN); - snprintf(sql,sizeof(sql)-1,"insert into alerts (actionid,clock,mediatypeid,sendto,subject,message,status,retries) values (%d,%d,%d,'%s','%s','%s',0,0)",actionid,now,mediatypeid,sendto_esc,subject_esc,message_esc); - DBexecute_thread(database, sql); - - return SUCCEED; -} -#endif - int DBadd_alert(int actionid, int mediatypeid, char *sendto, char *subject, char *message) { int now; @@ -2189,38 +1147,6 @@ int DBadd_alert(int actionid, int mediatypeid, char *sendto, char *subject, char return SUCCEED; } -#ifdef ZABBIX_THREADS -void DBvacuum_thread(MYSQL *database) -{ -#ifdef HAVE_PGSQL - char *table_for_housekeeping[]={"services", "services_links", "graphs_items", "graphs", "sysmaps_links", - "sysmaps_hosts", "sysmaps", "config", "groups", "hosts_groups", "alerts", - "actions", "alarms", "functions", "history", "history_str", "hosts", "trends", - "items", "media", "media_type", "triggers", "trigger_depends", "users", - "sessions", "rights", "service_alarms", "profiles", "screens", "screens_items", - "stats", - NULL}; - - char sql[MAX_STRING_LEN]; - char *table; - int i; -#ifdef HAVE_FUNCTION_SETPROCTITLE - setproctitle("housekeeper [vacuum DB]"); -#endif - i=0; - while (NULL != (table = table_for_housekeeping[i++])) - { - snprintf(sql,sizeof(sql)-1,"vacuum analyze %s", table); - DBexecute(sql); - } -#endif - -#ifdef HAVE_MYSQL - /* Nothing to do */ -#endif -} -#endif - void DBvacuum(void) { #ifdef HAVE_PGSQL diff --git a/include/db.h b/include/db.h index 5d076d37..26ce05c4 100644 --- a/include/db.h +++ b/include/db.h @@ -122,6 +122,7 @@ DB_ITEM char *snmpv3_privpassphrase; char *formula; + int lastlogsize; }; DB_FUNCTION @@ -142,6 +143,7 @@ DB_MEDIA /* char *type;*/ int mediatypeid; char *sendto; + char *period; int active; int severity; }; @@ -197,44 +199,6 @@ DB_ALERT }; void DBconnect(void); -#ifdef ZABBIX_THREADS -void DBconnect_thread(MYSQL *database); -void DBclose_thread(MYSQL *database); -int DBexecute_thread(MYSQL *database,char *query ); -DB_RESULT *DBselect_thread(MYSQL *database, char *query); - -void DBdelete_item_thread(MYSQL *database, int itemid); -void DBdelete_triggers_by_itemid_thread(MYSQL *database, int itemid); -void DBdelete_history_by_itemid_thread(MYSQL *database, int itemid); -void DBdelete_trends_by_itemid_thread(MYSQL *database, int itemid); -void DBdelete_trigger_thread(MYSQL *database, int triggerid); -void DBdelete_services_by_triggerid_thread(MYSQL *database, int triggerid); -void DBdelete_host_thread(MYSQL *database, int hostid); -void DBvacuum_thread(MYSQL *database); -void DBdelete_service_thread(MYSQL *database, int serviceid); -void DBdelete_sysmaps_links_by_shostid_thread(MYSQL *database, int shostid); -void DBupdate_host_availability_thread(MYSQL *database, int hostid,int available,int clock,char *error); -int DBupdate_item_status_to_notsupported_thread(MYSQL *database, int itemid, char *error); -int DBadd_history_thread(MYSQL *database, int itemid, double value, int clock); -int DBadd_trend_thread(MYSQL *database, int itemid, double value, int clock); -int DBadd_history_str_thread(MYSQL *database, int itemid, char *value, int clock); -int DBupdate_trigger_value_thread(MYSQL *database,int triggerid,int value,int clock); -int add_alarm_thread(MYSQL *database, int triggerid,int status,int clock); -int latest_alarm_thread(MYSQL *database,int triggerid, int status); -int DBadd_service_alarm_thread(MYSQL *database, int serviceid,int status,int clock); -int latest_service_alarm_thread(MYSQL *database, int serviceid, int status); -int DBget_prev_trigger_value_thread(MYSQL *database, int triggerid); -int DBadd_alert_thread(MYSQL *database, int actionid, int mediatypeid, char *sendto, char *subject, char *message); -int DBget_function_result_thread(MYSQL *database, double *result,char *functionid); - -int DBget_items_count_thread(MYSQL *database); -int DBget_items_unsupported_count_thread(MYSQL *database); -int DBget_history_count_thread(MYSQL *database); -int DBget_history_str_count_thread(MYSQL *database); -int DBget_trends_count_thread(MYSQL *database); -int DBget_triggers_count_thread(MYSQL *database); -int DBget_queue_count_thread(MYSQL *database); -#endif void DBclose(void); void DBvacuum(void); diff --git a/include/expression.c b/include/expression.c index 4713b5f0..1e6f4c70 100644 --- a/include/expression.c +++ b/include/expression.c @@ -665,137 +665,6 @@ int evaluate(int *result,char *exp) return SUCCEED; } -#ifdef ZABBIX_THREADS -/* Translate {DATE}, {TIME} */ -/* Doesn't work yet */ -void substitute_simple_macros_thread(MYSQL *database, DB_TRIGGER *trigger, DB_ACTION *action, char *exp) -{ - int found = SUCCEED; - char *s; - char sql[MAX_STRING_LEN]; - char str[MAX_STRING_LEN]; - char tmp[MAX_STRING_LEN]; - - time_t now; - struct tm *tm; - - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG, "In substitute_simple_macros [%s]",exp); - - while (found == SUCCEED) - { - strscpy(str, exp); - - - if( (s = strstr(str,"{HOSTNAME}")) != NULL ) - { -/* snprintf(sql,sizeof(sql)-1,"select distinct t.description,h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid);*/ - snprintf(sql,sizeof(sql)-1,"select distinct h.host from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid", trigger->triggerid); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log( LOG_LEVEL_ERR, "No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_syslog("No hostname in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - strscpy(tmp, "*UNKNOWN*"); - DBfree_result(result); - } - else - { - strscpy(tmp,DBget_field(result,0,0)); - - DBfree_result(result); - } - - s[0]=0; - strcpy(exp, str); - strncat(exp, tmp, MAX_STRING_LEN); - strncat(exp, s+strlen("{HOSTNAME}"), MAX_STRING_LEN); - - found = SUCCEED; - } - else if( (s = strstr(str,"{IPADDRESS}")) != NULL ) - { - snprintf(sql,sizeof(sql)-1,"select distinct h.ip from triggers t, functions f,items i, hosts h where t.triggerid=%d and f.triggerid=t.triggerid and f.itemid=i.itemid and h.hostid=i.hostid and i.useip=1", trigger->triggerid); - result = DBselect_thread(database, sql); - - if(DBnum_rows(result) == 0) - { - zabbix_log( LOG_LEVEL_ERR, "No IP address in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - zabbix_syslog("No IP address in substitute_simple_macros. Triggerid [%d]", trigger->triggerid); - strscpy(tmp, "*UNKNOWN IP*"); - DBfree_result(result); - } - else - { - strscpy(tmp,DBget_field(result,0,0)); - - DBfree_result(result); - } - - s[0]=0; - strcpy(exp, str); - strncat(exp, tmp, MAX_STRING_LEN); - strncat(exp, s+strlen("{IPADDRESS}"), MAX_STRING_LEN); - - found = SUCCEED; - } - else if( (s = strstr(str,"{DATE}")) != NULL ) - { - now=time(NULL); - tm=localtime(&now); - snprintf(tmp,sizeof(tmp)-1,"%.4d.%.2d.%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday); - - s[0]=0; - strcpy(exp, str); - strncat(exp, tmp, MAX_STRING_LEN); - strncat(exp, s+strlen("{DATE}"), MAX_STRING_LEN); - - found = SUCCEED; - } - else if( (s = strstr(str,"{TIME}")) != NULL ) - { - now=time(NULL); - tm=localtime(&now); - snprintf(tmp,sizeof(tmp)-1,"%.2d:%.2d:%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec); - - s[0]=0; - strcpy(exp, str); - strncat(exp, tmp, MAX_STRING_LEN); - strncat(exp, s+strlen("{TIME}"), MAX_STRING_LEN); - - found = SUCCEED; - } - else if( (s = strstr(str,"{STATUS}")) != NULL ) - { - /* This is old value */ - if(trigger->value == TRIGGER_VALUE_TRUE) - { - snprintf(tmp,sizeof(tmp)-1,"OFF"); - } - else - { - snprintf(tmp,sizeof(tmp)-1,"ON"); - } - - s[0]=0; - strcpy(exp, str); - strncat(exp, tmp, MAX_STRING_LEN); - strncat(exp, s+strlen("{STATUS}"), MAX_STRING_LEN); - - found = SUCCEED; - } - else - { - found = FAIL; - } - } - - zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]", exp ); -} -#endif - /* Translate {DATE}, {TIME} */ /* Doesn't work yet */ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *exp) @@ -925,135 +794,6 @@ void substitute_simple_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *exp) zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]", exp ); } -#ifdef ZABBIX_THREADS -/* - * Translate "{127.0.0.1:system[procload].last(0)}" to "1.34" - */ -/* - * Make this function more secure. Get rid of snprintf. Utilise substr() -*/ -int substitute_macros_thread(MYSQL *database, DB_TRIGGER *trigger, DB_ACTION *action, char *exp) -{ - char res[MAX_STRING_LEN]; - char macro[MAX_STRING_LEN]; - char host[MAX_STRING_LEN]; - char key[MAX_STRING_LEN]; - char function[MAX_STRING_LEN]; - char parameter[MAX_STRING_LEN]; - static char value[MAX_STRING_LEN]; - int i; - int r,l; - int r1,l1; - - zabbix_log(LOG_LEVEL_DEBUG, "In substitute_macros([%s])",exp); - - substitute_simple_macros_thread(database, trigger, action, exp); - - while( find_char(exp,'{') != FAIL ) - { - l=find_char(exp,'{'); - r=find_char(exp,'}'); - - if( r == FAIL ) - { - zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:[%s]", exp ); - zabbix_syslog("Cannot find right bracket. Expression:[%s]", exp ); - return FAIL; - } - - if( r < l ) - { - zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:[%s]", exp ); - zabbix_syslog("Right bracket is before left one. Expression:[%s]", exp ); - return FAIL; - } - - for(i=l+1;i<r;i++) - { - macro[i-l-1]=exp[i]; - } - macro[r-l-1]=0; - - zabbix_log( LOG_LEVEL_DEBUG, "Macro:%s", macro ); - - /* macro=="host:key.function(parameter)" */ - - r1=find_char(macro,':'); - - for(i=0;i<r1;i++) - { - host[i]=macro[i]; - } - host[r1]=0; - - zabbix_log( LOG_LEVEL_DEBUG, "Host:%s", host ); - - r1=r1+1; -/* Doesn't work if the key contains '.' */ -/* l1=find_char(macro+r1,'.');*/ - - l1=FAIL; - for(i=0;(macro+r1)[i]!=0;i++) - { - if((macro+r1)[i]=='.') l1=i; - } - - for(i=r1;i<l1+r1;i++) - { - key[i-r1]=macro[i]; - } - key[l1]=0; - - zabbix_log( LOG_LEVEL_DEBUG, "Key:%s", key ); - - l1=l1+r1+1; - r1=find_char(macro+l1,'('); - - for(i=l1;i<l1+r1;i++) - { - function[i-l1]=macro[i]; - } - function[r1]=0; - - zabbix_log( LOG_LEVEL_DEBUG, "Function:%s", function ); - - l1=l1+r1+1; - r1=find_char(macro+l1,')'); - - for(i=l1;i<l1+r1;i++) - { - parameter[i-l1]=macro[i]; - } - parameter[r1]=0; - - zabbix_log( LOG_LEVEL_DEBUG, "Parameter:%s", parameter ); - - i=get_lastvalue_thread(database,value,host,key,function,parameter); - zabbix_log( LOG_LEVEL_DEBUG, "Value3 [%s]", value ); - - - zabbix_log( LOG_LEVEL_DEBUG, "Value4 [%s]", exp ); - exp[l]='%'; - exp[l+1]='s'; - - zabbix_log( LOG_LEVEL_DEBUG, "Value41 [%s]", exp+l+2 ); - zabbix_log( LOG_LEVEL_DEBUG, "Value42 [%s]", exp+r+1 ); - strcpy(exp+l+2,exp+r+1); - - zabbix_log( LOG_LEVEL_DEBUG, "Value5 [%s]", exp ); - - snprintf(res,sizeof(res)-1,exp,value); - strcpy(exp,res); -/* delete_spaces(exp); */ - zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", exp ); - } - - zabbix_log( LOG_LEVEL_DEBUG, "Result expression:%s", exp ); - - return SUCCEED; -} -#endif - /* * Translate "{127.0.0.1:system[procload].last(0)}" to "1.34" */ @@ -1181,77 +921,6 @@ int substitute_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *exp) return SUCCEED; } -#ifdef ZABBIX_THREADS -/* - * Translate "({15}>10)|({123}=0)" to "(6.456>10)|(0=0)" - */ -int substitute_functions_thread(MYSQL *database, char *exp) -{ - double value; - char functionid[MAX_STRING_LEN]; - char res[MAX_STRING_LEN]; - int i,l,r; - - zabbix_log(LOG_LEVEL_DEBUG, "BEGIN substitute_functions (%s)", exp); - - while( find_char(exp,'{') != FAIL ) - { - l=find_char(exp,'{'); - r=find_char(exp,'}'); - if( r == FAIL ) - { - zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:[%s]", exp ); - zabbix_syslog("Cannot find right bracket. Expression:[%s]", exp ); - return FAIL; - } - if( r < l ) - { - zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:[%s]", exp ); - zabbix_syslog("Right bracket is before left one. Expression:[%s]", exp ); - return FAIL; - } - - for(i=l+1;i<r;i++) - { - functionid[i-l-1]=exp[i]; - } - functionid[r-l-1]=0; - - if( DBget_function_result_thread(database, &value, functionid ) != SUCCEED ) - { -/* It may happen because of functions.lastvalue is NULL, so this is not warning */ - zabbix_log( LOG_LEVEL_DEBUG, "Unable to get value for functionid [%s]", functionid ); - zabbix_syslog("Unable to get value for functionid [%s]", functionid ); - return FAIL; - } - - - zabbix_log( LOG_LEVEL_DEBUG, "Expression1:[%s]", exp ); - - exp[l]='%'; - exp[l+1]='l'; - exp[l+2]='f'; -/* exp[l]='%'; - exp[l+1]='f'; - exp[l+2]=' ';*/ - - zabbix_log( LOG_LEVEL_DEBUG, "Expression2:[%s]", exp ); - - for(i=l+3;i<=r;i++) exp[i]=' '; - - zabbix_log( LOG_LEVEL_DEBUG, "Expression3:[%s]", exp ); - - snprintf(res,sizeof(res)-1,exp,value); - strcpy(exp,res); - delete_spaces(exp); - zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", exp ); - } - zabbix_log( LOG_LEVEL_DEBUG, "Expression:[%s]", exp ); - zabbix_log( LOG_LEVEL_DEBUG, "END substitute_functions" ); - return SUCCEED; -} -#endif - /* * Translate "({15}>10)|({123}=0)" to "(6.456>10)|(0=0)" */ @@ -1321,29 +990,6 @@ int substitute_functions(char *exp) return SUCCEED; } -#ifdef ZABBIX_THREADS -/* - * Evaluate complex expression. Example: ({127.0.0.1:system[procload].last(0)}>1)|({127.0.0.1:system[procload].max(300)}>3) - */ -int evaluate_expression_thread(MYSQL *database, int *result,char *expression) -{ - zabbix_log(LOG_LEVEL_DEBUG, "In evaluate_expression(%s)", expression ); - - delete_spaces(expression); - if( substitute_functions_thread(database,expression) == SUCCEED) - { - /* No need for _thread function */ - if( evaluate(result, expression) == SUCCEED) - { - return SUCCEED; - } - } - zabbix_log(LOG_LEVEL_WARNING, "Evaluation of expression [%s] failed", expression ); - zabbix_syslog("Evaluation of expression [%s] failed", expression ); - return FAIL; -} -#endif - /* * Evaluate complex expression. Example: ({127.0.0.1:system[procload].last(0)}>1)|({127.0.0.1:system[procload].max(300)}>3) */ diff --git a/include/expression.h b/include/expression.h index c5340b4b..027e6f21 100644 --- a/include/expression.h +++ b/include/expression.h @@ -31,9 +31,4 @@ int substitute_macros(DB_TRIGGER *trigger, DB_ACTION *action, char *exp); int evaluate_expression (int *result,char *expression); void delete_reol(char *c); -#ifdef ZABBIX_THREADS -int substitute_macros_thread(MYSQL *database, DB_TRIGGER *trigger, DB_ACTION *action, char *exp); -int evaluate_expression_thread(MYSQL *database, int *result,char *expression); -#endif - #endif diff --git a/include/functions.c b/include/functions.c index 5491aa31..a5ad2733 100644 --- a/include/functions.c +++ b/include/functions.c @@ -89,43 +89,6 @@ int calculate_item_nextcheck(int nextcheck, int delay, int now) return i; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function COUNT - */ -int evaluate_COUNT_thread(MYSQL *database, char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select count(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database, sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for COUNT is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - } - DBfree_result(result); - - return res; -} -#endif - /* * Evaluate function COUNT */ @@ -161,43 +124,6 @@ int evaluate_COUNT(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function SUM - */ -int evaluate_SUM_thread(MYSQL *database, char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select sum(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database, sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for SUM is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - } - DBfree_result(result); - - return res; -} -#endif - /* * Evaluate function SUM */ @@ -233,44 +159,6 @@ int evaluate_SUM(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function AVG - */ -int evaluate_AVG_thread(MYSQL *database,char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select avg(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database,sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for AVG is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - del_zeroes(value); - } - DBfree_result(result); - - return res; -} -#endif - /* * Evaluate function AVG */ @@ -307,44 +195,6 @@ int evaluate_AVG(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function MIN - */ -int evaluate_MIN_thread(MYSQL *database, char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database,sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MIN is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - del_zeroes(value); - } - DBfree_result(result); - - return res; -} -#endif - /* * Evaluate function MIN */ @@ -381,44 +231,6 @@ int evaluate_MIN(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function MAX - */ -int evaluate_MAX_thread(MYSQL *database, char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select max(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database, sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for MAX is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - del_zeroes(value); - } - DBfree_result(result); - - return res; -} -#endif - /* * Evaluate function MAX */ @@ -455,45 +267,6 @@ int evaluate_MAX(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function DELTA - */ -int evaluate_DELTA_thread(MYSQL *database,char *value,DB_ITEM *item,int parameter) -{ - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - int now; - int res = SUCCEED; - - if(item->value_type != ITEM_VALUE_TYPE_FLOAT) - { - return FAIL; - } - - now=time(NULL); - - snprintf(sql,sizeof(sql)-1,"select max(value)-min(value) from history where clock>%d and itemid=%d",now-parameter,item->itemid); - - result = DBselect_thread(database,sql); - if(DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result for DELTA is empty" ); - res = FAIL; - } - else - { - strcpy(value,DBget_field(result,0,0)); - del_zeroes(value); - } - DBfree_result(result); - - return res; -} -#endif - - /* * Evaluate function DELTA */ @@ -530,279 +303,6 @@ int evaluate_DELTA(char *value,DB_ITEM *item,int parameter) return res; } -#ifdef ZABBIX_THREADS -/* - * Evaluate function (avg,min,max,prev,last,diff,str,change,abschange,delta,time,date) - */ -int evaluate_FUNCTION_thread(MYSQL *database, char *value,DB_ITEM *item,char *function,char *parameter, int flag) -{ - int ret = SUCCEED; - time_t now; - struct tm *tm; - - float value_float; - float value_float_abs; - char suffix[MAX_STRING_LEN]; - - int day; - - zabbix_log( LOG_LEVEL_DEBUG, "Function [%s]",function); - - if(strcmp(function,"last")==0) - { - if(item->lastvalue_null==1) - { - ret = FAIL; - } - else - { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 1"); - snprintf(value,MAX_STRING_LEN-1,"%f",item->lastvalue); - del_zeroes(value); - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 2"); - } - else - { -/* *value=strdup(item->lastvalue_str);*/ - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 3 [%s] [%s]",value,item->lastvalue_str); - strcpy(value,item->lastvalue_str); - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 4"); - } - } - } - else if(strcmp(function,"prev")==0) - { - if(item->prevvalue_null==1) - { - ret = FAIL; - } - else - { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - snprintf(value,MAX_STRING_LEN-1,"%f",item->prevvalue); - del_zeroes(value); - } - else - { - strcpy(value,item->prevvalue_str); - } - } - } - else if(strcmp(function,"min")==0) - { - ret = evaluate_MIN_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"max")==0) - { - ret = evaluate_MAX_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"avg")==0) - { - ret = evaluate_AVG_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"sum")==0) - { - ret = evaluate_SUM_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"count")==0) - { - ret = evaluate_COUNT_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"delta")==0) - { - ret = evaluate_DELTA_thread(database,value,item,atoi(parameter)); - } - else if(strcmp(function,"nodata")==0) - { - strcpy(value,"0"); - } - else if(strcmp(function,"date")==0) - { - now=time(NULL); - tm=localtime(&now); - snprintf(value,MAX_STRING_LEN-1,"%.4d%.2d%.2d",tm->tm_year+1900,tm->tm_mon+1,tm->tm_mday); - } - else if(strcmp(function,"dayofweek")==0) - { - now=time(NULL); - tm=localtime(&now); - /* The number of days since Sunday, in the range 0 to 6. */ - day=tm->tm_wday; - if(0 == day) day=7; - snprintf(value,MAX_STRING_LEN-1,"%d", day); - } - else if(strcmp(function,"time")==0) - { - now=time(NULL); - tm=localtime(&now); - snprintf(value,MAX_STRING_LEN-1,"%.2d%.2d%.2d",tm->tm_hour,tm->tm_min,tm->tm_sec); - } - else if(strcmp(function,"abschange")==0) - { - if((item->lastvalue_null==1)||(item->prevvalue_null==1)) - { - ret = FAIL; - } - else - { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - snprintf(value,MAX_STRING_LEN-1,"%f",(float)abs(item->lastvalue-item->prevvalue)); - del_zeroes(value); - } - else - { - if(strcmp(item->lastvalue_str, item->prevvalue_str) == 0) - { - strcpy(value,"0"); - } - else - { - strcpy(value,"1"); - } - } - } - } - else if(strcmp(function,"change")==0) - { - if((item->lastvalue_null==1)||(item->prevvalue_null==1)) - { - ret = FAIL; - } - else - { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - snprintf(value,MAX_STRING_LEN-1,"%f",item->lastvalue-item->prevvalue); - del_zeroes(value); - } - else - { - if(strcmp(item->lastvalue_str, item->prevvalue_str) == 0) - { - strcpy(value,"0"); - } - else - { - strcpy(value,"1"); - } - } - } - } - else if(strcmp(function,"diff")==0) - { - if((item->lastvalue_null==1)||(item->prevvalue_null==1)) - { - ret = FAIL; - } - else - { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - if(cmp_double(item->lastvalue, item->prevvalue) == 0) - { - strcpy(value,"0"); - } - else - { - strcpy(value,"1"); - } - } - else - { - if(strcmp(item->lastvalue_str, item->prevvalue_str) == 0) - { - strcpy(value,"0"); - } - else - { - strcpy(value,"1"); - } - } - } - } - else if(strcmp(function,"str")==0) - { - if(item->value_type==ITEM_VALUE_TYPE_STR) - { - if(strstr(item->lastvalue_str, parameter) == NULL) - { - strcpy(value,"0"); - } - else - { - strcpy(value,"1"); - } - - } - else - { - ret = FAIL; - } - } - else if(strcmp(function,"now")==0) - { - now=time(NULL); - snprintf(value,MAX_STRING_LEN-1,"%d",(int)now); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported function:%s",function); - zabbix_syslog("Unsupported function:%s",function); - ret = FAIL; - } - - /* Add suffix: 1000000 -> 1 MB */ - if( (EVALUATE_FUNCTION_SUFFIX == flag) && (ITEM_VALUE_TYPE_FLOAT == item->value_type) && - (SUCCEED == ret) && strlen(item->units)>0) - { - value_float=atof(value); - /* Use multiplier ? */ -/* if(item->multiplier == 1) - { - zabbix_log( LOG_LEVEL_WARNING, "HMM [%s] [%f] [%f]",item->formula, value_float, atof(item->formula)); - value_float=value_float*atof(item->formula); - }*/ - value_float_abs=abs(value_float); - if(value_float_abs<1024) - { - strscpy(suffix,""); - } - else if(value_float_abs<1024*1024) - { - strscpy(suffix,"K"); - value_float=value_float/1024; - } - else if(value_float_abs<1024*1024*1024) - { - strscpy(suffix,"M"); - value_float=value_float/(1024*1024); - } - else - { - strscpy(suffix,"G"); - value_float=value_float/(1024*1024*1024); - } - zabbix_log( LOG_LEVEL_DEBUG, "Value [%s] [%f] Suffix [%s] Units [%s]",value,value_float,suffix,item->units); -// if(cmp_double((double)round(value_float), value_float) == 0) - if(cmp_double((int)(value_float+0.5), value_float) == 0) - { - snprintf(value, MAX_STRING_LEN-1, "%.0f %s%s", value_float, suffix, item->units); - } - else - { - snprintf(value, MAX_STRING_LEN-1, "%.2f %s%s", value_float, suffix, item->units); - } - } - - zabbix_log( LOG_LEVEL_DEBUG, "End of evaluate_FUNCTION. Result [%s]",value); - return ret; -} -#endif - /* * Evaluate function (avg,min,max,prev,last,diff,str,change,abschange,delta,time,date) */ @@ -1082,53 +582,6 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,char *parameter, return ret; } -#ifdef ZABBIX_THREADS -/* - * Re-calculate values of functions related to given ITEM - */ -void update_functions_thread(MYSQL *database, DB_ITEM *item) -{ - DB_FUNCTION function; - DB_RESULT *result; - char sql[MAX_STRING_LEN]; - char value[MAX_STRING_LEN]; - char value_esc[MAX_STRING_LEN]; - int ret=SUCCEED; - int i; - - zabbix_log( LOG_LEVEL_DEBUG, "In update_functions(%d)",item->itemid); - - snprintf(sql,sizeof(sql)-1,"select function,parameter,itemid from functions where itemid=%d group by 1,2,3 order by 1,2,3",item->itemid); - - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - function.function=DBget_field(result,i,0); - function.parameter=DBget_field(result,i,1); - function.itemid=atoi(DBget_field(result,i,2)); - - zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)\n",function.itemid,function.function,function.parameter); - - ret = evaluate_FUNCTION_thread(database,value,item,function.function,function.parameter, EVALUATE_FUNCTION_NORMAL); - if( FAIL == ret) - { - zabbix_log( LOG_LEVEL_DEBUG, "Evaluation failed for function:%s\n",function.function); - continue; - } - zabbix_log( LOG_LEVEL_DEBUG, "Result of evaluate_FUNCTION [%s]\n",value); - if (ret == SUCCEED) - { - DBescape_string(value,value_esc,MAX_STRING_LEN); - snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value_esc, function.itemid, function.function, function.parameter ); - DBexecute_thread(database, sql); - } - } - - DBfree_result(result); -} -#endif - /* * Re-calculate values of functions related to given ITEM */ @@ -1174,38 +627,52 @@ void update_functions(DB_ITEM *item) DBfree_result(result); } -#ifdef ZABBIX_THREADS -/* Cannot use action->userid as it may also represent groupd id*/ -void send_to_user_medias_thread(MYSQL *database, DB_TRIGGER *trigger,DB_ACTION *action, int userid) +/* 1 - within period, 0 - out of period */ +int check_time_period(char *period) { - DB_MEDIA media; - char sql[MAX_STRING_LEN]; - DB_RESULT *result; + 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; - int i; - snprintf(sql,sizeof(sql)-1,"select mediatypeid,sendto,active,severity from media where active=%d and userid=%d",MEDIA_STATUS_ACTIVE,userid); - result = DBselect_thread(database, sql); + zabbix_log( LOG_LEVEL_DEBUG, "In check_time_period(%s)",period); - for(i=0;i<DBnum_rows(result);i++) + 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) { - media.mediatypeid=atoi(DBget_field(result,i,0)); - media.sendto=DBget_field(result,i,1); - media.active=atoi(DBget_field(result,i,2)); - media.severity=atoi(DBget_field(result,i,3)); + zabbix_log( LOG_LEVEL_DEBUG, "Period [%s]",s); - zabbix_log( LOG_LEVEL_DEBUG, "Trigger severity [%d] Media severity [%d]",trigger->priority, media.severity); - if(((1<<trigger->priority)&media.severity)==0) + if(sscanf(s,"%d-%d,%d:%d-%d:%d",&d1,&d2,&h1,&m1,&h2,&m2) == 6) { - zabbix_log( LOG_LEVEL_DEBUG, "Won't send message"); - continue; + 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); } - DBadd_alert_thread(database, action->actionid,media.mediatypeid,media.sendto,action->subject,action->message); + s=(char *)strtok(NULL,";"); } - DBfree_result(result); + return ret; } -#endif /* Cannot use action->userid as it may also represent groupd id*/ void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int userid) @@ -1216,7 +683,7 @@ void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int userid) int i; - snprintf(sql,sizeof(sql)-1,"select mediatypeid,sendto,active,severity from media where active=%d and userid=%d",MEDIA_STATUS_ACTIVE,userid); + snprintf(sql,sizeof(sql)-1,"select mediatypeid,sendto,active,severity,period from media where active=%d and userid=%d",MEDIA_STATUS_ACTIVE,userid); result = DBselect(sql); for(i=0;i<DBnum_rows(result);i++) @@ -1225,52 +692,25 @@ void send_to_user_medias(DB_TRIGGER *trigger,DB_ACTION *action, int userid) media.sendto=DBget_field(result,i,1); media.active=atoi(DBget_field(result,i,2)); media.severity=atoi(DBget_field(result,i,3)); + media.period=DBget_field(result,i,4); - zabbix_log( LOG_LEVEL_DEBUG, "Trigger severity [%d] Media severity [%d]",trigger->priority, media.severity); + zabbix_log( LOG_LEVEL_DEBUG, "Trigger severity [%d] Media severity [%d] Period [%s]",trigger->priority, media.severity, media.period); if(((1<<trigger->priority)&media.severity)==0) { zabbix_log( LOG_LEVEL_DEBUG, "Won't send message"); continue; } + if(check_time_period(media.period) == 0) + { + zabbix_log( LOG_LEVEL_DEBUG, "Won't send message"); + continue; + } DBadd_alert(action->actionid,media.mediatypeid,media.sendto,action->subject,action->message); } DBfree_result(result); } -#ifdef ZABBIX_THREADS -/* - * Send message to user. Message will be sent to all medias registered to given user. - */ -void send_to_user_thread(MYSQL *database, DB_TRIGGER *trigger,DB_ACTION *action) -{ - char sql[MAX_STRING_LEN]; - DB_RESULT *result; - - int i; - - if(action->recipient == RECIPIENT_TYPE_USER) - { - send_to_user_medias_thread(database,trigger, action, action->userid); - } - else if(action->recipient == RECIPIENT_TYPE_GROUP) - { - snprintf(sql,sizeof(sql)-1,"select u.userid from users u, users_groups ug where ug.usrgrpid=%d and ug.userid=u.userid", action->userid); - result = DBselect_thread(database, sql); - for(i=0;i<DBnum_rows(result);i++) - { - send_to_user_medias_thread(database, trigger, action, atoi(DBget_field(result,i,0))); - } - DBfree_result(result); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Unknown recipient type [%d] for actionid [%d]",action->recipient,action->actionid); - zabbix_syslog("Unknown recipient type [%d] for actionid [%d]",action->recipient,action->actionid); - } -} -#endif - /* * Send message to user. Message will be sent to all medias registered to given user. */ @@ -1302,183 +742,6 @@ void send_to_user(DB_TRIGGER *trigger,DB_ACTION *action) } } -#ifdef ZABBIX_THREADS -/* - * Apply actions if any. - */ -/*void apply_actions(int triggerid,int good)*/ -void apply_actions_thread(MYSQL *database, DB_TRIGGER *trigger,int trigger_value) -{ - DB_RESULT *result,*result2,*result3; - - DB_ACTION action; - - char sql[MAX_STRING_LEN]; - - int i,j; - int now; - - zabbix_log( LOG_LEVEL_DEBUG, "In apply_actions(%d,%d)",trigger->triggerid, trigger_value); - - if(TRIGGER_VALUE_TRUE == trigger_value) - { - zabbix_log( LOG_LEVEL_DEBUG, "Check dependencies"); - - snprintf(sql,sizeof(sql)-1,"select count(*) from trigger_depends d,triggers t where d.triggerid_down=%d and d.triggerid_up=t.triggerid and t.value=%d",trigger->triggerid, TRIGGER_VALUE_TRUE); - result = DBselect_thread(database, sql); - if(DBnum_rows(result) == 1) - { - if(atoi(DBget_field(result,0,0))>0) - { - zabbix_log( LOG_LEVEL_DEBUG, "Will not apply actions"); - DBfree_result(result); - return; - } - } - DBfree_result(result); - } - - zabbix_log( LOG_LEVEL_DEBUG, "Applying actions"); - - now = time(NULL); - -/* snprintf(sql,sizeof(sql)-1,"select actionid,userid,delay,subject,message,scope,severity,recipient,good from actions where (scope=%d and triggerid=%d and good=%d and nextcheck<=%d) or (scope=%d and good=%d) or (scope=%d and good=%d)",ACTION_SCOPE_TRIGGER,trigger->triggerid,trigger_value,now,ACTION_SCOPE_HOST,trigger_value,ACTION_SCOPE_HOSTS,trigger_value);*/ - snprintf(sql,sizeof(sql)-1,"select actionid,userid,delay,subject,message,scope,severity,recipient,good from actions where (scope=%d and triggerid=%d and (good=%d or good=2) and nextcheck<=%d) or (scope=%d and (good=%d or good=2)) or (scope=%d and (good=%d or good=2))",ACTION_SCOPE_TRIGGER,trigger->triggerid,trigger_value,now,ACTION_SCOPE_HOST,trigger_value,ACTION_SCOPE_HOSTS,trigger_value); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - - zabbix_log( LOG_LEVEL_DEBUG, "i=[%d]",i); -/* zabbix_log( LOG_LEVEL_ERR, "Fetched: ID [%s] %s %s %s %s\n",DBget_field(result,i,0),DBget_field(result,i,1),DBget_field(result,i,2),DBget_field(result,i,3),DBget_field(result,i,4));*/ - - action.actionid=atoi(DBget_field(result,i,0)); - action.userid=atoi(DBget_field(result,i,1)); - action.delay=atoi(DBget_field(result,i,2)); - strscpy(action.subject,DBget_field(result,i,3)); - strscpy(action.message,DBget_field(result,i,4)); - action.scope=atoi(DBget_field(result,i,5)); - action.severity=atoi(DBget_field(result,i,6)); - action.recipient=atoi(DBget_field(result,i,7)); - action.good=atoi(DBget_field(result,i,8)); - - if(ACTION_SCOPE_TRIGGER==action.scope) - { -/* substitute_hostname(trigger->triggerid,action.message); - substitute_hostname(trigger->triggerid,action.subject);*/ - - substitute_macros_thread(database,trigger, &action, action.message); - substitute_macros_thread(database,trigger, &action, action.subject); - - send_to_user_thread(database,trigger,&action); - snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid); - DBexecute_thread(database,sql); - } - else if(ACTION_SCOPE_HOST==action.scope) - { - if(trigger->priority<action.severity) - { - continue; - } - - snprintf(sql,sizeof(sql)-1,"select distinct h.hostid from hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and t.triggerid=%d", trigger->triggerid); - result2 = DBselect_thread(database,sql); - - for(j=0;j<DBnum_rows(result2);j++) - { - snprintf(sql,sizeof(sql)-1,"select distinct a.actionid from actions a,hosts h,items i,triggers t,functions f where h.hostid=i.hostid and i.itemid=f.itemid and f.triggerid=t.triggerid and a.triggerid=%d and a.scope=1 and a.actionid=%d and a.triggerid=h.hostid",atoi(DBget_field(result2,j,0)),action.actionid); - result3 = DBselect_thread(database,sql); - if(DBnum_rows(result3)==0) - { - DBfree_result(result3); - continue; - } - DBfree_result(result3); - - strscpy(action.subject,trigger->description); - if(TRIGGER_VALUE_TRUE == trigger_value) - { - strncat(action.subject," (ON)", MAX_STRING_LEN); - } - else - { - strncat(action.subject," (OFF)", MAX_STRING_LEN); - } - strscpy(action.message,action.subject); - - substitute_macros_thread(database,trigger, &action, action.message); - substitute_macros_thread(database,trigger, &action, action.subject); - - send_to_user_thread(database,trigger,&action); - snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid); - DBexecute_thread(database,sql); - } - DBfree_result(result2); - -/* snprintf(sql,sizeof(sql)-1,"select * from actions a,triggers t,hosts h,functions f where a.triggerid=t.triggerid and f.triggerid=t.triggerid and h.hostid=a.triggerid and t.triggerid=%d and a.scope=%d",trigger->triggerid,ACTION_SCOPE_HOST); - result2 = DBselect(sql); - if(DBnum_rows(result2)==0) - { - DBfree_result(result2); - continue; - } - DBfree_result(result2); - - strscpy(action.subject,trigger->description); - if(TRIGGER_VALUE_TRUE == trigger_value) - { - strncat(action.subject," (ON)", MAX_STRING_LEN); - } - else - { - strncat(action.subject," (OFF)", MAX_STRING_LEN); - } - strscpy(action.message,action.subject); - - substitute_macros(trigger, &action, action.message); - substitute_macros(trigger, &action, action.subject);*/ - } - else if(ACTION_SCOPE_HOSTS==action.scope) - { -/* Added in Zabbix 1.0beta10 */ - if(trigger->priority<action.severity) - { - continue; - } -/* -- */ - strscpy(action.subject,trigger->description); - if(TRIGGER_VALUE_TRUE == trigger_value) - { - strncat(action.subject," (ON)", MAX_STRING_LEN); - } - else - { - strncat(action.subject," (OFF)", MAX_STRING_LEN); - } - strscpy(action.message,action.subject); - - substitute_macros_thread(database,trigger, &action, action.message); - substitute_macros_thread(database,trigger, &action, action.subject); - -/* substitute_hostname(trigger->triggerid,action.message); - substitute_hostname(trigger->triggerid,action.subject);*/ - - send_to_user_thread(database,trigger,&action); - snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=%d where actionid=%d",now+action.delay,action.actionid); - DBexecute_thread(database,sql); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Unsupported scope [%d] for actionid [%d]", action.scope, action.actionid); - zabbix_syslog("Unsupported scope [%d] for actionid [%d]", action.scope, action.actionid); - } - - } - zabbix_log( LOG_LEVEL_DEBUG, "Actions applied for trigger %d %d", trigger->triggerid, trigger_value ); - DBfree_result(result); -} -#endif - /* * Apply actions if any. */ @@ -1654,87 +917,6 @@ void apply_actions(DB_TRIGGER *trigger,int trigger_value) DBfree_result(result); } -#ifdef ZABBIX_THREADS -/* - * Recursive function! - */ -void update_serv_thread(MYSQL *database,int serviceid) -{ - char sql[MAX_STRING_LEN]; - int i; - int status; - int serviceupid, algorithm; - int now; - - DB_RESULT *result,*result2; - - snprintf(sql,sizeof(sql)-1,"select l.serviceupid,s.algorithm from services_links l,services s where s.serviceid=l.serviceupid and l.servicedownid=%d",serviceid); - result=DBselect_thread(database, sql); - status=0; - for(i=0;i<DBnum_rows(result);i++) - { - serviceupid=atoi(DBget_field(result,i,0)); - algorithm=atoi(DBget_field(result,i,1)); - if(SERVICE_ALGORITHM_NONE == algorithm) - { -/* Do nothing */ - } - else if((SERVICE_ALGORITHM_MAX == algorithm) - || - (SERVICE_ALGORITHM_MIN == algorithm)) - { - /* Why it was so complex ? - sprintf(sql,"select status from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid); - result2=DBselect(sql); - for(j=0;j<DBnum_rows(result2);j++) - { - if(atoi(DBget_field(result2,j,0))>status) - { - status=atoi(DBget_field(result2,j,0)); - } - } - DBfree_result(result2);*/ - - if(SERVICE_ALGORITHM_MAX == algorithm) - { - snprintf(sql,sizeof(sql)-1,"select count(*),max(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid); - } - /* MIN otherwise */ - else - { - snprintf(sql,sizeof(sql)-1,"select count(*),min(status) from services s,services_links l where l.serviceupid=%d and s.serviceid=l.servicedownid",serviceupid); - } - result2=DBselect_thread(database, sql); - if(atoi(DBget_field(result2,0,0))!=0) - { - status=atoi(DBget_field(result2,0,1)); - } - DBfree_result(result2); - - now=time(NULL); - DBadd_service_alarm_thread(database, atoi(DBget_field(result,i,0)),status,now); - snprintf(sql,sizeof(sql)-1,"update services set status=%d where serviceid=%d",status,atoi(DBget_field(result,i,0))); - DBexecute_thread(database, sql); - } - else - { - zabbix_log( LOG_LEVEL_ERR, "Unknown calculation algorithm of service status [%d]", algorithm); - zabbix_syslog("Unknown calculation algorithm of service status [%d]", algorithm); - } - } - DBfree_result(result); - - snprintf(sql,sizeof(sql)-1,"select serviceupid from services_links where servicedownid=%d",serviceid); - result=DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - update_serv_thread(database,atoi(DBget_field(result,i,0))); - } - DBfree_result(result); -} -#endif - /* * Recursive function! */ @@ -1814,31 +996,6 @@ void update_serv(int serviceid) DBfree_result(result); } -#ifdef ZABBIX_THREADS -void update_services_thread(MYSQL *database, int triggerid, int status) -{ - char sql[MAX_STRING_LEN]; - int i; - - DB_RESULT *result; - - snprintf(sql,sizeof(sql)-1,"update services set status=%d where triggerid=%d",status,triggerid); - DBexecute_thread(database, sql); - - - snprintf(sql,sizeof(sql)-1,"select serviceid from services where triggerid=%d", triggerid); - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - update_serv_thread(database, atoi(DBget_field(result,i,0))); - } - - DBfree_result(result); - return; -} -#endif - void update_services(int triggerid, int status) { char sql[MAX_STRING_LEN]; @@ -1862,111 +1019,6 @@ void update_services(int triggerid, int status) return; } -#ifdef ZABBIX_THREADS -/* -* Re-calculate values of triggers -*/ -void update_triggers_thread(MYSQL *database, int itemid) -{ - char sql[MAX_STRING_LEN]; - char exp[MAX_STRING_LEN]; - int b; - int now; - DB_TRIGGER trigger; - DB_RESULT *result; - - int i; - int prevvalue; - - zabbix_log( LOG_LEVEL_DEBUG, "In update_triggers [%d]", itemid); - -/* Does not work for PostgreSQL */ -/* sprintf(sql,"select t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value from triggers t,functions f,items i where i.status<>3 and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d group by t.triggerid,t.expression,t.dep_level",TRIGGER_STATUS_ENABLED,sucker_num);*/ -/* Is it correct SQL? */ - snprintf(sql,sizeof(sql)-1,"select distinct t.triggerid,t.expression,t.status,t.dep_level,t.priority,t.value,t.description from triggers t,functions f,items i where i.status<>%d and i.itemid=f.itemid and t.status=%d and f.triggerid=t.triggerid and f.itemid=%d",ITEM_STATUS_NOTSUPPORTED, TRIGGER_STATUS_ENABLED, itemid); - - result = DBselect_thread(database, sql); - - for(i=0;i<DBnum_rows(result);i++) - { - trigger.triggerid=atoi(DBget_field(result,i,0)); - trigger.expression=DBget_field(result,i,1); - trigger.status=atoi(DBget_field(result,i,2)); - trigger.priority=atoi(DBget_field(result,i,4)); - - trigger.value=atoi(DBget_field(result,i,5)); - trigger.description=DBget_field(result,i,6); - strscpy(exp, trigger.expression); - if( evaluate_expression_thread(database, &b, exp) != 0 ) - { - zabbix_log( LOG_LEVEL_WARNING, "Expression [%s] cannot be evaluated.",trigger.expression); - zabbix_syslog("Expression [%s] cannot be evaluated.",trigger.expression); - continue; - } - -/* Oprimise a little bit */ - prevvalue=DBget_prev_trigger_value_thread(database, trigger.triggerid); - - zabbix_log( LOG_LEVEL_DEBUG, "b trigger.value prevvalue [%d] [%d] [%d]", b, trigger.value, prevvalue); - - if(TRIGGER_VALUE_TRUE == b) - { - if(trigger.value != TRIGGER_VALUE_TRUE) - { - now = time(NULL); - DBupdate_trigger_value_thread(database, trigger.triggerid,TRIGGER_VALUE_TRUE,now); - } - if((trigger.value == TRIGGER_VALUE_FALSE) - || - ( - (trigger.value == TRIGGER_VALUE_UNKNOWN) && -/* Optimise a little bit. This optimisation does not work because DBupdate_trigger_value may add alarm! */ - (prevvalue == TRIGGER_VALUE_FALSE) -/* (DBget_prev_trigger_value(trigger.triggerid) == TRIGGER_VALUE_FALSE)*/ - )) - { - now = time(NULL); -/* apply_actions(trigger.triggerid,1);*/ - apply_actions_thread(database, &trigger,1); - - snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=0 where triggerid=%d and good=0",trigger.triggerid); - DBexecute_thread(database,sql); - - update_services_thread(database,trigger.triggerid, trigger.priority); - } - - } - - if(TRIGGER_VALUE_FALSE == b) - { - if(trigger.value != TRIGGER_VALUE_FALSE) - { - now = time(NULL); - DBupdate_trigger_value_thread(database,trigger.triggerid,TRIGGER_VALUE_FALSE,now); - } - if((trigger.value == TRIGGER_VALUE_TRUE) - || - ( - (trigger.value == TRIGGER_VALUE_UNKNOWN) && -/* Optimise a little bit. This optimisation does not work because DBupdate_trigger_value may add alarm! */ - (prevvalue == TRIGGER_VALUE_TRUE) -/* (DBget_prev_trigger_value(trigger.triggerid) == TRIGGER_VALUE_TRUE)*/ - )) - { -/* apply_actions(trigger.triggerid,0);*/ - apply_actions_thread(database,&trigger,0); - - snprintf(sql,sizeof(sql)-1,"update actions set nextcheck=0 where triggerid=%d and good=1",trigger.triggerid); - DBexecute_thread(database,sql); - - update_services_thread(database,trigger.triggerid, 0); - } - } - } - DBfree_result(result); -} -#endif - /* * Re-calculate values of triggers */ @@ -2070,72 +1122,6 @@ void update_triggers(int itemid) DBfree_result(result); } -#ifdef ZABBIX_THREADS -/* - The fuction is used to evaluate macros for email notifications -*/ -int get_lastvalue_thread(MYSQL *database, char *value,char *host,char *key,char *function,char *parameter) -{ - DB_ITEM item; - DB_RESULT *result; - - char sql[MAX_STRING_LEN]; - char *s; - int res; - - zabbix_log(LOG_LEVEL_DEBUG, "In get_lastvalue()" ); - - snprintf(sql,sizeof(sql)-1,"select i.itemid,i.prevvalue,i.lastvalue,i.value_type,i.multiplier,i.units from items i,hosts h where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", host, key ); - result = DBselect_thread(database,sql); - - if(DBnum_rows(result) == 0) - { - DBfree_result(result); - zabbix_log(LOG_LEVEL_WARNING, "Query [%s] returned empty result", sql ); - zabbix_syslog("Query [%s] returned empty result", sql ); - return FAIL; - } - - item.itemid=atoi(DBget_field(result,0,0)); - s=DBget_field(result,0,1); - if(s==NULL) - { - item.prevvalue_null=1; - } - else - { - item.prevvalue_null=0; - item.prevvalue_str=s; - item.prevvalue=atof(s); - } - s=DBget_field(result,0,2); - if(s==NULL) - { - item.lastvalue_null=1; - } - else - { - item.lastvalue_null=0; - item.lastvalue_str=s; - item.lastvalue=atof(s); - } - item.value_type=atoi(DBget_field(result,0,3)); - - item.multiplier=atoi(DBget_field(result,0,4)); - item.units=DBget_field(result,0,5); - - zabbix_log(LOG_LEVEL_DEBUG, "Itemid:%d", item.itemid ); - - zabbix_log(LOG_LEVEL_DEBUG, "Before evaluate_FUNCTION()" ); - - res = evaluate_FUNCTION_thread(database, value,&item,function,parameter, EVALUATE_FUNCTION_SUFFIX); - -/* Cannot call DBfree_result until evaluate_FUNC */ - DBfree_result(result); - return res; -} -#endif - /* The fuction is used to evaluate macros for email notifications */ @@ -2213,13 +1199,13 @@ int send_list_of_active_checks(int sockfd, char *host) zabbix_log( LOG_LEVEL_DEBUG, "In send_list_of_active_checks()"); - snprintf(sql,sizeof(sql)-1,"select i.key_,i.delay from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host); + snprintf(sql,sizeof(sql)-1,"select i.key_,i.delay,i.lastlogsize from items i,hosts h where i.hostid=h.hostid and h.status=%d and i.status=%d and i.type=%d and h.host='%s'", HOST_STATUS_MONITORED, ITEM_STATUS_ACTIVE, ITEM_TYPE_ZABBIX_ACTIVE, host); result = DBselect(sql); for(i=0;i<DBnum_rows(result);i++) { - snprintf(s,sizeof(s)-1,"%s:%s\n",DBget_field(result,i,0),DBget_field(result,i,1)); + snprintf(s,sizeof(s)-1,"%s:%s:%s\n",DBget_field(result,i,0),DBget_field(result,i,1),DBget_field(result,i,2)); zabbix_log( LOG_LEVEL_DEBUG, "Sending [%s]", s); if( write(sockfd,s,strlen(s)) == -1 ) { @@ -2265,6 +1251,7 @@ int process_data(int sockfd,char *server,char *key,char *value) DB_RESULT *result; DB_ITEM item; char *s; + char lastlogsize[MAX_STRING_LEN]; zabbix_log( LOG_LEVEL_DEBUG, "In process_data()"); @@ -2335,151 +1322,33 @@ int process_data(int sockfd,char *server,char *key,char *value) item.multiplier=atoi(DBget_field(result,0,19)); item.formula=DBget_field(result,0,20); - process_new_value(&item,value); - - update_triggers(item.itemid); - - DBfree_result(result); - - return SUCCEED; -} - -#ifdef ZABBIX_THREADS -void process_new_value_thread(MYSQL *database, DB_ITEM *item,char *value) -{ - int now; - char sql[MAX_STRING_LEN]; - char value_str[MAX_STRING_LEN]; - char value_esc[MAX_STRING_LEN]; - double value_double; - double multiplier; - char *e; - - now = time(NULL); - - strscpy(value_str, value); - - zabbix_log( LOG_LEVEL_DEBUG, "In process_new_value()"); - value_double=strtod(value_str,&e); - - if( (item->value_type==ITEM_VALUE_TYPE_FLOAT) && (item->multiplier == ITEM_MULTIPLIER_USE)) - { - multiplier = strtod(item->formula,&e); - value_double = value_double * multiplier; - snprintf(value_str,sizeof(value_str)-1,"%f",value_double); - } - - if(item->history>0) + s=value; + if(strncmp(item.key,"log[",4)==0) { - if(item->value_type==ITEM_VALUE_TYPE_FLOAT) - { - /* Should we store delta or original value? */ - if(item->delta == ITEM_STORE_AS_IS) - { - DBadd_history_thread(database, item->itemid,value_double,now); - } - /* Delta as speed of change */ - else if(item->delta == ITEM_STORE_SPEED_PER_SECOND) - { - /* Save delta */ - if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) - { - DBadd_history_thread(database, item->itemid, (value_double - item->prevorgvalue)/(now-item->lastclock), now); - } - } - /* Real delta: simple difference between values */ - else if(item->delta == ITEM_STORE_SIMPLE_CHANGE) - { - /* Save delta */ - if((item->prevorgvalue_null == 0) && (item->prevorgvalue <= value_double) ) - { - DBadd_history_thread(database, item->itemid, (value_double - item->prevorgvalue), now); - } - } - else - { - zabbix_log(LOG_LEVEL_ERR, "Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta); - zabbix_syslog("Value not stored for itemid [%d]. Unknown delta [%d]", item->itemid, item->delta); - return; - } - } - else + s=strchr(value,':'); + if(s == NULL) { - DBadd_history_str_thread(database, item->itemid,value_str,now); + zabbix_log(LOG_LEVEL_WARNING, "Wrong value received for item [%s:%s]", item.host, item.key); + DBfree_result(result); + return FAIL; } - } + s++; + strncpy(lastlogsize, value, s-value-1); + lastlogsize[s-value-1]=0; - if(item->delta == ITEM_STORE_AS_IS) - { - if((item->prevvalue_null == 1) || (strcmp(value_str,item->lastvalue_str) != 0) || (strcmp(item->prevvalue_str,item->lastvalue_str) != 0) ) - { - 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);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),value_esc,now,item->itemid); - item->prevvalue=item->lastvalue; - item->lastvalue=value_double; - item->prevvalue_str=item->lastvalue_str; - /* Risky !!!*/ - item->lastvalue_str=value_str; - item->prevvalue_null=item->lastvalue_null; - item->lastvalue_null=0; - } - else - { -/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",now+item->delay,now,item->itemid);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),now,item->itemid); - } + item.lastlogsize=atoi(lastlogsize); + zabbix_log(LOG_LEVEL_DEBUG, "Value [%s] S [%s] Lastlogsize [%s] [%d]", value, s, lastlogsize, s-value-1); } - /* Logic for delta as speed of change */ - else if(item->delta == ITEM_STORE_SPEED_PER_SECOND) - { - 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);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),value_double,(value_double - item->prevorgvalue)/(now-item->lastclock),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);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),value_double,now,item->itemid); - } - item->prevvalue=item->lastvalue; - item->lastvalue=(value_double - item->prevorgvalue)/(now-item->lastclock); - item->prevvalue_str=item->lastvalue_str; - /* Risky !!!*/ - item->lastvalue_str=value_str; - item->prevvalue_null=item->lastvalue_null; - item->lastvalue_null=0; - } - /* Real delta: simple difference between values */ - else if(item->delta == ITEM_STORE_SIMPLE_CHANGE) - { - 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->itemid);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,prevorgvalue=%f,lastvalue='%f',lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),value_double,(value_double - item->prevorgvalue),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);*/ - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevorgvalue=%f,lastclock=%d where itemid=%d",calculate_item_nextcheck(item->nextcheck,item->delay,now),value_double,now,item->itemid); - } + process_new_value(&item,s); - item->prevvalue=item->lastvalue; - item->lastvalue=(value_double - item->prevorgvalue); - item->prevvalue_str=item->lastvalue_str; - /* Risky !!!*/ - item->lastvalue_str=value_str; - item->prevvalue_null=item->lastvalue_null; - item->lastvalue_null=0; - } - DBexecute_thread(database,sql); + update_triggers(item.itemid); + + DBfree_result(result); - update_functions_thread(database, item ); + return SUCCEED; } -#endif void process_new_value(DB_ITEM *item,char *value) { @@ -2546,6 +1415,8 @@ void process_new_value(DB_ITEM *item,char *value) else if(item->value_type==ITEM_VALUE_TYPE_LOG) { DBadd_history_log(item->itemid,value_str,now); + snprintf(sql,sizeof(sql)-1,"update items set lastlogsize=%d where itemid=%d",item->lastlogsize,item->itemid); + DBexecute(sql); } else { diff --git a/include/functions.h b/include/functions.h index e4bfd734..1949bb5a 100644 --- a/include/functions.h +++ b/include/functions.h @@ -33,15 +33,4 @@ int process_data(int sockfd,char *server,char *key, char *value); void process_new_value(DB_ITEM *item,char *value); int send_list_of_active_checks(int sockfd, char *host); -#ifdef ZABBIX_THREADS -void update_triggers_thread(MYSQL *database, int itemid); -void process_new_value_thread(MYSQL *database, DB_ITEM *item,char *value); -void update_services_thread(MYSQL *database, int triggerid, int status); -void update_serv_thread(MYSQL *database,int serviceid); -void apply_actions_thread(MYSQL *database, DB_TRIGGER *trigger,int trigger_value); -void send_to_user_thread(MYSQL *database, DB_TRIGGER *trigger,DB_ACTION *action); -void update_functions_thread(MYSQL *database, DB_ITEM *item); -int get_lastvalue_thread(MYSQL *database, char *value,char *host,char *key,char *function,char *parameter); -#endif - #endif diff --git a/src/zabbix_agent/active.c b/src/zabbix_agent/active.c index 56ae0eb1..cf7c1820 100644 --- a/src/zabbix_agent/active.c +++ b/src/zabbix_agent/active.c @@ -114,7 +114,7 @@ int get_min_nextcheck() return min; } -void add_check(char *key, int refresh) +void add_check(char *key, int refresh, int lastlogsize) { int i; @@ -128,7 +128,7 @@ void add_check(char *key, int refresh) metrics[i].refresh=refresh; metrics[i].nextcheck=0; metrics[i].status=ITEM_STATUS_ACTIVE; - metrics[i].lastlogsize=0; + metrics[i].lastlogsize=lastlogsize; metrics=realloc(metrics,(i+2)*sizeof(METRIC)); metrics[i+1].key=NULL; @@ -141,6 +141,7 @@ void add_check(char *key, int refresh) metrics[i].nextcheck=0; } metrics[i].refresh=refresh; + metrics[i].lastlogsize=lastlogsize; metrics[i].status=ITEM_STATUS_ACTIVE; break; } @@ -151,7 +152,7 @@ void add_check(char *key, int refresh) int parse_list_of_checks(char *str) { char *line; - char *key, *refresh; + char *key, *refresh, *lastlogsize; char *s1, *s2; disable_all_metrics(); @@ -167,8 +168,10 @@ int parse_list_of_checks(char *str) zabbix_log( LOG_LEVEL_DEBUG, "Key [%s]", key); refresh=(char *)strtok_r(NULL,":",&s2); zabbix_log( LOG_LEVEL_DEBUG, "Refresh [%s]", refresh); + lastlogsize=(char *)strtok_r(NULL,":",&s2); + zabbix_log( LOG_LEVEL_DEBUG, "Lastlogsize [%s]", lastlogsize); - add_check(key, atoi(refresh)); + add_check(key, atoi(refresh), atoi(lastlogsize)); line=(char *)strtok_r(NULL,"\n",&s1); } @@ -380,6 +383,7 @@ int send_value(char *server,int port,char *shortname,char *value) int process_active_checks(char *server, int port) { char value[MAX_STRING_LEN]; + char value_tmp[MAX_STRING_LEN]; int i, now, count; int ret = SUCCEED; @@ -407,7 +411,8 @@ int process_active_checks(char *server, int port) { snprintf(shortname, MAX_STRING_LEN-1,"%s:%s",CONFIG_HOSTNAME,metrics[i].key); zabbix_log( LOG_LEVEL_DEBUG, "%s",shortname); - if(send_value(server,port,shortname,value) == FAIL) + snprintf(value_tmp, MAX_STRING_LEN-1,"%d:%s",metrics[i].lastlogsize,value); + if(send_value(server,port,shortname,value_tmp) == FAIL) { ret = FAIL; break; diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c index 3191576f..930799b0 100644 --- a/src/zabbix_agent/sysinfo.c +++ b/src/zabbix_agent/sysinfo.c @@ -2541,7 +2541,7 @@ int DISK_WBLK(const char *cmd, const char *parameter,double *value) int VERSION(const char *cmd, const char *parameter,char **value) { - static char version[]="1.1alpha9"; + static char version[]=ZABBIX_VERSION; *value=strdup(version); return SYSINFO_RET_OK; diff --git a/src/zabbix_server/alerter.c b/src/zabbix_server/alerter.c index 5b1ffb58..b38e9bae 100644 --- a/src/zabbix_server/alerter.c +++ b/src/zabbix_server/alerter.c @@ -130,11 +130,7 @@ int send_alert(DB_ALERT *alert,DB_MEDIATYPE *mediatype, char *error, int max_err return res; } -#ifdef ZABBIX_THREADS -void *main_alerter_loop() -#else int main_alerter_loop() -#endif { char sql[MAX_STRING_LEN]; char error[MAX_STRING_LEN]; @@ -144,36 +140,20 @@ int main_alerter_loop() struct sigaction phan; -#ifdef ZABBIX_THREADS - DB_HANDLE database; -#endif - DB_RESULT *result; DB_ALERT alert; DB_MEDIATYPE mediatype; -#ifdef ZABBIX_THREADS - my_thread_init(); -#endif - for(;;) { #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("connecting to the database"); #endif -#ifdef ZABBIX_THREADS - DBconnect_thread(&database); -#else DBconnect(); -#endif snprintf(sql,sizeof(sql)-1,"select a.alertid,a.mediatypeid,a.sendto,a.subject,a.message,a.status,a.retries,mt.mediatypeid,mt.type,mt.description,mt.smtp_server,mt.smtp_helo,mt.smtp_email,mt.exec_path from alerts a,media_type mt where a.status=0 and a.retries<3 and a.mediatypeid=mt.mediatypeid order by a.clock"); -#ifdef ZABBIX_THREADS - result = DBselect_thread(&database, sql); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { @@ -215,21 +195,13 @@ int main_alerter_loop() zabbix_syslog("Error sending alert ID [%d]", alert.alertid); DBescape_string(error,error_esc,MAX_STRING_LEN); snprintf(sql,sizeof(sql)-1,"update alerts set retries=retries+1,error='%s' where alertid=%d", error_esc, alert.alertid); -#ifdef ZABBIX_THREADS - DBexecute_thread(&database,sql); -#else DBexecute(sql); -#endif } } DBfree_result(result); -#ifdef ZABBIX_THREADS - DBclose_thread(&database); -#else DBclose(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("sender [sleeping for %d seconds]", CONFIG_SENDER_FREQUENCY); #endif diff --git a/src/zabbix_server/alerter.h b/src/zabbix_server/alerter.h index 52a0a621..5fba1229 100644 --- a/src/zabbix_server/alerter.h +++ b/src/zabbix_server/alerter.h @@ -30,10 +30,6 @@ extern char *CONFIG_ALERT_SCRIPTS_PATH; extern void signal_handler( int sig ); -#ifdef ZABBIX_THREADS -void *main_alerter_loop(); -#else int main_alerter_loop(); -#endif #endif diff --git a/src/zabbix_server/checks_internal.c b/src/zabbix_server/checks_internal.c index 0140f795..a76a6f35 100644 --- a/src/zabbix_server/checks_internal.c +++ b/src/zabbix_server/checks_internal.c @@ -20,59 +20,6 @@ #include "common.h" #include "checks_internal.h" -#ifdef ZABBIX_THREADS -int get_value_internal(double *result,char *result_str,DB_ITEM *item,char *error,int max_error_len) -{ - DB_HANDLE database; - - DBconnect_thread(&database); - - if(strcmp(item->key,"zabbix[triggers]")==0) - { - *result=DBget_triggers_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[items]")==0) - { - *result=DBget_items_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[items_unsupported]")==0) - { - *result=DBget_items_unsupported_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[history]")==0) - { - *result=DBget_history_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[history_str]")==0) - { - *result=DBget_history_str_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[trends]")==0) - { - *result=DBget_trends_count_thread(&database); - } - else if(strcmp(item->key,"zabbix[queue]")==0) - { - *result=DBget_queue_count_thread(&database); - } - else - { - DBclose_thread(&database); - zabbix_log( LOG_LEVEL_WARNING, "Internal check [%s] is not supported", item->key); - snprintf(error,max_error_len-1,"Internal check [%s] is not supported", item->key); - return NOTSUPPORTED; - } - - snprintf(result_str,MAX_STRING_LEN-1,"%f",*result); - - zabbix_log( LOG_LEVEL_DEBUG, "INTERNAL [%s] [%f]", result_str, *result); - - DBclose_thread(&database); - - return SUCCEED; -} - -#else int get_value_internal(double *result,char *result_str,DB_ITEM *item,char *error,int max_error_len) { if(strcmp(item->key,"zabbix[triggers]")==0) @@ -115,4 +62,3 @@ int get_value_internal(double *result,char *result_str,DB_ITEM *item,char *error zabbix_log( LOG_LEVEL_DEBUG, "INTERNAL [%s] [%f]", result_str, *result); return SUCCEED; } -#endif diff --git a/src/zabbix_server/housekeeper.c b/src/zabbix_server/housekeeper.c index ceded21c..54e488c5 100644 --- a/src/zabbix_server/housekeeper.c +++ b/src/zabbix_server/housekeeper.c @@ -51,70 +51,42 @@ #include "housekeeper.h" /* Remove items having status 'deleted' */ -#ifdef ZABBIX_THREADS -void *housekeeping_items(MYSQL *database) -#else int housekeeping_items(void) -#endif { char sql[MAX_STRING_LEN]; DB_RESULT *result; int i,itemid; snprintf(sql,sizeof(sql)-1,"select itemid from items where status=%d", ITEM_STATUS_DELETED); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { itemid=atoi(DBget_field(result,i,0)); -#ifdef ZABBIX_THREADS - DBdelete_item_thread(database, itemid); -#else DBdelete_item(itemid); -#endif } DBfree_result(result); return SUCCEED; } /* Remove hosts having status 'deleted' */ -#ifdef ZABBIX_THREADS -int housekeeping_hosts(MYSQL *database) -#else int housekeeping_hosts(void) -#endif { char sql[MAX_STRING_LEN]; DB_RESULT *result; int i,hostid; snprintf(sql,sizeof(sql)-1,"select hostid from hosts where status=%d", HOST_STATUS_DELETED); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { hostid=atoi(DBget_field(result,i,0)); -#ifdef ZABBIX_THREADS - DBdelete_host_thread(database, hostid); -#else DBdelete_host(hostid); -#endif } DBfree_result(result); return SUCCEED; } -#ifdef ZABBIX_THREADS -int housekeeping_history_and_trends(MYSQL *database, int now) -#else int housekeeping_history_and_trends(int now) -#endif { char sql[MAX_STRING_LEN]; DB_ITEM item; @@ -126,11 +98,7 @@ int housekeeping_history_and_trends(int now) /* How lastdelete is used ??? */ /* snprintf(sql,sizeof(sql)-1,"select itemid,lastdelete,history,delay,trends from items where lastdelete<=%d", now);*/ snprintf(sql,sizeof(sql)-1,"select itemid,history,delay,trends from items"); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { @@ -150,11 +118,7 @@ int housekeeping_history_and_trends(int now) #else snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d and clock<%d",item.itemid,now-24*3600*item.history); #endif -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif /* Delete HISTORY_STR */ #ifdef HAVE_MYSQL @@ -162,11 +126,7 @@ int housekeeping_history_and_trends(int now) #else snprintf(sql,sizeof(sql)-1,"delete from history_str where itemid=%d and clock<%d",item.itemid,now-24*3600*item.history); #endif -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif /* Delete HISTORY_LOG */ #ifdef HAVE_MYSQL @@ -174,11 +134,7 @@ int housekeeping_history_and_trends(int now) #else snprintf(sql,sizeof(sql)-1,"delete from history_log where itemid=%d and clock<%d",item.itemid,now-24*3600*item.history); #endif -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif /* Delete HISTORY_TRENDS */ #ifdef HAVE_MYSQL @@ -186,46 +142,23 @@ int housekeeping_history_and_trends(int now) #else snprintf(sql,sizeof(sql)-1,"delete from trends where itemid=%d and clock<%d",item.itemid,now-24*3600*item.trends); #endif -#ifdef ZABBIX_THREADS - DBexecute_thread(database,sql); -#else - DBexecute(sql); -#endif -/* snprintf(sql,sizeof(sql)-1,"update items set lastdelete=%d where itemid=%d",now,item.itemid); -#ifdef ZABBIX_THREADS - DBexecute_thread(database,sql); -#else DBexecute(sql); -#endif -*/ } DBfree_result(result); return SUCCEED; } -#ifdef ZABBIX_THREADS -int housekeeping_sessions(MYSQL *database, int now) -#else int housekeeping_sessions(int now) -#endif { char sql[MAX_STRING_LEN]; snprintf(sql,sizeof(sql)-1,"delete from sessions where lastaccess<%d",now-24*3600); -#ifdef ZABBIX_THREADS - DBexecute_thread(database,sql); -#else DBexecute(sql); -#endif return SUCCEED; } -#ifdef ZABBIX_THREADS -int housekeeping_alerts(MYSQL *database, int now) -#else int housekeeping_alerts(int now) -#endif { char sql[MAX_STRING_LEN]; int alert_history; @@ -233,11 +166,7 @@ int housekeeping_alerts(int now) int res = SUCCEED; snprintf(sql,sizeof(sql)-1,"select alert_history from config"); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif if(DBnum_rows(result) == 0) { @@ -249,22 +178,14 @@ int housekeeping_alerts(int now) alert_history=atoi(DBget_field(result,0,0)); snprintf(sql,sizeof(sql)-1,"delete from alerts where clock<%d",now-24*3600*alert_history); -#ifdef ZABBIX_THREADS - DBexecute_thread(database,sql); -#else DBexecute(sql); -#endif } DBfree_result(result); return res; } -#ifdef ZABBIX_THREADS -int housekeeping_alarms(MYSQL *database, int now) -#else int housekeeping_alarms(int now) -#endif { char sql[MAX_STRING_LEN]; int alarm_history; @@ -272,11 +193,7 @@ int housekeeping_alarms(int now) int res = SUCCEED; snprintf(sql,sizeof(sql)-1,"select alarm_history from config"); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif if(DBnum_rows(result) == 0) { zabbix_log( LOG_LEVEL_ERR, "No records in table 'config'."); @@ -287,33 +204,17 @@ int housekeeping_alarms(int now) alarm_history=atoi(DBget_field(result,0,0)); snprintf(sql,sizeof(sql)-1,"delete from alarms where clock<%d",now-24*3600*alarm_history); -#ifdef ZABBIX_THREADS - DBexecute_thread(database,sql); -#else DBexecute(sql); -#endif } DBfree_result(result); return res; } -#ifdef ZABBIX_THREADS -void *main_housekeeper_loop() -#else int main_housekeeper_loop() -#endif { int now; -#ifdef ZABBIX_THREADS - DB_HANDLE database; -#endif - -#ifdef ZABBIX_THREADS - my_thread_init(); -#endif - if(CONFIG_DISABLE_HOUSEKEEPING == 1) { for(;;) @@ -332,79 +233,47 @@ int main_housekeeper_loop() #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("connecting to the database"); #endif -#ifdef ZABBIX_THREADS - DBconnect_thread(&database); -#else DBconnect(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing deleted hosts]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_hosts(&database); -#else housekeeping_hosts(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing deleted items]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_items(&database); -#else housekeeping_items(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old values]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_history_and_trends(&database, now); -#else housekeeping_history_and_trends(now); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old alarms]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_alarms(&database, now); -#else housekeeping_alarms(now); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old alerts]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_alerts(&database, now); -#else housekeeping_alerts(now); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old sessions]"); #endif -#ifdef ZABBIX_THREADS - housekeeping_sessions(&database, now); -#else housekeeping_sessions(now); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [vacuuming database]"); #endif -#ifdef ZABBIX_THREADS - DBvacuum_thread(&database); -#else DBvacuum(); -#endif zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d hours", CONFIG_HOUSEKEEPING_FREQUENCY); @@ -412,11 +281,7 @@ int main_housekeeper_loop() setproctitle("housekeeper [sleeping for %d hour(s)]", CONFIG_HOUSEKEEPING_FREQUENCY); #endif -#ifdef ZABBIX_THREADS - DBclose_thread(&database); -#else DBclose(); -#endif sleep(3660*CONFIG_HOUSEKEEPING_FREQUENCY); } } diff --git a/src/zabbix_server/housekeeper.h b/src/zabbix_server/housekeeper.h index 07c5d008..987c23fe 100644 --- a/src/zabbix_server/housekeeper.h +++ b/src/zabbix_server/housekeeper.h @@ -29,10 +29,6 @@ extern char *CONFIG_DBPASSWORD; extern char *CONFIG_DBSOCKET; extern char *CONFIG_FPING_LOCATION; -#ifdef ZABBIX_THREADS -void *main_housekeeper_loop(); -#else int main_housekeeper_loop(); -#endif #endif diff --git a/src/zabbix_server/pinger.c b/src/zabbix_server/pinger.c index 810d144f..eae4dc5f 100644 --- a/src/zabbix_server/pinger.c +++ b/src/zabbix_server/pinger.c @@ -87,11 +87,7 @@ int is_ip(char *ip) return res; } -#ifdef ZABBIX_THREADS -int process_value(MYSQL *database, char *key, char *host, char *value) -#else int process_value(char *key, char *host, char *value) -#endif { char sql[MAX_STRING_LEN]; @@ -111,11 +107,7 @@ int process_value(char *key, char *host, char *value) snprintf(sql,sizeof(sql)-1,"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.value_type,i.trapper_hosts,i.delta,i.units,i.multiplier,i.formula from items i,hosts h where h.status=%d and h.hostid=i.hostid and h.host='%s' and i.key_='%s' and i.status=%d and i.type=%d", HOST_STATUS_MONITORED, host, key, ITEM_STATUS_ACTIVE, ITEM_TYPE_SIMPLE); } zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]", sql); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif if(DBnum_rows(result) == 0) { @@ -166,24 +158,15 @@ int process_value(char *key, char *host, char *value) item.multiplier=atoi(DBget_field(result,0,19)); item.formula=DBget_field(result,0,20); -#ifdef ZABBIX_THREADS - process_new_value_thread(database,&item,value); - update_triggers_thread(database,item.itemid); -#else process_new_value(&item,value); update_triggers(item.itemid); -#endif DBfree_result(result); return SUCCEED; } -#ifdef ZABBIX_THREADS -int create_host_file(MYSQL *database) -#else int create_host_file(void) -#endif { char sql[MAX_STRING_LEN]; FILE *f; @@ -206,12 +189,8 @@ int create_host_file(void) now=time(NULL); /* Select hosts monitored by IP */ snprintf(sql,sizeof(sql)-1,"select distinct h.ip from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=1", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif - + for(i=0;i<DBnum_rows(result);i++) { host.ip=DBget_field(result,i,0); @@ -225,12 +204,8 @@ int create_host_file(void) /* Select hosts monitored by hostname */ snprintf(sql,sizeof(sql)-1,"select distinct h.host from hosts h,items i where i.hostid=h.hostid and (h.status=%d or (h.status=%d and h.available=%d and h.disable_until<=%d)) and (i.key_='%s' or i.key_='%s') and i.type=%d and i.status=%d and h.useip=0", HOST_STATUS_MONITORED, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, ITEM_TYPE_SIMPLE, ITEM_STATUS_ACTIVE); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else result = DBselect(sql); -#endif - + for(i=0;i<DBnum_rows(result);i++) { host.host=DBget_field(result,i,0); @@ -247,11 +222,7 @@ int create_host_file(void) } -#ifdef ZABBIX_THREADS -int do_ping(MYSQL *database) -#else int do_ping(void) -#endif { FILE *f; char ip[MAX_STRING_LEN]; @@ -297,24 +268,14 @@ int do_ping(void) zabbix_log( LOG_LEVEL_DEBUG, "IP [%s] alive [%d]", ip, alive); if(0 == alive) { -#ifdef ZABBIX_THREADS - process_value(database,SERVER_ICMPPING_KEY,ip,"0"); - process_value(database,SERVER_ICMPPINGSEC_KEY,ip,"0"); -#else process_value(SERVER_ICMPPING_KEY,ip,"0"); process_value(SERVER_ICMPPINGSEC_KEY,ip,"0"); -#endif } else { snprintf(tmp,sizeof(tmp)-1,"%f",mseconds/1000); -#ifdef ZABBIX_THREADS - process_value(database,SERVER_ICMPPING_KEY,ip,"1"); - process_value(database,SERVER_ICMPPINGSEC_KEY,ip,tmp); -#else process_value(SERVER_ICMPPING_KEY,ip,"1"); process_value(SERVER_ICMPPINGSEC_KEY,ip,tmp); -#endif } } } @@ -325,19 +286,10 @@ int do_ping(void) return SUCCEED; } -#ifdef ZABBIX_THREADS -void *main_pinger_loop() -#else int main_pinger_loop() -#endif { int ret = SUCCEED; -#ifdef ZABBIX_THREADS - DB_HANDLE database; -#endif - - if(1 == CONFIG_DISABLE_PINGER) { for(;;) @@ -353,19 +305,11 @@ int main_pinger_loop() setproctitle("connecting to the database"); #endif -#ifdef ZABBIX_THREADS - DBconnect_thread(&database); -#else DBconnect(); -#endif /* zabbix_set_log_level(LOG_LEVEL_DEBUG);*/ -#ifdef ZABBIX_THREADS - ret = create_host_file(&database); -#else ret = create_host_file(); -#endif if( SUCCEED == ret) { @@ -373,21 +317,13 @@ int main_pinger_loop() setproctitle("pinging hosts"); #endif -#ifdef ZABBIX_THREADS - ret = do_ping(&database); -#else ret = do_ping(); -#endif } unlink("/tmp/zabbix_suckerd.pinger"); /* zabbix_set_log_level(LOG_LEVEL_WARNING); */ -#ifdef ZABBIX_THREADS - DBclose_thread(&database); -#else DBclose(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("pinger [sleeping for %d seconds]", CONFIG_PINGER_FREQUENCY); diff --git a/src/zabbix_server/pinger.h b/src/zabbix_server/pinger.h index c0727fd2..17538f59 100644 --- a/src/zabbix_server/pinger.h +++ b/src/zabbix_server/pinger.h @@ -31,10 +31,6 @@ extern char *CONFIG_FPING_LOCATION; extern void signal_handler( int sig ); -#ifdef ZABBIX_THREADS -void *main_pinger_loop(); -#else int main_pinger_loop(); -#endif #endif diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c index ae3a58ee..e653b478 100644 --- a/src/zabbix_server/server.c +++ b/src/zabbix_server/server.c @@ -42,10 +42,6 @@ #include "log.h" #include "zlog.h" -#ifdef ZABBIX_THREADS - #include <pthread.h> -#endif - #include "common.h" #include "functions.h" #include "expression.h" @@ -62,27 +58,6 @@ #define LISTENQ 1024 -#ifdef ZABBIX_THREADS -struct poller_answer { - int status; /* 0 - not received 1 - in processing 2 - received */ - int itemid; - int ret; - double value; - char value_str[100]; -}; - -struct poller_answer requests[10000]; -int answer_count = 0; -int request_count = 0; - -pthread_mutex_t poller_mutex; - -pthread_mutex_t result_mutex; -pthread_cond_t result_cv; -int state = 0; /* 0 - select data from DB, 1 - poll values from agents, 2 - update database */ -DB_RESULT *shared_result; -#endif - static pid_t *pids=NULL; static int sucker_num=0; @@ -236,7 +211,7 @@ void daemon_init(void) void usage(char *prog) { - printf("zabbix_server - ZABBIX server process v1.1alpha9\n"); + printf("zabbix_server - ZABBIX server process %s\n", ZABBIX_VERSION); printf("Usage: %s [-h] [-c <file>]\n", prog); printf("\nOptions:\n"); printf(" -c <file> Specify configuration file. Default is /etc/zabbix/zabbix_server.conf\n"); @@ -249,11 +224,7 @@ void init_config(void) static struct cfg_line cfg[]= { /* PARAMETER ,VAR ,FUNC, TYPE(0i,1s),MANDATORY,MIN,MAX */ -#ifdef ZABBIX_THREADS - {"StartSuckers",&CONFIG_SUCKERD_FORKS,0,TYPE_INT,PARM_OPT,6,255}, -#else {"StartSuckers",&CONFIG_SUCKERD_FORKS,0,TYPE_INT,PARM_OPT,5,255}, -#endif {"HousekeepingFrequency",&CONFIG_HOUSEKEEPING_FREQUENCY,0,TYPE_INT,PARM_OPT,1,24}, {"SenderFrequency",&CONFIG_SENDER_FREQUENCY,0,TYPE_INT,PARM_OPT,5,3600}, {"PingerFrequency",&CONFIG_PINGER_FREQUENCY,0,TYPE_INT,PARM_OPT,1,3600}, @@ -350,47 +321,6 @@ int get_value(double *result,char *result_str,DB_ITEM *item, char *error, int ma return res; } -#ifdef ZABBIX_THREADS -int get_minnextcheck_thread(MYSQL *database, int now) -{ - char sql[MAX_STRING_LEN]; - - DB_RESULT *result; - - int res; - -/* Host status 0 == MONITORED - 1 == NOT MONITORED - 2 == UNREACHABLE */ - snprintf(sql,sizeof(sql)-1,"select count(*),min(nextcheck) from items i,hosts h where ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and h.hostid=i.hostid and i.status=%d and i.type not in (%d,%d) and i.key_ not in ('%s','%s','%s','%s')", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE,HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY, SERVER_ZABBIXLOG_KEY); -#ifdef ZABBIX_THREADS - result = DBselect_thread(database, sql); -#else - result = DBselect(sql); -#endif - - if( DBnum_rows(result) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "No items to update for minnextcheck."); - res = FAIL; - } - else - { - if( atoi(DBget_field(result,0,0)) == 0) - { - res = FAIL; - } - else - { - res = atoi(DBget_field(result,0,1)); - } - } - DBfree_result(result); - - return res; -} -#endif - int get_minnextcheck(int now) { char sql[MAX_STRING_LEN]; @@ -426,40 +356,6 @@ int get_minnextcheck(int now) return res; } -#ifdef ZABBIX_THREADS -/* Update special host's item - "status" */ -void update_key_status_thread(MYSQL *database, int hostid,int host_status) -{ - char sql[MAX_STRING_LEN]; - char value_str[MAX_STRING_LEN]; - char *s; - - DB_ITEM item; - DB_RESULT *result; - - zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status()"); - - snprintf(sql,sizeof(sql)-1,"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.network_errors,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 from items i,hosts h where h.hostid=i.hostid and h.hostid=%d and i.key_='%s'", hostid,SERVER_STATUS_KEY); - result = DBselect_thread(database, sql); - - if( DBnum_rows(result) == 0) - { - zabbix_log( LOG_LEVEL_DEBUG, "No items to update."); - } - else - { - DBget_item_from_db(&item,result,0); - - snprintf(value_str,sizeof(value_str)-1,"%d",host_status); - - process_new_value_thread(database,&item,value_str); - update_triggers_thread(database,item.itemid); - } - - DBfree_result(result); -} -#endif - /* Update special host's item - "status" */ void update_key_status(int hostid,int host_status) { @@ -516,11 +412,7 @@ void trend(void) DBfree_result(result2); } -#ifdef ZABBIX_THREADS -int get_values(MYSQL *database) -#else int get_values(void) -#endif { double value; char value_str[MAX_STRING_LEN]; @@ -539,99 +431,24 @@ int get_values(void) now = time(NULL); -#ifdef ZABBIX_THREADS - snprintf(sql,sizeof(sql)-1,"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.network_errors,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 from items i,hosts h where i.nextcheck<=%d and i.status=%d and i.type not in (%d,%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE,HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY); -#else snprintf(sql,sizeof(sql)-1,"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.network_errors,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 from items i,hosts h where i.nextcheck<=%d and i.status=%d and i.type not in (%d,%d) and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<=%d)) and h.hostid=i.hostid and i.itemid%%%d=%d and i.key_ not in ('%s','%s','%s','%s') order by i.nextcheck", now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, CONFIG_SUCKERD_FORKS-4,sucker_num-4,SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY); -#endif -#ifdef ZABBIX_THREADS - pthread_mutex_lock (&result_mutex); -// zabbix_log( LOG_LEVEL_WARNING, "\nSUCKER: waiting for state 0 [select data from DB] state [%d]", state); - while (state != 0) - { - pthread_cond_wait(&result_cv, &result_mutex); - } - pthread_mutex_unlock(&result_mutex); - - result = DBselect_thread(database, sql); - shared_result = result; - answer_count = 0; - request_count = DBnum_rows(result); - for(i=0;i<request_count;i++) - { - requests[i].status = 0; - requests[i].itemid=atoi(DBget_field(result,i,0)); - } - - - pthread_mutex_lock (&result_mutex); - state = 1; -// pthread_cond_signal(&result_cv); - zabbix_log( LOG_LEVEL_WARNING, "sucker: broadcast state [%d]", state); - pthread_cond_broadcast(&result_cv); - pthread_mutex_unlock(&result_mutex); - - pthread_mutex_lock (&result_mutex); - zabbix_log( LOG_LEVEL_WARNING, "sucker: waiting for request_count [%d] == answer_count [%d] [update data in DB] state [%d]", request_count, answer_count, state); -// while ( (state != 2) && (answer_count != request_count)) -// while (state != CONFIG_SUCKERD_FORKS-5+request_count) - while (answer_count!=request_count) - { - pthread_cond_wait(&result_cv, &result_mutex); -/* zabbix_log( LOG_LEVEL_WARNING, "sucker: YOPT %d %d", request_count, answer_count); - zabbix_log( LOG_LEVEL_WARNING, "sucker: before printing result"); - for(i=0;i<request_count;i++) - { - zabbix_log( LOG_LEVEL_WARNING, "sucker: before doing actual DB update: itemid [%d] status [%d]", atoi(DBget_field(shared_result,i,0)), requests[i].status ); - }*/ -// pthread_mutex_unlock (&poller_mutex); - } - pthread_mutex_unlock(&result_mutex); - - pthread_mutex_lock (&result_mutex); - state = 0; -// pthread_cond_signal(&result_cv); - zabbix_log( LOG_LEVEL_WARNING, "sucker: broadcast state [%d]", state); - pthread_cond_broadcast(&result_cv); - pthread_mutex_unlock(&result_mutex); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { DBget_item_from_db(&item,result, i); -#ifdef ZABBIX_THREADS - res = requests[i].ret; - value = requests[i].value; - strscpy(value_str,requests[i].value_str); - if(requests[i].status != 2) - { - zabbix_log( LOG_LEVEL_WARNING, "sucker: ERROR status [%d] expected [2] host [%s] key [%s]", requests[i].status, item.host, item.key ); - } -/* res = get_value(&value,value_str,&item);*/ -#else res = get_value(&value,value_str,&item,error,sizeof(error)); -#endif zabbix_log( LOG_LEVEL_DEBUG, "GOT VALUE [%s]", value_str ); if(res == SUCCEED ) { -#ifdef ZABBIX_THREADS - process_new_value_thread(database, &item,value_str); -#else process_new_value(&item,value_str); -#endif if(item.host_network_errors>0) { snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=0,error='' where hostid=%d and network_errors>0", item.hostid); -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif } /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ @@ -640,45 +457,27 @@ int get_values(void) item.host_available=HOST_AVAILABLE_TRUE; zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host ); zabbix_syslog("Enabling host [%s]", item.host ); -#ifdef ZABBIX_THREADS - DBupdate_host_availability_thread(database, item.hostid,HOST_AVAILABLE_TRUE,now,error); - update_key_status_thread(database, item.hostid,HOST_STATUS_MONITORED); -#else DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,error); update_key_status(item.hostid,HOST_STATUS_MONITORED); -#endif /* Why this break??? Trigger needs to be updated anyway! break;*/ } -#ifdef ZABBIX_THREADS - update_triggers_thread(database, item.itemid); -#else update_triggers(item.itemid); -#endif } else if(res == NOTSUPPORTED) { zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s]", item.key, item.host ); zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", item.key, item.host ); -#ifdef ZABBIX_THREADS - DBupdate_item_status_to_notsupported_thread(database, item.itemid, error); -#else DBupdate_item_status_to_notsupported(item.itemid, error); -#endif /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ if(HOST_AVAILABLE_TRUE != item.host_available) { item.host_available=HOST_AVAILABLE_TRUE; zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", item.host ); zabbix_syslog("Enabling host [%s]", item.host ); -#ifdef ZABBIX_THREADS - DBupdate_host_availability_thread(database, item.hostid,HOST_AVAILABLE_TRUE,now,error); - update_key_status_thread(database, item.hostid,HOST_STATUS_MONITORED); -#else DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,error); update_key_status(item.hostid,HOST_STATUS_MONITORED); -#endif break; } @@ -690,29 +489,16 @@ int get_values(void) { zabbix_log( LOG_LEVEL_WARNING, "Host [%s] will be checked after [%d] seconds", item.host, DELAY_ON_NETWORK_FAILURE ); zabbix_syslog("Host [%s] will be checked after [%d] seconds", item.host, DELAY_ON_NETWORK_FAILURE ); -#ifdef ZABBIX_THREADS - DBupdate_host_availability_thread(database, item.hostid,HOST_AVAILABLE_FALSE,now,error); - update_key_status_thread(database,item.hostid,HOST_AVAILABLE_FALSE); -#else DBupdate_host_availability(item.hostid,HOST_AVAILABLE_FALSE,now,error); update_key_status(item.hostid,HOST_AVAILABLE_FALSE); -#endif snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=3 where hostid=%d", item.hostid); -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif } else { snprintf(sql,sizeof(sql)-1,"update hosts set network_errors=%d where hostid=%d", item.host_network_errors, item.hostid); -#ifdef ZABBIX_THREADS - DBexecute_thread(database, sql); -#else DBexecute(sql); -#endif } break; @@ -738,11 +524,7 @@ int get_values(void) return SUCCEED; } -#ifdef ZABBIX_THREADS -void *main_nodata_loop() -#else int main_nodata_loop() -#endif { char sql[MAX_STRING_LEN]; int i,now; @@ -750,9 +532,6 @@ int main_nodata_loop() int itemid,functionid; char *parameter; -#ifdef ZABBIX_THREADS - DB_HANDLE database; -#endif DB_RESULT *result; for(;;) @@ -761,11 +540,7 @@ int main_nodata_loop() setproctitle("updating nodata() functions"); #endif -#ifdef ZABBIX_THREADS - DBconnect_thread(&database); -#else DBconnect(); -#endif now=time(NULL); #ifdef HAVE_PGSQL @@ -774,11 +549,7 @@ int main_nodata_loop() snprintf(sql,sizeof(sql)-1,"select distinct f.itemid,f.functionid,f.parameter from functions f, items i,hosts h where h.hostid=i.hostid and ((h.status=%d and h.available!=%d) or (h.status=%d and h.available=%d and h.disable_until<%d)) and i.itemid=f.itemid and f.function='nodata' and i.lastclock+f.parameter<=%d and i.status=%d and i.type=%d and (f.lastvalue<>1 or f.lastvalue is NULL)", HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, HOST_STATUS_MONITORED, HOST_AVAILABLE_FALSE, now, now, ITEM_STATUS_ACTIVE, ITEM_TYPE_TRAPPER); #endif -#ifdef ZABBIX_THREADS - result = DBselect_thread(&database, sql); -#else result = DBselect(sql); -#endif for(i=0;i<DBnum_rows(result);i++) { @@ -787,25 +558,13 @@ int main_nodata_loop() parameter=DBget_field(result,i,2); snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='1' where itemid=%d and function='nodata' and parameter='%s'" , itemid, parameter ); -#ifdef ZABBIX_THREADS - DBexecute_thread(&database, sql); -#else DBexecute(sql); -#endif -#ifdef ZABBIX_THREADS - update_triggers_thread(&database, itemid); -#else update_triggers(itemid); -#endif } DBfree_result(result); -#ifdef ZABBIX_THREADS - DBclose_thread(&database); -#else DBclose(); -#endif #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("sleeping for 30 sec"); @@ -814,171 +573,12 @@ int main_nodata_loop() } } -#ifdef ZABBIX_THREADS -void *main_poller_loop() -{ - int i, num, ret, end, unprocessed_flag, processed; - int itemid=0; - - DB_ITEM item; - - zabbix_log( LOG_LEVEL_DEBUG, "In main_poller_loop()"); - for(;;) - { -// zabbix_log( LOG_LEVEL_WARNING, "poller: waiting for state 1..%d [poll values from agents] State [%d]", (CONFIG_SUCKERD_FORKS-4)-1, state); - zabbix_log( LOG_LEVEL_WARNING, "poller: waiting for state 1 [poll values from agents] State [%d]", state); - pthread_mutex_lock (&result_mutex); - while (state != 1) -// while ( (state != 1) && (answer_count == request_count )) -// while ( (state < 1) || (state>(CONFIG_SUCKERD_FORKS-4)) ) - { - pthread_cond_wait(&result_cv, &result_mutex); - } - pthread_mutex_unlock (&result_mutex); -// Do work till there are unprocessed requests - for(;;) - { - pthread_mutex_lock (&poller_mutex); - unprocessed_flag=0; - processed=0; - for(i=0;i<request_count;i++) - { -// if(requests[i].status == 1) -// zabbix_log( LOG_LEVEL_WARNING, "poller: looking for status [0] host [%s] key [%s] status [%d]", DBget_field(shared_result,i,2), DBget_field(shared_result,i,1), requests[i].status); - num = i; - if(requests[i].status == 0) - { -// zabbix_log( LOG_LEVEL_WARNING, "poller: itemid [%d]", atoi(DBget_field(shared_result,i,0)) ); - if(requests[i].status!=0) - zabbix_log( LOG_LEVEL_WARNING, "poller: ERROR status [%d] must be [0] host [%s] key [%s]", requests[num].status, item.host, item.key); - requests[i].status = 1; - /* we should retrieve info from shared_result here */ - itemid=atoi(DBget_field(shared_result,i,0)); - unprocessed_flag=1; - break; - } - else - { - processed++; - } - } - pthread_mutex_unlock (&poller_mutex); - -/* zabbix_log( LOG_LEVEL_WARNING, "poller: number of already retrieved items [%d] total [%d]", i, request_count);*/ - - /* 0 5 6 ? */ -// zabbix_log( LOG_LEVEL_WARNING, "poller: num [%d] answer count [%d] request count [%d]", num, answer_count, request_count); -// if(processed < request_count-1) - if( (num < request_count) && (unprocessed_flag == 1)) - { - /* do logic */ -// zabbix_log( LOG_LEVEL_WARNING, "poller: processing host [%s] key [%s] status [%d]", DBget_field(shared_result,num,2), DBget_field(shared_result,num,1), requests[num].status); - - item.key=DBget_field(shared_result,num,1); - item.host=DBget_field(shared_result,num,2); - item.port=atoi(DBget_field(shared_result,num,3)); - item.type=atoi(DBget_field(shared_result,num,7)); - item.snmp_community=DBget_field(shared_result,num,8); - item.snmp_oid=DBget_field(shared_result,num,9); - item.useip=atoi(DBget_field(shared_result,num,10)); - item.ip=DBget_field(shared_result,num,11); - item.value_type=atoi(DBget_field(shared_result,num,17)); - item.snmp_port=atoi(DBget_field(shared_result,num,19)); - - if(requests[num].status!=1) - zabbix_log( LOG_LEVEL_WARNING, "poller: ERROR status [%d] must be [1] host [%s] key [%s]", requests[num].status, item.host, item.key); - ret = get_value(&requests[num].value,requests[num].value_str,&item); - /* end of do logic */ - - pthread_mutex_lock (&poller_mutex); - requests[num].ret = ret; - if(requests[num].status!=1) - { - zabbix_log( LOG_LEVEL_WARNING, "poller: ERROR2 status [%d] must be [1] host [%s] key [%s] num [%d] processed [%d] request_count [%d]", requests[num].status, item.host, item.key, num, processed, request_count); - zabbix_log( LOG_LEVEL_WARNING, "poller: ERROR2 host2 [%s] item.host [%s]", DBget_field(shared_result,num,2), item.host); - } - requests[num].status = 2; - answer_count++; -// zabbix_log( LOG_LEVEL_WARNING, "poller: answer count [%d] request count [%d]", answer_count, request_count); - pthread_mutex_unlock (&poller_mutex); - -// zabbix_log( LOG_LEVEL_WARNING, "poller: processed [%d] request count [%d]", processed, request_count); - } - -// if(num == request_count-1) - pthread_mutex_lock (&poller_mutex); -// zabbix_log( LOG_LEVEL_WARNING, "poller: num [%d] answer count [%d] request count [%d] processed [%d]", num, answer_count, request_count, processed); - if(processed == request_count) end = 1; - else end = 0; - pthread_mutex_unlock (&poller_mutex); - - if(end == 1) - { - break; - } - - } - - pthread_mutex_lock (&result_mutex); -// if( (state >= 1) && (state< CONFIG_SUCKERD_FORKS-4) ) - -/* if(state == 1) - { - state = 2; - zabbix_log( LOG_LEVEL_WARNING, "poller: broadcast state [%d]", state); - pthread_cond_broadcast(&result_cv); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "poller: do not broadcast state [2]"); - } -*/ - state = 2; - zabbix_log( LOG_LEVEL_WARNING, "poller: broadcast state [%d]", state); - pthread_cond_broadcast(&result_cv); - pthread_mutex_unlock (&result_mutex); - -/* pthread_mutex_lock (&result_mutex); -// if( (answer_count == request_count) && (state == 1)) - if( answer_count == request_count) - { - state = 2; - zabbix_log( LOG_LEVEL_WARNING, "poller: broadcast state [%d]", state); - pthread_cond_signal(&result_cv); -// pthread_cond_broadcast(&result_cv); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "poller: do not broadcast state [2]"); - } - pthread_mutex_unlock (&result_mutex);*/ - } - sleep(100000); -} -#endif - -#ifdef ZABBIX_THREADS -void *main_sucker_loop() -#else int main_sucker_loop() -#endif { int now; int nextcheck,sleeptime; -#ifdef ZABBIX_THREADS - DB_HANDLE database; -#endif - -#ifdef ZABBIX_THREADS - my_thread_init(); -#endif - -#ifdef ZABBIX_THREADS - DBconnect_thread(&database); -#else DBconnect(); -#endif for(;;) { @@ -986,19 +586,11 @@ int main_sucker_loop() setproctitle("sucker [getting values]"); #endif now=time(NULL); -#ifdef ZABBIX_THREADS - get_values(&database); -#else get_values(); -#endif zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while updating values", (int)time(NULL)-now ); -#ifdef ZABBIX_THREADS - nextcheck=get_minnextcheck_thread(&database,now); -#else nextcheck=get_minnextcheck(now); -#endif zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) ); if( FAIL == nextcheck) @@ -1034,55 +626,6 @@ int main_sucker_loop() } } -#ifdef ZABBIX_THREADS - -#define NUM_THREADS 100 -void init_threads(void) -{ - pthread_t threads[NUM_THREADS]; - int rc, i; - for(i=0;i < CONFIG_SUCKERD_FORKS;i++){ - zabbix_log( LOG_LEVEL_WARNING, "Creating thread %d", i); - if(i==0) - { - rc = pthread_create(&threads[i], NULL, main_housekeeper_loop, (void *)i); - } - else if(i==1) - { - rc = pthread_create(&threads[i], NULL, main_alerter_loop, (void *)i); - } - else if(i==2) - { - rc = pthread_create(&threads[i], NULL, main_nodata_loop, (void *)i); -// rc = pthread_create(&threads[i], NULL, main_housekeeper_loop, (void *)i); - } - else if(i==3) - { - rc = pthread_create(&threads[i], NULL, main_pinger_loop, (void *)i); -// rc = pthread_create(&threads[i], NULL, main_housekeeper_loop, (void *)i); - } - else if(i==4) - { -#ifdef HAVE_SNMP - init_snmp("zabbix_server"); -#endif - rc = pthread_create(&threads[i], NULL, main_sucker_loop, (void *)i); - } - else - { - rc = pthread_create(&threads[i], NULL, main_poller_loop, (void *)i); - } - - if (rc){ - zabbix_log( LOG_LEVEL_ERR, "ERROR from pthread_create() [%m]"); - exit(-1); - } - } - pthread_exit(NULL); -} -#endif - - int tcp_listen(const char *host, int port, socklen_t *addrlenp) { int sockfd; @@ -1198,16 +741,6 @@ int main(int argc, char **argv) DBclose(); pids=calloc(CONFIG_SUCKERD_FORKS+CONFIG_TRAPPERD_FORKS-1,sizeof(pid_t)); -#ifdef ZABBIX_THREADS - my_init(); - pthread_mutex_init(&poller_mutex, NULL); - pthread_mutex_init(&result_mutex, NULL); - pthread_cond_init(&result_cv, NULL); - init_threads(); - for(;;) sleep(100000); - return 0; -#endif - for(i=1;i<CONFIG_SUCKERD_FORKS;i++) { if((pid = fork()) == 0) diff --git a/src/zabbix_server/trapper.c b/src/zabbix_server/trapper.c index ef1e07f6..cc199488 100644 --- a/src/zabbix_server/trapper.c +++ b/src/zabbix_server/trapper.c @@ -45,10 +45,6 @@ #include "log.h" #include "zlog.h" -#ifdef ZABBIX_THREADS - #include <pthread.h> -#endif - #include "common.h" #include "functions.h" #include "expression.h" diff --git a/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/mysql/patch.sql b/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/mysql/patch.sql index fdb35617..778fdb9d 100644 --- a/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/mysql/patch.sql +++ b/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/mysql/patch.sql @@ -10,3 +10,8 @@ CREATE TABLE history_log ( PRIMARY KEY (id), KEY itemidclock (itemid, clock) ) type=InnoDB; + + +alter table media add period varchar(100) DEFAULT '1-7,00:00-23:59' NOT NULL; +alter table screens_items add colspan int(4) DEFAULT '0' NOT NULL; +alter table items add lastlogsize int(4) DEFAULT '0' NOT NULL; diff --git a/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/postgresql/patch.sql b/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/postgresql/patch.sql index 0e85aff2..cf9b1cce 100644 --- a/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/postgresql/patch.sql +++ b/upgrades/dbpatches/1.1alpha9_to_1.1alpha10/postgresql/patch.sql @@ -12,3 +12,7 @@ CREATE TABLE history_log ( ); CREATE INDEX history_log_i_c on history_str (itemid, clock); + +alter table media add period varchar(100) DEFAULT '1-7,00:00-23:59' NOT NULL; +alter table screens_items add colspan int4 DEFAULT '0' NOT NULL; +alter table items add lastlogsize int4 DEFAULT '0' NOT NULL; |