diff options
| author | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-02-10 12:53:34 +0000 |
|---|---|---|
| committer | osmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-02-10 12:53:34 +0000 |
| commit | f54860dfdd8d24de1dc26a530d95a23343756dc2 (patch) | |
| tree | 76234c5a861862aee2170b41cf7a517e82633e93 /frontends/php/include | |
| parent | 455a64dfe19d7700fa1fe10edecb1ea82fa5dcce (diff) | |
| download | zabbix-f54860dfdd8d24de1dc26a530d95a23343756dc2.tar.gz zabbix-f54860dfdd8d24de1dc26a530d95a23343756dc2.tar.xz zabbix-f54860dfdd8d24de1dc26a530d95a23343756dc2.zip | |
- improved Templates logic (Eugene)
- speed improvement for proc.num of Tru64 (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@2631 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php/include')
| -rw-r--r-- | frontends/php/include/config.inc.php | 204 | ||||
| -rw-r--r-- | frontends/php/include/db.inc.php | 9 | ||||
| -rw-r--r-- | frontends/php/include/forms.inc.php | 42 | ||||
| -rw-r--r-- | frontends/php/include/graphs.inc.php | 24 | ||||
| -rw-r--r-- | frontends/php/include/hosts.inc.php | 261 | ||||
| -rw-r--r-- | frontends/php/include/html.inc.php | 2 | ||||
| -rw-r--r-- | frontends/php/include/items.inc.php | 281 | ||||
| -rw-r--r-- | frontends/php/include/locales/en_gb.inc.php | 3 | ||||
| -rw-r--r-- | frontends/php/include/profiles.inc.php | 43 | ||||
| -rw-r--r-- | frontends/php/include/services.inc.php | 6 |
10 files changed, 474 insertions, 401 deletions
diff --git a/frontends/php/include/config.inc.php b/frontends/php/include/config.inc.php index 6956ff0c..59c8bbc9 100644 --- a/frontends/php/include/config.inc.php +++ b/frontends/php/include/config.inc.php @@ -278,10 +278,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! function get_template_permission_str($num) { - $str=" "; - if(($num&1)==1) $str=$str.S_ADD." "; - if(($num&2)==2) $str=$str.S_UPDATE." "; - if(($num&4)==4) $str=$str.S_DELETE." "; + $str=SPACE; + if(($num&1)==1) $str=$str.S_ADD.SPACE; + if(($num&2)==2) $str=$str.S_UPDATE.SPACE; + if(($num&4)==4) $str=$str.S_DELETE.SPACE; return $str; } @@ -1227,7 +1227,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! if(($sub["url"]=="screenconf.php")&&!check_anyright("Screen","U")) continue; if(($sub["url"]=="services.php")&&!check_anyright("Service","U")) continue; - echo "<a href=\"".$sub["url"]."\" class=\"highlight\">".$sub["label"]."</a><span class=\"divider\"> | </span>\n"; + echo "<a href=\"".$sub["url"]."\" class=\"highlight\">".$sub["label"]."</a><span class=\"divider\">".SPACE.SPACE."|".SPACE."</span>\n"; } ?> </b></td></tr> @@ -1600,178 +1600,6 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! } } - # Add host-template linkage - function add_template_linkage($hostid,$templateid,$items,$triggers,$graphs) - { - $sql="insert into hosts_templates (hostid,templateid,items,triggers,graphs) values ($hostid,$templateid,$items,$triggers,$graphs)"; - return DBexecute($sql); - } - - # Update host-template linkage - function update_template_linkage($hosttemplateid,$hostid,$templateid,$items,$triggers,$graphs) - { - $sql="update hosts_templates set hostid=$hostid,templateid=$templateid,items=$items,triggers=$triggers,graphs=$graphs where hosttemplateid=$hosttemplateid"; - return DBexecute($sql); - } - - # Delete host-template linkage - function delete_template_linkage($hosttemplateid) - { - $sql="delete from hosts_templates where hosttemplateid=$hosttemplateid"; - return DBexecute($sql); - } - - function add_group_to_host($hostid,$newgroup) - { - $sql="insert into groups (groupid,name) values (NULL,".zbx_dbstr($newgroup).")"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - - $groupid=DBinsert_id($result,"groupd","groupid"); - - $sql="insert into hosts_groups (hostid,groupid) values ($hostid,$groupid)"; - $result=DBexecute($sql); - - return $result; - } - - function update_host_groups_by_groupid($groupid,$hosts) - { - $count=count($hosts); - - $sql="delete from hosts_groups where groupid=$groupid"; - DBexecute($sql); - - for($i=0;$i<$count;$i++) - { - $sql="insert into hosts_groups (hostid,groupid) values (".$hosts[$i].",$groupid)"; - DBexecute($sql); - } - } - - function update_host_groups($hostid,$groups) - { - $count=count($groups); - - $sql="delete from hosts_groups where hostid=$hostid"; - DBexecute($sql); - - for($i=0;$i<$count;$i++) - { - $sql="insert into hosts_groups (hostid,groupid) values ($hostid,".$groups[$i].")"; - DBexecute($sql); - } - } - - function add_host_group($name,$hosts) - { -// if(!check_right("Host","A",0)) -// { -// error("Insufficient permissions"); -// return 0; -// } - - $sql="select * from groups where name=".zbx_dbstr($name); - $result=DBexecute($sql); - if(DBnum_rows($result)>0) - { - error("Group '$name' already exists"); - return 0; - } - - $sql="insert into groups (name) values (".zbx_dbstr($name).")"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - - $groupid=DBinsert_id($result,"groups","groupid"); - - update_host_groups_by_groupid($groupid,$hosts); - - return $result; - } - - function update_host_group($groupid,$name,$users) - { -// if(!check_right("Host","U",0)) -// { -// error("Insufficient permissions"); -// return 0; -// } - - $sql="select * from groups where name=".zbx_dbstr($name)." and groupid<>$groupid"; - $result=DBexecute($sql); - if(DBnum_rows($result)>0) - { - error("Group '$name' already exists"); - return 0; - } - - $sql="update groups set name=".zbx_dbstr($name)." where groupid=$groupid"; - $result=DBexecute($sql); - if(!$result) - { - return $result; - } - - update_host_groups_by_groupid($groupid,$users); - - return $result; - } - - # Sync host with hard-linked templates - function sync_host_with_templates($hostid) - { - $sql="select * from hosts_templates where hostid=$hostid"; - $result=DBselect($sql); - while($row=DBfetch($result)) - { - sync_host_with_template($hostid,$row["templateid"],$row["items"],$row["triggers"], - $row["graphs"]); - } - } - - # Sync host with hard-linked template - function sync_host_with_template($hostid,$templateid,$items,$triggers,$graphs) - { - if(!isset($templateid)||($templateid==0)) - { - error("Select template first"); - return 0; - } - - // Sync items - $sql="select itemid from items where hostid=$templateid"; - $result=DBselect($sql); - while($row=DBfetch($result)) - { - add_item_to_linked_hosts($row["itemid"],$hostid); - } - - // Sync triggers - $sql="select distinct t.triggerid from hosts h, items i,triggers t,functions f where h.hostid=$templateid and h.hostid=i.hostid and t.triggerid=f.triggerid and i.itemid=f.itemid"; - $result=DBselect($sql); - while($row=DBfetch($result)) - { - add_trigger_to_linked_hosts($row["triggerid"],$hostid); - } - - // Sync graphs - $sql="select distinct gi.gitemid from graphs g,graphs_items gi,items i where i.itemid=gi.itemid and i.hostid=$templateid and g.graphid=gi.graphid"; - $result=DBselect($sql); - while($row=DBfetch($result)) - { - add_graph_item_to_linked_hosts($row["gitemid"],$hostid); - } - - return TRUE; - } - # Delete Media definition by mediatypeid function delete_media_by_mediatypeid($mediatypeid) @@ -2462,8 +2290,10 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! S_ZABBIX_VER.SPACE.S_COPYRIGHT_BY.SPACE.S_SIA_ZABBIX, "http://www.zabbix.com", "highlight"), "page_footer_l"), - new CCol("<span class='divider'> | </span>". - S_CONNECTED_AS." ".$USER_DETAILS["alias"], + new CCol(array( + new CSpan(SPACE.SPACE."|".SPACE.SPACE,"divider"), + S_CONNECTED_AS.SPACE.$USER_DETAILS["alias"] + ), "page_footer_r") )); $table->Show(); @@ -2919,7 +2749,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! echo "<TD ALIGN=LEFT>"; echo "<div align=left>"; - echo "<b>".S_PERIOD.":</b> "; + echo "<b>".S_PERIOD.":</b>".SPACE; $hour=3600; @@ -2944,14 +2774,14 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! $tmp=$_REQUEST["period"]+$sec; echo("<A HREF=\"charts.php?period=$tmp".url_param($resource).url_param("stime").url_param("from").url_param("keep").url_param("fullscreen")."\">+</A>"); - echo "] "; + echo "]".SPACE; } echo("</div>"); echo "</TD>"; echo "<TD BGCOLOR=#FFFFFF WIDTH=15% ALIGN=RIGHT>"; - echo "<b>".nbsp(S_KEEP_PERIOD).":</b> "; + echo "<b>".nbsp(S_KEEP_PERIOD).":</b>".SPACE; if($_REQUEST["keep"] == 1) { echo("[<A HREF=\"charts.php?keep=0".url_param($resource).url_param("from").url_param("period").url_param("fullscreen")."\">".S_ON_C."</a>]"); @@ -2967,7 +2797,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! if(isset($_REQUEST["stime"])) { echo "<div align=left>" ; - echo "<b>".S_MOVE.":</b> " ; + echo "<b>".S_MOVE.":</b>".SPACE; $day=24; // $a already defined @@ -2991,14 +2821,14 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! $tmp=date("YmdHi",$tmp); echo("<A HREF=\"charts.php?stime=$tmp".url_param($resource).url_param("period").url_param("keep").url_param("fullscreen")."\">+</A>"); - echo "] "; + echo "]".SPACE; } echo("</div>"); } else { echo "<div align=left>"; - echo "<b>".S_MOVE.":</b> "; + echo "<b>".S_MOVE.":</b>".SPACE; $day=24; // $a already defined @@ -3022,7 +2852,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! echo "+"; } - echo "] "; + echo "]".SPACE; } echo("</div>"); } @@ -3040,7 +2870,7 @@ function SDI($msg="SDI") { echo "DEBUG INFO: $msg ".BR; } # DEBUG INFO!!! { echo "<input name=\"stime\" class=\"biginput\" value=\"yyyymmddhhmm\" size=12>"; } - echo " "; + echo SPACE; echo "<input class=\"button\" type=\"submit\" name=\"action\" value=\"go\">"; echo "</form>"; // echo("</div>"); diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php index 7d9c1cf4..8f6c2b68 100644 --- a/frontends/php/include/db.inc.php +++ b/frontends/php/include/db.inc.php @@ -79,7 +79,7 @@ { global $DB,$DB_TYPE; -# echo $query."<br>"; + $result = FALSE; if($DB_TYPE == "MYSQL") { @@ -90,14 +90,15 @@ error("SQL error: ".mysql_error()); error("Query: $query"); } - return $result; } if($DB_TYPE == "POSTGRESQL") { $result=pg_exec($DB,$query); - return $result; } - return FALSE; + +//SDI("DBexecute($query) = '".$result."'"); + + return $result; } function DBfetch($result) diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 18e767f6..e2d9725f 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -318,7 +318,9 @@ if(isset($_REQUEST["groupid"])) $frmItem->AddVar("groupid",$_REQUEST["groupid"]); - $description = get_request("description" ,""); + $frmItem->AddVar("hostid",$_REQUEST["hostid"]); + + $description = get_request("description" ,"new"); $key = get_request("key" ,""); $host = get_request("host", NULL); $delay = get_request("delay" ,30); @@ -332,7 +334,6 @@ $trapper_hosts = get_request("trapper_hosts" ,""); $units = get_request("units" ,''); $multiplier = get_request("multiplier" ,0); - $hostid = get_request("hostid" ,0); $delta = get_request("delta" ,0); $trends = get_request("trends" ,365); @@ -347,8 +348,8 @@ $add_groupid = get_request("add_groupid" ,get_request("groupid",0)); - if(is_null($host)&&$hostid>0){ - $host_info = get_host_by_hostid($hostid); + if(is_null($host)){ + $host_info = get_host_by_hostid($_REQUEST["hostid"]); $host = $host_info["host"]; } @@ -364,8 +365,6 @@ " from items i,hosts h where i.itemid=".$_REQUEST["itemid"]. " and h.hostid=i.hostid"); $row=DBfetch($result); - - $frmItem->SetTitle(S_ITEM." \"". $row["description"]."\""); } if(isset($_REQUEST["itemid"]) && !isset($_REQUEST["form_refresh"])) @@ -396,16 +395,14 @@ $formula = $row["formula"]; $logtimefmt = $row["logtimefmt"]; } + if(isset($_REQUEST["itemid"])) { + $frmItem->SetTitle(S_ITEM." '$host:".$row["description"]."'"); + } else { + $frmItem->SetTitle(S_ITEM." '$host:$description'"); + } $frmItem->AddRow(S_DESCRIPTION, new CTextBox("description",$description,40)); - $frmItem->AddVar("hostid",$hostid); - $frmItem->AddRow(S_HOST, array( - new CTextBox("host",$host,30,NULL,'yes'), - new CButton("btn1","Select","return PopUp('popup.php?form=".$frmItem->GetName(). - "&field1=hostid&field2=host','host','width=450,height=450,". - "resizable=1,scrollbars=1');","T") - )); $cmbType = new CComboBox("type",$type,"submit()"); $cmbType->AddItem(ITEM_TYPE_ZABBIX,'Zabbix agent'); @@ -1188,7 +1185,7 @@ while($trigger = DBfetch($triggers)) { $cmbCondVal->AddItem($trigger["triggerid"], - $trigger["host"].": ".$trigger["description"]); + $trigger["host"].":".SPACE.$trigger["description"]); } array_push($rowCondition,$cmbCondVal); } @@ -1735,7 +1732,6 @@ $groups= get_request("groups",array()); $newgroup = get_request("newgroup",""); - $host_templateid= get_request("host_templateid",""); $host = get_request("host", ""); $port = get_request("port", get_profile("HOST_PORT",10050)); @@ -1757,6 +1753,8 @@ $location = get_request("location",""); $notes = get_request("notes",""); + $templateid= get_request("templateid",0); + if(isset($_REQUEST["hostid"])){ $db_host=get_host_by_hostid($_REQUEST["hostid"]); $frm_title = S_HOST.SPACE."\"".$db_host["host"]."\""; @@ -1771,6 +1769,8 @@ $status = $db_host["status"]; $useip = $db_host["useip"]==1 ? 'yes' : 'no'; $ip = $db_host["ip"]; + + $templateid = $db_host["templateid"]; // add groups $db_groups=DBselect("select groupid from hosts_groups where hostid=".$_REQUEST["hostid"]); while($db_group=DBfetch($db_groups)){ @@ -1845,14 +1845,15 @@ $cmbStatus->AddItem(HOST_STATUS_NOT_MONITORED, S_NOT_MONITORED); $frmHost->AddRow(S_STATUS,$cmbStatus); - $cmbHosts = new CComboBox("host_templateid",$host_templateid); + $cmbHosts = new CComboBox("templateid",$templateid); $cmbHosts->AddItem(0,"..."); - $hosts=DBselect("select host,hostid from hosts where status not in (".HOST_STATUS_DELETED.") order by host"); + $hosts=DBselect("select host,hostid from hosts where status not in (".HOST_STATUS_DELETED.")". + " order by host"); while($host=DBfetch($hosts)) { $cmbHosts->AddItem($host["hostid"],$host["host"]); } - $frmHost->AddRow(S_USE_TEMPLATES_OF_THIS_HOST,$cmbHosts); + $frmHost->AddRow(S_LINK_WITH_HOST,$cmbHosts); $frmHost->AddRow(S_USE_PROFILE,new CCheckBox("useprofile",$useprofile,NULL,"submit()")); if($useprofile=="yes") @@ -1892,12 +1893,13 @@ $frmHost->AddItemToBottomRow(SPACE); $frmHost->AddItemToBottomRow( new CButtonDelete(S_DELETE_SELECTED_HOST_Q, - url_param("form").url_param("config").url_param("hostid") + url_param("form").url_param("config").url_param("hostid"). + url_param("groupid") ) ); } $frmHost->AddItemToBottomRow(SPACE); - $frmHost->AddItemToBottomRow(new CButtonCancel(url_param("config"))); + $frmHost->AddItemToBottomRow(new CButtonCancel(url_param("config").url_param("groupid"))); $frmHost->Show(); } diff --git a/frontends/php/include/graphs.inc.php b/frontends/php/include/graphs.inc.php index 495d6c46..0963cbbb 100644 --- a/frontends/php/include/graphs.inc.php +++ b/frontends/php/include/graphs.inc.php @@ -495,7 +495,7 @@ function navigation_bar($url) { $h1=S_NAVIGATE; - $h2=S_PERIOD." "; + $h2=S_PERIOD.SPACE; $h2=$h2."<select class=\"biginput\" name=\"period\" onChange=\"submit()\">"; $h2=$h2.form_select("period",3600,"1h"); $h2=$h2.form_select("period",2*3600,"2h"); @@ -525,7 +525,7 @@ $h2=$h2.form_select("inc",31*24*3600,"+month"); $h2=$h2.form_select("inc",365*24*3600,"+year"); $h2=$h2."</select>"; - $h2=$h2." ".S_MOVE." "; + $h2=$h2.SPACE.S_MOVE.SPACE; $h2=$h2."<select class=\"biginput\" name=\"left\" onChange=\"submit()\">"; $h2=$h2.form_select("left",0,S_LEFT_DIR); $h2=$h2.form_select("left",1,"-1h"); @@ -544,9 +544,9 @@ $h2=$h2.form_select("right",31*24,"+month"); $h2=$h2.form_select("right",365*24,"+year"); $h2=$h2."</select>"; - $h2=$h2." "; + $h2=$h2.SPACE; $h2=$h2."<input name=\"stime\" size=18 class=\"biginput\" value=\"yyyymmddhhmm\" size=12>"; - $h2=$h2." "; + $h2=$h2.SPACE; $h2=$h2."<input class=\"button\" type=\"submit\" name=\"action\" value=\"go\">"; $h2=$h2."<input class=\"button\" type=\"submit\" name=\"reset\" value=\"reset\">"; @@ -584,7 +584,7 @@ echo "<TD ALIGN=LEFT>"; echo "<div align=left>"; - echo "<b>".S_PERIOD.":</b> "; + echo "<b>".S_PERIOD.":</b>".SPACE; $hour=3600; @@ -609,14 +609,14 @@ $tmp=$_REQUEST["period"]+$sec; echo("<A HREF=\"$url?period=$tmp".url_param("graphid").url_param("stime").url_param("from").url_param("keep").url_param("fullscreen")."\">+</A>"); - echo "] "; + echo "]".SPACE; } echo("</div>"); echo "</TD>"; echo "<TD BGCOLOR=#FFFFFF WIDTH=15% ALIGN=RIGHT>"; - echo "<b>".nbsp(S_KEEP_PERIOD).":</b> "; + echo "<b>".nbsp(S_KEEP_PERIOD).":</b>".SPACE; if($_REQUEST["keep"] == 1) { echo("[<A HREF=\"$url?keep=0".url_param("graphid").url_param("from").url_param("period").url_param("fullscreen")."\">".S_ON_C."</a>]"); @@ -632,7 +632,7 @@ if(isset($_REQUEST["stime"])) { echo "<div align=left>" ; - echo "<b>".S_MOVE.":</b> " ; + echo "<b>".S_MOVE.":</b>".SPACE; $day=24; // $a already defined @@ -656,14 +656,14 @@ $tmp=date("YmdHi",$tmp); echo("<A HREF=\"$url?stime=$tmp".url_param("graphid").url_param("period").url_param("keep").url_param("fullscreen")."\">+</A>"); - echo "] "; + echo "]".SPACE; } echo("</div>"); } else { echo "<div align=left>"; - echo "<b>".S_MOVE.":</b> "; + echo "<b>".S_MOVE.":</b>".SPACE; $day=24; // $a already defined @@ -687,7 +687,7 @@ echo "+"; } - echo "] "; + echo "]".SPACE; } echo("</div>"); } @@ -704,7 +704,7 @@ { echo "<input name=\"stime\" class=\"biginput\" value=\"yyyymmddhhmm\" size=12>"; } - echo " "; + echo SPACE; echo "<input class=\"button\" type=\"submit\" name=\"action\" value=\"go\">"; echo "</form>"; echo "</TD>"; diff --git a/frontends/php/include/hosts.inc.php b/frontends/php/include/hosts.inc.php index c874c318..3a547d46 100644 --- a/frontends/php/include/hosts.inc.php +++ b/frontends/php/include/hosts.inc.php @@ -19,122 +19,234 @@ **/ ?> <?php - # Add Host definition - function add_host($host,$port,$status,$useip,$ip,$host_templateid,$newgroup,$groups) +/* HOST GROUP functions */ + function add_host_to_group($hostid, $groupid) { - if(!check_right("Host","A",0)) - { - error("Insufficient permissions"); - return 0; + if(!is_numeric($hostid) || !is_numeric($groupid)){ + error("incorrect parameters for 'add_host_to_group'"); + return FALSE; } - - if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, $arr)) - { - error("Hostname should contain 0-9a-zA-Z_.- characters only"); - return 0; + return DBexecute("insert into hosts_groups (hostid,groupid) values ($hostid,$groupid)"); + } + function db_save_group($name,$groupid=NULL) + { + if(!is_string($name)){ + error("incorrect parameters for 'db_save_group'"); + return FALSE; } - - $sql="select * from hosts where host=".zbx_dbstr($host); - $result=DBexecute($sql); + + if($groupid==NULL) + $result = DBexecute("select * from groups where name=".zbx_dbstr($name)); + else + $result = DBexecute("select * from groups where name=".zbx_dbstr($name). + " and groupid<>$groupid"); + if(DBnum_rows($result)>0) { - error("Host '$host' already exists"); - return 0; - } - - if($useip=="on" || $useip=="yes" || $useip==1) - { - $useip=1; + error("Group '$name' already exists"); + return FALSE; } + if($groupid==NULL) + return DBexecute("insert into groups (name) values (".zbx_dbstr($name).")"); else - { - $useip=0; - } + return DBexecute("update groups set name=".zbx_dbstr($name)." where groupid=$groupid"); + } + + function add_group_to_host($hostid,$newgroup="") + { + if($newgroup == "" || $newgroup == NULL) + return TRUE; - $sql="insert into hosts (host,port,status,useip,ip,disable_until,available) values (".zbx_dbstr($host).",$port,$status,$useip,".zbx_dbstr($ip).",0,".HOST_AVAILABLE_UNKNOWN.")"; - $result=DBexecute($sql); + $result = db_save_group($newgroup); if(!$result) - { return $result; - } - $hostid=DBinsert_id($result,"hosts","hostid"); + $groupid = DBinsert_id($result,"groupd","groupid"); - if($host_templateid != 0) - { - add_templates_to_host($hostid,$host_templateid); - sync_host_with_templates($hostid); - } - if($groups != "") + return add_host_to_group($hostid, $groupid); + } + + function update_host_groups_by_groupid($groupid,$hosts=array()) + { + DBexecute("delete from hosts_groups where groupid=$groupid"); + + foreach($hosts as $hostid) { - update_host_groups($hostid,$groups); + add_host_to_group($hostid, $groupid); } - if($newgroup != "") + } + + function update_host_groups($hostid,$groups=array()) + { + DBexecute("delete from hosts_groups where hostid=$hostid"); + + foreach($groups as $groupid) { - add_group_to_host($hostid,$newgroup); + add_host_to_group($hostid, $groupid); } + } - update_profile("HOST_PORT",$port); + function add_host_group($name,$hosts) + { +// if(!check_right("Host","A",0)) +// { +// error("Insufficient permissions"); +// return FLASE; +// } + + $result = db_save_group($name); + if(!$result) + return $result; - return $result; + $groupid = DBinsert_id($result,"groups","groupid"); + + update_host_groups_by_groupid($groupid,$hosts); + + return $groupid; } - function update_host($hostid,$host,$port,$status,$useip,$ip,$newgroup,$groups) + function update_host_group($groupid,$name,$hosts) { - if(!check_right("Host","U",$hostid)) - { - error("Insufficient permissions"); - return 0; - } +// if(!check_right("Host","U",0)) +// { +// error("Insufficient permissions"); +// return 0; +// } - if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host, $arr)) + + $result = db_save_group($name,$groupid); + if(!$result) + return $result; + + update_host_groups_by_groupid($groupid,$hosts); + + return $result; + } + +/* HOST finction */ + function check_circle_host_link($hostid, $templateid) + { + if($templateid <= 0) return FALSE; + if($hostid == $templateid) return TRUE; + $template = get_host_by_hostid($templateid); + if($template["templateid"] > 0) + return check_circle_host_link($hostid, $template["templateid"]); + + return FALSE; + } + + function db_save_host($host,$port,$status,$useip,$ip,$templateid,$hostid=NULL) + { + if (!eregi('^([0-9a-zA-Z\_\.-]+)$', $host)) { error("Hostname should contain 0-9a-zA-Z_.- characters only"); - return 0; + return FALSE; } - $sql="select * from hosts where host=".zbx_dbstr($host)." and hostid<>$hostid"; - $result=DBexecute($sql); + if($hostid==NULL) + $result=DBexecute("select * from hosts where host=".zbx_dbstr($host)); + else + $result=DBexecute("select * from hosts where host=".zbx_dbstr($host). + " and hostid<>$hostid"); + if(DBnum_rows($result)>0) { error("Host '$host' already exists"); - return 0; + return FALSE; } + if($useip=="on" || $useip=="yes" || $useip==1) $useip=1; + else $useip=0; - if($useip=="on" || $useip=="yes" || $useip==1) + if($hostid==NULL) { - $useip=1; + $result = DBexecute("insert into hosts". + " (host,port,status,useip,ip,disable_until,available,templateid)". + " values (".zbx_dbstr($host).",$port,$status,$useip,".zbx_dbstr($ip).",0," + .HOST_AVAILABLE_UNKNOWN.",$templateid)"); } else { - $useip=0; + if(check_circle_host_link($hostid, $templateid)) + { + error("Circle link can't be created"); + return FALSE; + } + + $result = DBexecute("update hosts set host=".zbx_dbstr($host).",". + "port=$port,useip=$useip,ip=".zbx_dbstr($ip).",templateid=$templateid". + " where hostid=$hostid"); + + update_host_status($hostid, $status); } + return $result; + } - $sql="update hosts set host=".zbx_dbstr($host).",port=$port,useip=$useip,ip=".zbx_dbstr($ip)." where hostid=$hostid"; - $result=DBexecute($sql); + function add_host($host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups) + { + if(!check_right("Host","A",0)) + { + error("Insufficient permissions"); + return FALSE; + } + $result = db_save_host($host,$port,$status,$useip,$ip,$templateid); + if(!$result) + return $result; + + $hostid = DBinsert_id($result,"hosts","hostid"); - update_host_status($hostid, $status); update_host_groups($hostid,$groups); - if($newgroup != "") + + add_group_to_host($hostid,$newgroup); + + sync_host_with_templates($hostid); + + update_profile("HOST_PORT",$port); + + return $hostid; + } + + function update_host($hostid,$host,$port,$status,$useip,$ip,$templateid,$newgroup,$groups) + { + if(!check_right("Host","U",$hostid)) { - add_group_to_host($hostid,$newgroup); + error("Insufficient permissions"); + return FALSE; } + + $old_host = get_host_by_hostid($hostid); + + $result = db_save_host($host,$port,$status,$useip,$ip,$templateid,$hostid); + if(!$result) + return $result; + + update_host_groups($hostid, $groups); + + add_group_to_host($hostid,$newgroup); + + if($old_host["templateid"] != $templateid) + sync_host_with_templates($hostid); + return $result; } - # Add templates linked to template host to the host - - function add_templates_to_host($hostid,$host_templateid) +# Sync host with linked template + function sync_host_with_templates($hostid) { - $sql="select * from hosts_templates where hostid=$host_templateid"; - $result=DBselect($sql); - while($row=DBfetch($result)) + $host = get_host_by_hostid($hostid); + delete_template_items_by_hostid($hostid); +// TODO delete_template_triggers_by_hostid($hostid); +// TODO delete_template_hosts_by_hostid($hostid); + + if($host["templateid"] > 0) { - add_template_linkage($hostid,$row["templateid"],$row["items"],$row["triggers"], - $row["graphs"]); +// start host syncing + sync_items_with_template($hostid); +// TODO sync_triggers_with_template($hostid); +// TODO sync_hosts_with_teplates($hostid); +// end host syncing } } @@ -243,13 +355,24 @@ if($status != $old_status) { update_trigger_value_to_unknown_by_hostid($hostid); - $sql="update hosts set status=$status where hostid=$hostid and status!=".HOST_STATUS_DELETED; info("Updated status of host ".$row["host"]); - return DBexecute($sql); + return DBexecute("update hosts set status=$status". + " where hostid=$hostid and status!=".HOST_STATUS_DELETED); } else { return 1; } } + + function get_template_path($hostid) + { + $host = get_host_by_hostid($hostid); + + if ($host["templateid"]==0) + return "/"; + + $tmp_host = get_host_by_hostid($host["templateid"]); + return get_template_path($tmp_host["hostid"]).$tmp_host["host"]."/"; + } ?> diff --git a/frontends/php/include/html.inc.php b/frontends/php/include/html.inc.php index 19751f62..4c888aaa 100644 --- a/frontends/php/include/html.inc.php +++ b/frontends/php/include/html.inc.php @@ -44,7 +44,7 @@ function nbsp($str) { - return str_replace(" "," ",$str);; + return str_replace(" ",SPACE,$str);; } function form_select($var, $value, $label) diff --git a/frontends/php/include/items.inc.php b/frontends/php/include/items.inc.php index cdcdb6c4..8cdd3d26 100644 --- a/frontends/php/include/items.inc.php +++ b/frontends/php/include/items.inc.php @@ -47,11 +47,12 @@ return 0; } - $sql="select i.itemid from hosts_groups hg,items i where hg.groupid=$groupid and i.key_=".zbx_dbstr($item["key_"])." and hg.hostid=i.hostid"; + $sql="select i.itemid from hosts_groups hg,items i". + " where hg.groupid=$groupid and i.key_=".zbx_dbstr($item["key_"]). + " and hg.hostid=i.hostid"; $result=DBexecute($sql); while($row=DBfetch($result)) { - delete_item_from_templates($row["itemid"]); delete_item($row["itemid"]); } return 1; @@ -72,35 +73,30 @@ # Add Item definition - function add_item($description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt) + function add_item( + $description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid, + $value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname, + $snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt, + $templateid=0) { - if(!check_right("Item","A",0)) - { - error("Insufficient permissions"); - return 0; - } - $host=get_host_by_hostid($hostid); - $sql="select count(*) as cnt from items where hostid=$hostid and key_=".zbx_dbstr($key); - $result=DBexecute($sql); - $row = DBfetch($result); - if($row["cnt"]>0) + if(!check_right("Item","A",0)) { - error("An item with the same Key already exists for host ".$host["host"].". The key must be unique."); - return 0; + error("Insufficient permissions to item '".$host["host"].":$key'"); + return FALSE; } if($delay<1) { error("Delay cannot be less than 1 second"); - return 0; + return FALSE; } if( ($snmp_port<1)||($snmp_port>65535)) { error("Invalid SNMP port"); - return 0; + return FALSE; } if($value_type == ITEM_VALUE_TYPE_STR) @@ -108,14 +104,70 @@ $delta=0; } - $sql="insert into items (description,key_,hostid,delay,history,nextcheck,status,type,snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,snmpv3_privpassphrase,formula,trends,logtimefmt) values (".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0,$status,$type,".zbx_dbstr($snmp_community).",".zbx_dbstr($snmp_oid).",$value_type,".zbx_dbstr($trapper_hosts).",$snmp_port,".zbx_dbstr($units).",$multiplier,$delta,".zbx_dbstr($snmpv3_securityname).",$snmpv3_securitylevel,".zbx_dbstr($snmpv3_authpassphrase).",".zbx_dbstr($snmpv3_privpassphrase).",".zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).")"; - $result=DBexecute($sql); - if($result) + $db_items = DBexecute("select itemid,hostid from items". + " where hostid=$hostid and key_=".zbx_dbstr($key)); + if(DBnum_rows($db_items) > 0 && $templateid == 0) + { + error("An item with the same Key already exists for host ".$host["host"].".". + " The key must be unique."); + return FALSE; + } elseif (DBnum_rows($db_items) > 0 && $templateid != 0){ + $db_item = DBfetch($db_items); + + $result = update_item( + $db_item["itemid"], $description, $key, $db_item["hostid"], + $delay, $history, $status, $type, $snmp_community, $snmp_oid, + $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, + $delta, $snmpv3_securityname, $snmpv3_securitylevel, + $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, + $trends, $logtimefmt, $itemid); + + return $result; + } + + // first add mother item + $result=DBexecute("insert into items". + " (description,key_,hostid,delay,history,nextcheck,status,type,". + "snmp_community,snmp_oid,value_type,trapper_hosts,snmp_port,units,multiplier,". + "delta,snmpv3_securityname,snmpv3_securitylevel,snmpv3_authpassphrase,". + "snmpv3_privpassphrase,formula,trends,logtimefmt,templateid)". + " values (".zbx_dbstr($description).",".zbx_dbstr($key).",$hostid,$delay,$history,0, + $status,$type,".zbx_dbstr($snmp_community).",".zbx_dbstr($snmp_oid).",$value_type,". + zbx_dbstr($trapper_hosts).",$snmp_port,".zbx_dbstr($units).",$multiplier,$delta,". + zbx_dbstr($snmpv3_securityname).",$snmpv3_securitylevel,". + zbx_dbstr($snmpv3_authpassphrase).",".zbx_dbstr($snmpv3_privpassphrase).",". + zbx_dbstr($formula).",$trends,".zbx_dbstr($logtimefmt).",$templateid)"); + + + if(!$result) + return $result; + + $itemid = DBinsert_id($result,"items","itemid"); + info("Added new item ".$host["host"].":$key"); + +// add items to child hosts + + $db_hosts = DBselect("select hostid from hosts where templateid=".$host["hostid"]); + while($db_host = DBfetch($db_hosts)) { - $host=get_host_by_hostid($hostid); - info("Added new item ".$host["host"].":$key"); + // recursion + $result = add_item($description, $key, $db_host["hostid"], + $delay, $history, $status, $type, $snmp_community, $snmp_oid, + $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, + $delta, $snmpv3_securityname, $snmpv3_securitylevel, + $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, + $trends, $logtimefmt, $itemid); + if(!$result) + break; } - return DBinsert_id($result,"items","itemid"); + if($result) + return $itemid; + + if($templateid == 0){ + delete_item($itemid); + } + + return $result; } # Update Item status @@ -140,23 +192,26 @@ function update_item($itemid,$description,$key,$hostid,$delay,$history,$status,$type, $snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta, $snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase, - $formula,$trends,$logtimefmt) + $formula,$trends,$logtimefmt,$templateid=0) { + $host = get_host_by_hostid($hostid); + if(!check_right("Item","U",$itemid)) { - error("Insufficient permissions"); - return 0; + error("Insufficient permissions to item '".$host["host"].":$key'"); + return FALSE; } + if($delay<1) { error("Delay cannot be less than 1 second"); - return 0; + return FALSE; } if( ($snmp_port<1)||($snmp_port>65535)) { error("Invalid SNMP port"); - return 0; + return FALSE; } if($value_type == ITEM_VALUE_TYPE_STR) @@ -164,10 +219,52 @@ $delta=0; } + $db_items = DBexecute("select itemid as cnt from items". + " where hostid=$hostid and itemid<>$itemid and key_=".zbx_dbstr($key)); + if(DBnum_rows($db_items) > 0 && $templateid == 0) + { + error("An item with the same Key already exists for host ".$host["host"].".". + " The key must be unique."); + return FALSE; + } + + // first update child items + $db_tmp_items = DBselect("select itemid, hostid from items where templateid=$itemid"); + while($db_tmp_item = DBfetch($db_tmp_items)) + { + // recursion + $result = update_item( + $db_tmp_item["itemid"], $description, $key, $db_tmp_item["hostid"], + $delay, $history, $status, $type, $snmp_community, $snmp_oid, + $value_type, $trapper_hosts, $snmp_port, $units, $multiplier, + $delta, $snmpv3_securityname, $snmpv3_securitylevel, + $snmpv3_authpassphrase, $snmpv3_privpassphrase, $formula, + $trends, $logtimefmt, $itemid); + + if(!$result) + return $result; + } + + if(DBnum_rows($db_items) > 0 && $templateid != 0) + { + $result = delete_item($itemid); + if(!$result) { + error("Can't update item '".$host["host"].":$key'"); + return FALSE; + } + $db_item = DBfetch($db_items); + $itemid = $db_item("itemid"); + } + DBexecute("update items set lastlogsize=0 where itemid=$itemid and key_<>".zbx_dbstr($key)); - $sql="update items set description=".zbx_dbstr($description).",key_=".zbx_dbstr($key).",". - "hostid=$hostid,delay=$delay,history=$history,nextcheck=0,status=$status,type=$type,". + if($templateid==0){ + update_item_status($itemid, $status); + } + + $result=DBexecute( + "update items set description=".zbx_dbstr($description).",key_=".zbx_dbstr($key).",". + "hostid=$hostid,delay=$delay,history=$history,nextcheck=0,type=$type,". "snmp_community=".zbx_dbstr($snmp_community).",snmp_oid=".zbx_dbstr($snmp_oid).",". "value_type=$value_type,trapper_hosts=".zbx_dbstr($trapper_hosts).",". "snmp_port=$snmp_port,units=".zbx_dbstr($units).",multiplier=$multiplier,delta=$delta,". @@ -176,35 +273,63 @@ "snmpv3_authpassphrase=".zbx_dbstr($snmpv3_authpassphrase).",". "snmpv3_privpassphrase=".zbx_dbstr($snmpv3_privpassphrase).",". "formula=".zbx_dbstr($formula).",trends=$trends,logtimefmt=".zbx_dbstr($logtimefmt). - " where itemid=$itemid"; - $result=DBexecute($sql); + ",templateid=$templateid where itemid=$itemid"); if($result) { - $host=get_host_by_hostid($hostid); - info("Item ".$host["host"].":$key updated"); + info("Item '".$host["host"].":$key' updated"); + } return $result; } - function sync_items_with_template_host($hostid,$host_templateid) + function delete_template_items_by_hostid($hostid) { - $sql="select itemid from items where hostid=$host_templateid"; - $result=DBselect($sql); - while($row=DBfetch($result)) + $db_items = DBselect("select itemid from items where hostid=$hostid and templateid<>0"); + while($db_item = DBfetch($db_items)) { - $item=get_item_by_itemid($row["itemid"]); + delete_item($db_item["itemid"]); + } + } - $sql="select itemid from items where key_=".zbx_dbstr($item["key_"])." and hostid=$hostid"; - $result2=DBselect($sql); - if(DBnum_rows($result2)==0) - { - add_item($item["description"],$item["key_"],$hostid,$item["delay"],$item["history"],$item["status"],$item["type"],$item["snmp_community"],$item["snmp_oid"],$item["value_type"],$item["trapper_hosts"],$item["snmp_port"],$item["units"],$item["multiplier"],$item["delta"],$item["snmpv3_securityname"],$item["snmpv3_securitylevel"],$item["snmpv3_authpassphrase"],$item["snmpv3_privpassphrase"],$item["formula"],$item["trends"],$item["logtimefmt"]); - } + function sync_items_with_template($hostid) + { + $host = get_host_by_hostid($hostid); + +//SDI("sync host: ".$host['host']); + + $db_tmp_items = DBselect("select * from items where hostid=".$host["templateid"]); + + while($db_tmp_item = DBfetch($db_tmp_items)) + { + add_item( + $db_tmp_item["description"], + $db_tmp_item["key_"], + $hostid, + $db_tmp_item["delay"], + $db_tmp_item["history"], + $db_tmp_item["status"], + $db_tmp_item["type"], + $db_tmp_item["snmp_community"], + $db_tmp_item["snmp_oid"], + $db_tmp_item["value_type"], + $db_tmp_item["trapper_hosts"], + $db_tmp_item["snmp_port"], + $db_tmp_item["units"], + $db_tmp_item["multiplier"], + $db_tmp_item["delta"], + $db_tmp_item["snmpv3_securityname"], + $db_tmp_item["snmpv3_securitylevel"], + $db_tmp_item["snmpv3_authpassphrase"], + $db_tmp_item["snmpv3_privpassphrase"], + $db_tmp_item["formula"], + $db_tmp_item["trends"], + $db_tmp_item["logtimefmt"], + $db_tmp_item["itemid"]); } } # Add item to hardlinked hosts - +/* function add_item_to_linked_hosts($itemid,$hostid=0) { if($itemid<=0) @@ -244,9 +369,9 @@ } } } - +*/ # Add item to hardlinked hosts - +/* function delete_item_from_templates($itemid) { if($itemid<=0) @@ -270,9 +395,9 @@ } } } - +*/ # Update item in hardlinked hosts - +/* function update_item_in_templates($itemid,$description,$key,$hostid,$delay,$history,$status,$type, $snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta, $snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase, @@ -304,7 +429,7 @@ } } } - +*/ # Activate Item function activate_item($itemid) @@ -349,30 +474,33 @@ function delete_item($itemid) { - $result=delete_triggers_by_itemid($itemid); - if(!$result) - { - return $result; - } - $result=delete_trends_by_itemid($itemid); - $result=delete_history_by_itemid($itemid); - $sql="delete from graphs_items where itemid=$itemid"; - if(!$result) - { - return $result; - } - $result=DBexecute($sql); - if(!$result) - { - return $result; + $item = get_item_by_itemid($itemid); + $host = get_host_by_itemid($itemid); + + // first delete child items + $db_items = DBselect("select itemid from items where templateid=$itemid"); + while($db_item = DBfetch($db_items)) + {// recursion + $result = delete_item($db_item["itemid"]); + if(!$result) return $result; } - $item=get_item_by_itemid($itemid); - $host=get_host_by_hostid($item["hostid"]); - $sql="delete from items where itemid=$itemid"; - $result=DBexecute($sql); + + $result = delete_triggers_by_itemid($itemid); + if(!$result) return $result; + + $result = delete_trends_by_itemid($itemid); + if(!$result) return $result; + + $result = delete_history_by_itemid($itemid); + if(!$result) return $result; + + $result = DBexecute("delete from graphs_items where itemid=$itemid"); + if(!$result) return $result; + + $result = DBexecute("delete from items where itemid=$itemid"); if($result) { - info("Item ".$host["host"].":".$item["key_"]." deleted"); + info("Item '".$host["host"].":".$item["key_"]."' deleted"); } return $result; } @@ -405,4 +533,13 @@ return $descr; } + + function get_realhost_by_itemid($itemid) + { + $itme = get_item_by_itemid($itemid); + if($itme["templateid"] <> 0) + return get_realhost_by_itemid($itme["templateid"]); + + return get_host_by_itemid($itemid); + } ?> diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php index 0a9c47c6..72944c65 100644 --- a/frontends/php/include/locales/en_gb.inc.php +++ b/frontends/php/include/locales/en_gb.inc.php @@ -342,7 +342,8 @@ "S_USE_IP_ADDRESS"=> "Use IP address", "S_IP_ADDRESS"=> "IP address", // "S_USE_THE_HOST_AS_A_TEMPLATE"=> "Use the host as a template", - "S_USE_TEMPLATES_OF_THIS_HOST"=> "Use templates of this host", +// "S_USE_TEMPLATES_OF_THIS_HOST"=> "Use templates of this host", + "S_LINK_WITH_HOST"=> "Link with host", "S_USE_PROFILE"=> "Use profile", "S_DELETE_SELECTED_HOST_Q"=> "Delete selected host?", "S_DELETE_SELECTED_GROUP_Q"=> "Delete selected group?", diff --git a/frontends/php/include/profiles.inc.php b/frontends/php/include/profiles.inc.php index c0feaaa1..6ad187ee 100644 --- a/frontends/php/include/profiles.inc.php +++ b/frontends/php/include/profiles.inc.php @@ -21,7 +21,9 @@ <?php # Add Host Profile - function add_host_profile($hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,$hardware,$software,$contact,$location,$notes) + function add_host_profile( + $hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress, + $hardware,$software,$contact,$location,$notes) { // If user has update permission then ok if(!check_right("Host","U",0)) @@ -30,41 +32,19 @@ return 0; } - $sql="select * from hosts_profiles where hostid=$hostid"; - $result=DBexecute($sql); + $result=DBexecute("select * from hosts_profiles where hostid=$hostid"); if(DBnum_rows($result)>0) { error("Host profile already exists"); return 0; } - $sql="insert into hosts_profiles (hostid,devicetype,name,os,serialno,tag,macaddress,hardware,software,contact,location,notes) values ($hostid,".zbx_dbstr($devicetype).",".zbx_dbstr($name).",".zbx_dbstr($os).",".zbx_dbstr($serialno).",".zbx_dbstr($tag).",".zbx_dbstr($macaddress).",".zbx_dbstr($hardware).",".zbx_dbstr($software).",".zbx_dbstr($contact).",".zbx_dbstr($location).",".zbx_dbstr($notes).")"; - $result=DBexecute($sql); - - return $result; - } - - # Update Host Profile - - function update_host_profile($hostid,$devicetype,$name,$os,$serialno,$tag,$macaddress,$hardware,$software,$contact,$location,$notes) - { - // If user has update permission then ok - if(!check_right("Host","U",0)) - { - error("Insufficient permissions"); - return 0; - } - - $sql="select * from hosts_profiles where hostid=$hostid"; - $result=DBexecute($sql); - if(DBnum_rows($result)==0) - { - error("Host profile does not exist"); - return 0; - } - - $sql="update hosts_profiles set devicetype=".zbx_dbstr($devicetype).",name=".zbx_dbstr($name).",os=".zbx_dbstr($os).",serialno=".zbx_dbstr($serialno).",tag=".zbx_dbstr($tag).",macaddress=".zbx_dbstr($macaddress).",hardware=".zbx_dbstr($hardware).",software=".zbx_dbstr($software).",contact=".zbx_dbstr($contact).",location=".zbx_dbstr($location).",notes=".zbx_dbstr($notes)." where hostid=$hostid"; - $result=DBexecute($sql); + $result=DBexecute("insert into hosts_profiles". + " (hostid,devicetype,name,os,serialno,tag,macaddress,hardware,software,contact,". + "location,notes) values ($hostid,".zbx_dbstr($devicetype).",".zbx_dbstr($name).",". + zbx_dbstr($os).",".zbx_dbstr($serialno).",".zbx_dbstr($tag).",".zbx_dbstr($macaddress). + ",".zbx_dbstr($hardware).",".zbx_dbstr($software).",".zbx_dbstr($contact).",". + zbx_dbstr($location).",".zbx_dbstr($notes).")"); return $result; } @@ -78,8 +58,7 @@ error("Insufficient permissions"); return 0; } - $sql="delete from hosts_profiles where hostid=$hostid"; - $result=DBexecute($sql); + $result=DBexecute("delete from hosts_profiles where hostid=$hostid"); return $result; } diff --git a/frontends/php/include/services.inc.php b/frontends/php/include/services.inc.php index 60990702..c5a36eed 100644 --- a/frontends/php/include/services.inc.php +++ b/frontends/php/include/services.inc.php @@ -312,15 +312,15 @@ } elseif($status==4) { - $desc="<font color=\"#FF8888\">Serious problem</a>"; + $desc="<font color=\"#FF8888\">Serious".SPACE."problem</a>"; } elseif($status==3) { - $desc="<font color=\"#AA0000\">Average problem</a>"; + $desc="<font color=\"#AA0000\">Average".SPACE."problem</a>"; } elseif($status==2) { - $desc="<font color=\"#AA5555\">Minor problem</a>"; + $desc="<font color=\"#AA5555\">Minor".SPACE."problem</a>"; } elseif($status==1) { |
