summaryrefslogtreecommitdiffstats
path: root/frontends
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-10-03 15:10:07 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2005-10-03 15:10:07 +0000
commitcc3aafd58689e4391c75a4d54531cc26bca06c44 (patch)
treee2217ade7edc9ff081e946e2965a168b0867a9f5 /frontends
parenta4bb707afc71f1060abd3f27f7b9a4f12c4bfff6 (diff)
downloadzabbix-cc3aafd58689e4391c75a4d54531cc26bca06c44.tar.gz
zabbix-cc3aafd58689e4391c75a4d54531cc26bca06c44.tar.xz
zabbix-cc3aafd58689e4391c75a4d54531cc26bca06c44.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@2089 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends')
-rw-r--r--frontends/php/config.php64
-rw-r--r--frontends/php/include/autoregistration.inc.php370
-rw-r--r--frontends/php/include/forms.inc.php69
-rw-r--r--frontends/php/include/locales/en_gb.inc.php6
4 files changed, 506 insertions, 3 deletions
diff --git a/frontends/php/config.php b/frontends/php/config.php
index 242f958a..434c128f 100644
--- a/frontends/php/config.php
+++ b/frontends/php/config.php
@@ -142,6 +142,33 @@
unset($_GET["escalationid"]);
show_messages($result, S_ESCALATION_DELETED, S_ESCALATION_WAS_NOT_DELETED);
}
+ if($_GET["register"]=="add autoregistration")
+ {
+ $result=add_autoregistration($_GET["pattern"],$_GET["priority"],$_GET["hostid"]);
+ if($result)
+ {
+ add_audit(AUDIT_ACTION_ADD,AUDIT_RESOURCE_AUTOREGISTRATION,"Autoregistration [".addslashes($_GET["pattern"])."]");
+ }
+ show_messages($result, S_AUTOREGISTRATION_ADDED, S_AUTOREGISTRATION_WAS_NOT_ADDED);
+ }
+ if($_GET["register"]=="update autoregistration")
+ {
+ $result=update_autoregistration($_GET["id"],$_GET["pattern"],$_GET["priority"],$_GET["hostid"]);
+ if($result)
+ {
+ add_audit(AUDIT_ACTION_UPDATE,AUDIT_RESOURCE_AUTOREGISTRATION,"Autoregistration [".addslashes($_GET["pattern"])."]");
+ }
+ show_messages($result, S_AUTOREGISTRATION_UPDATED, S_AUTOREGISTRATION_WAS_NOT_UPDATED);
+ }
+ if($_GET["register"]=="delete autoregistration")
+ {
+ $result=delete_autoregistration($_GET["id"]);
+ if($result)
+ {
+ add_audit(AUDIT_ACTION_DELETE,AUDIT_RESOURCE_AUTOREGISTRATION,"Autoregistration [".addslashes($_GET["pattern"])."]");
+ }
+ show_messages($result, S_AUTOREGISTRATION_DELETED, S_AUTOREGISTRATION_WAS_NOT_DELETED);
+ }
if($_GET["register"]=="add")
{
$result=add_mediatype($_GET["type"],$_GET["description"],$_GET["smtp_server"],$_GET["smtp_helo"],$_GET["smtp_email"],$_GET["exec_path"]);
@@ -185,12 +212,11 @@
$h2=$h2.form_select("config",1,S_MEDIA_TYPES);
$h2=$h2.form_select("config",2,S_ESCALATION_RULES);
$h2=$h2.form_select("config",3,S_IMAGES);
- $h2=$h2.form_select("config",4,S_AUTODISCOVERY);
+ $h2=$h2.form_select("config",4,S_AUTOREGISTRATION);
$h2=$h2."</select>";
show_header2($h1, $h2, "<form name=\"selection\" method=\"get\" action=\"config.php\">", "</form>");
-
# show_table_header(S_CONFIGURATION_OF_ZABBIX_BIG);
?>
@@ -535,5 +561,39 @@
?>
<?php
+ if($_GET["config"]==4)
+ {
+ echo "<br>";
+ show_table_header(S_AUTOREGISTRATION_RULES_BIG);
+
+ table_begin();
+ table_header(array(S_ID,S_PRIORITY,S_PATTERN,S_HOST,S_ACTIONS));
+
+ $result=DBselect("select * from autoreg order by priority");
+ $col=0;
+ while($row=DBfetch($result))
+ {
+ $host=get_host_by_hostid($row["hostid"]);
+ $actions="<a href=\"config.php?config=4&register=change&id=".$row["id"]."\">".S_CHANGE."</a>";
+ table_row(array(
+ $row["id"],
+ $row["priority"],
+ $row["pattern"],
+ $host["host"],
+ $actions),$col++);
+ }
+ if(DBnum_rows($result)==0)
+ {
+ echo "<TR BGCOLOR=#EEEEEE>";
+ echo "<TD COLSPAN=4 ALIGN=CENTER>".S_NO_AUTOREGISTRATION_RULES_DEFINED."</TD>";
+ echo "<TR>";
+ }
+ table_end();
+
+ @insert_autoregistration_form($_GET["id"]);
+ }
+?>
+
+<?php
show_footer();
?>
diff --git a/frontends/php/include/autoregistration.inc.php b/frontends/php/include/autoregistration.inc.php
new file mode 100644
index 00000000..cb57ef9e
--- /dev/null
+++ b/frontends/php/include/autoregistration.inc.php
@@ -0,0 +1,370 @@
+<?php
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+?>
+<?php
+ # Update Item definition for selected group
+
+ function update_item_in_group($groupid,$itemid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt)
+ {
+ $sql="select i.itemid,i.hostid from hosts_groups hg,items i where hg.groupid=$groupid and i.key_=\"$key\" and hg.hostid=i.hostid";
+ $result=DBexecute($sql);
+ while($row=DBfetch($result))
+ {
+ update_item($row["itemid"],$description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt);
+ }
+ return 1;
+ }
+
+ # Delete Item definition from selected group
+
+ function delete_item_from_group($groupid,$itemid)
+ {
+ if(!isset($itemid))
+ {
+ return 0;
+ }
+
+ $item=get_item_by_itemid($itemid);
+ if(!$item)
+ {
+ return 0;
+ }
+
+ $sql="select i.itemid from hosts_groups hg,items i where hg.groupid=$groupid and i.key_=\"".$item["key_"]."\" and hg.hostid=i.hostid";
+ $result=DBexecute($sql);
+ while($row=DBfetch($result))
+ {
+ delete_item($row["itemid"]);
+ }
+ return 1;
+ }
+
+ # Add Item definition to selected group
+
+ function add_item_to_group($groupid,$description,$key,$hostid,$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt)
+ {
+ $sql="select hostid from hosts_groups where groupid=$groupid";
+ $result=DBexecute($sql);
+ while($row=DBfetch($result))
+ {
+ add_item($description,$key,$row["hostid"],$delay,$history,$status,$type,$snmp_community,$snmp_oid,$value_type,$trapper_hosts,$snmp_port,$units,$multiplier,$delta,$snmpv3_securityname,$snmpv3_securitylevel,$snmpv3_authpassphrase,$snmpv3_privpassphrase,$formula,$trends,$logtimefmt);
+ }
+ return 1;
+ }
+
+ # 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)
+ {
+ if(!check_right("Item","A",0))
+ {
+ error("Insufficient permissions");
+ return 0;
+ }
+
+ $host=get_host_by_hostid($hostid);
+
+ $sql="select count(*) from items where hostid=$hostid and key_='$key'";
+ $result=DBexecute($sql);
+ if(DBget_field($result,0,0)>0)
+ {
+ error("An item with the same Key already exists for host ".$host["host"].". The key must be unique.");
+ return 0;
+ }
+
+ if($delay<1)
+ {
+ error("Delay cannot be less than 1 second");
+ return 0;
+ }
+
+ if( ($snmp_port<1)||($snmp_port>65535))
+ {
+ error("Invalid SNMP port");
+ return 0;
+ }
+
+ if($value_type == ITEM_VALUE_TYPE_STR)
+ {
+ $delta=0;
+ }
+
+ $key=addslashes($key);
+ $description=addslashes($description);
+ $logtimefmt=addslashes($logtimefmt);
+ $snmpv3_securityname=addslashes($snmpv3_securityname);
+ $snmpv3_authpassphrase=addslashes($snmpv3_authpassphrase);
+ $snmpv3_privpassphrase=addslashes($snmpv3_privpassphrase);
+
+ $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 ('$description','$key',$hostid,$delay,$history,0,$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')";
+ $result=DBexecute($sql);
+ if($result)
+ {
+ $host=get_host_by_hostid($hostid);
+ info("Added new item ".$host["host"].":$key");
+ }
+ return DBinsert_id($result,"items","itemid");
+ }
+
+ # Update Item status
+
+ function update_item_status($itemid,$status)
+ {
+ if(!check_right("Item","U",0))
+ {
+ error("Insufficient permissions");
+ return 0;
+ }
+ if($status==ITEM_STATUS_ACTIVE)
+ $sql="update items set status=$status,error=\"\" where itemid=$itemid";
+ else
+ $sql="update items set status=$status where itemid=$itemid";
+
+ return DBexecute($sql);
+ }
+
+ # Update Item definition
+
+ 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)
+ {
+ if(!check_right("Item","U",$itemid))
+ {
+ error("Insufficient permissions");
+ return 0;
+ }
+ if($delay<1)
+ {
+ error("Delay cannot be less than 1 second");
+ return 0;
+ }
+
+ if( ($snmp_port<1)||($snmp_port>65535))
+ {
+ error("Invalid SNMP port");
+ return 0;
+ }
+
+ if($value_type == ITEM_VALUE_TYPE_STR)
+ {
+ $delta=0;
+ }
+
+ $key=addslashes($key);
+ $description=addslashes($description);
+ $logtimefmt=addslashes($logtimefmt);
+ $snmpv3_securityname=addslashes($snmpv3_securityname);
+ $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,logtimefmt='$logtimefmt' where itemid=$itemid";
+ $result=DBexecute($sql);
+ if($result)
+ {
+ $host=get_host_by_hostid($hostid);
+ info("Item ".$host["host"].":$key updated");
+ }
+ return $result;
+ }
+
+ # Add item to hardlinked hosts
+
+ function add_item_to_linked_hosts($itemid,$hostid=0)
+ {
+ if($itemid<=0)
+ {
+ return;
+ }
+
+ $item=get_item_by_itemid($itemid);
+
+ // Link with one host only
+ if($hostid!=0)
+ {
+ $sql="select hostid,templateid,items from hosts_templates where hostid=$hostid and templateid=".$item["hostid"];
+ }
+ else
+ {
+ $sql="select hostid,templateid,items from hosts_templates where templateid=".$item["hostid"];
+ }
+ $result=DBselect($sql);
+ while($row=DBfetch($result))
+ {
+ if($row["items"]&1 == 0) continue;
+ $sql="select itemid from items where key_=\"".$item["key_"]."\" and hostid=".$row["hostid"];
+ $result2=DBselect($sql);
+ if(DBnum_rows($result2)==0)
+ {
+ add_item($item["description"],$item["key_"],$row["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"]);
+ $host=get_host_by_hostid($row["hostid"]);
+ info("Added to linked host ".$host["host"]);
+ }
+ }
+ }
+
+ # Add item to hardlinked hosts
+
+ function delete_item_from_templates($itemid)
+ {
+ if($itemid<=0)
+ {
+ return;
+ }
+
+ $item=get_item_by_itemid($itemid);
+
+ $sql="select hostid,templateid,items from hosts_templates where templateid=".$item["hostid"];
+ $result=DBselect($sql);
+ while($row=DBfetch($result))
+ {
+ if($row["items"]&4 == 0) continue;
+ $sql="select itemid from items where key_=\"".$item["key_"]."\" and hostid=".$row["hostid"];
+ $result2=DBselect($sql);
+ while($row2=DBfetch($result2))
+ {
+ delete_item($row2["itemid"]);
+ $host=get_host_by_hostid($row["hostid"]);
+ info("Deleted from linked host ".$host["host"]);
+ }
+ }
+ }
+
+ # Update item in hardlinked hosts
+
+ function update_item_in_templates($itemid)
+ {
+ if($itemid<=0)
+ {
+ return;
+ }
+
+ $item=get_item_by_itemid($itemid);
+
+ $sql="select hostid,templateid,items from hosts_templates where templateid=".$item["hostid"];
+ $result=DBselect($sql);
+ while($row=DBfetch($result))
+ {
+ if($row["items"]&2 == 0) continue;
+ $sql="select itemid from items where key_=\"".$item["key_"]."\" and hostid=".$row["hostid"];
+ $result2=DBselect($sql);
+ if(DBnum_rows($result2)==1)
+ {
+ $row2=DBfetch($result2);
+ update_item($row2["itemid"],$item["description"],$item["key_"],$row["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"]);
+ $host=get_host_by_hostid($row["hostid"]);
+ info("Updated for linked host ".$host["host"]);
+ }
+ }
+ }
+
+ # Activate Item
+
+ function activate_item($itemid)
+ {
+ $sql="update items set status=".ITEM_STATUS_ACTIVE." where itemid=$itemid";
+ return DBexecute($sql);
+ }
+
+ # Disable Item
+
+ function disable_item($itemid)
+ {
+ $sql="update items set status=".ITEM_STATUS_DISABLED." where itemid=$itemid";
+ return DBexecute($sql);
+ }
+
+ function get_item_by_itemid($itemid)
+ {
+ $sql="select * from items where itemid=$itemid";
+ $result=DBselect($sql);
+ if(DBnum_rows($result) == 1)
+ {
+ return DBfetch($result);
+ }
+ else
+ {
+ error("No item with itemid=[$itemid]");
+ }
+ return $item;
+ }
+
+ # Delete Item definition
+
+ 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_hostid($item["hostid"]);
+ $sql="delete from items where itemid=$itemid";
+ $result=DBexecute($sql);
+ if($result)
+ {
+ info("Item ".$host["host"].":".$item["key_"]." deleted");
+ }
+ return $result;
+ }
+
+ function get_n_param($key, $num)
+ {
+ $param="";
+
+// echo $key." ".$num."<br>";
+
+// $params=split('[\[\]\,]', $description);
+ $params=preg_split('/[\]\[,]/', $key);
+
+ if(isset($params[$num]))
+ {
+ $param=$params[$num];
+ }
+
+ return $param;
+ }
+
+ function item_description($description, $key)
+ {
+ $descr=$description;
+
+ for($i=9;$i>0;$i--)
+ {
+ $descr=str_replace("$$i",get_n_param($key,$i),$descr);
+ }
+
+ return $descr;
+ }
+?>
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index 46fe70bb..e398c8a8 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -1418,4 +1418,73 @@
show_table2_header_end();
}
+
+ # Insert autoregistration form
+ function insert_autoregistration_form($id)
+ {
+ if(isset($id))
+ {
+ $result=DBselect("select * from autoreg where id=$id");
+
+ $row=DBfetch($result);
+
+ $pattern=$row["pattern"];
+ $priority=$row["priority"];
+ $hopstid=$row["hostid"];
+ }
+ else
+ {
+ $pattern="*";
+ $priority=10;
+ $hostid=0;
+ }
+
+ $col=0;
+
+ show_form_begin("autoregistration");
+ echo S_AUTOREGISTRATION;
+
+ show_table2_v_delimiter($col++);
+ echo "<form method=\"get\" action=\"config.php\">";
+ echo "<input class=\"biginput\" name=\"config\" type=\"hidden\" value=\"".$_GET["config"]."\" size=8>";
+ if(isset($id))
+ {
+ echo "<input class=\"biginput\" name=\"id\" type=\"hidden\" value=\"$id\" size=8>";
+ }
+
+ echo S_PATTERN;
+ show_table2_h_delimiter();
+ echo "<input class=\"biginput\" name=\"pattern\" size=64 value=\"$pattern\">";
+
+ show_table2_v_delimiter($col++);
+ echo S_PRIORITY;
+ show_table2_h_delimiter();
+ echo "<input class=\"biginput\" name=\"priority\" size=4 value=\"$priority\">";
+
+ show_table2_v_delimiter($col++);
+ echo S_HOST;
+ show_table2_h_delimiter();
+
+ echo "<select class=\"biginput\" name=\"hostid\">";
+ echo form_select("hostid",0,S_SELECT_HOST_DOT_DOT_DOT);
+
+ $sql="select h.hostid,h.host from hosts h where h.status<>".HOST_STATUS_DELETED." group by h.hostid,h.host order by h.host";
+
+ $result=DBselect($sql);
+ while($row=DBfetch($result))
+ {
+ echo form_select("hostid",$row["hostid"],$row["host"]);
+ }
+ echo "</select>";
+
+ show_table2_v_delimiter2($col++);
+ echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"add autoregistration\">";
+ if(isset($id))
+ {
+ echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"update autoregistration\">";
+ echo "<input class=\"button\" type=\"submit\" name=\"register\" value=\"delete autoregistration\" onClick=\"return Confirm('Delete selected autoregistration rule?');\">";
+ }
+
+ show_table2_header_end();
+ }
?>
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index 0415a5a7..301254ba 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -207,7 +207,11 @@
"S_CANNOT_ADD_IMAGE"=> "Cannot add image",
"S_IMAGE_DELETED"=> "Image deleted",
"S_CANNOT_DELETE_IMAGE"=> "Cannot delete image",
- "S_AUTODISCOVERY"=> "Autodiscovery",
+ "S_AUTOREGISTRATION"=> "Autoregistration",
+ "S_AUTOREGISTRATION_RULES_BIG"=> "AUTOREGISTRATION RULES",
+ "S_PRIORITY"=> "Priority",
+ "S_PATTERN"=> "Pattern",
+ "S_NO_AUTOREGISTRATION_RULES_DEFINED"=> "No autoregistration rules defined",
// Latest values
"S_LATEST_VALUES"=> "Latest values",