summaryrefslogtreecommitdiffstats
path: root/frontends/php
diff options
context:
space:
mode:
authorosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-25 07:21:56 +0000
committerosmiy <osmiy@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-10-25 07:21:56 +0000
commitd23332dbc5dabb29dfec400d2d9ba782b46b5615 (patch)
tree21d5823c2940c9ada032bc3650fac8423b266365 /frontends/php
parent28a09ed13e41ddbe5e30d63e92a1f5fb3395ef89 (diff)
downloadzabbix-d23332dbc5dabb29dfec400d2d9ba782b46b5615.tar.gz
zabbix-d23332dbc5dabb29dfec400d2d9ba782b46b5615.tar.xz
zabbix-d23332dbc5dabb29dfec400d2d9ba782b46b5615.zip
- developed node manager (Eugene)
git-svn-id: svn://svn.zabbix.com/trunk@3379 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'frontends/php')
-rw-r--r--frontends/php/include/actions.inc.php13
-rw-r--r--frontends/php/include/audit.inc.php1
-rw-r--r--frontends/php/include/db.inc.php29
-rw-r--r--frontends/php/include/defines.inc.php1
-rw-r--r--frontends/php/include/forms.inc.php81
-rw-r--r--frontends/php/include/locales/en_gb.inc.php13
-rw-r--r--frontends/php/include/nodes.inc.php72
-rw-r--r--frontends/php/items.php2
-rw-r--r--frontends/php/nodes.php64
9 files changed, 241 insertions, 35 deletions
diff --git a/frontends/php/include/actions.inc.php b/frontends/php/include/actions.inc.php
index ca0e28bb..47a771de 100644
--- a/frontends/php/include/actions.inc.php
+++ b/frontends/php/include/actions.inc.php
@@ -87,11 +87,7 @@
function add_action($actiontype,$userid,$subject,$message,$recipient,$maxrepeats,$repeatdelay,$status,$scripts)
{
-// if(!check_right_on_trigger("A",$triggerid))
-// {
-// error("Insufficient permissions");
-// return 0;
-// }
+ // TODO check permission by new value.
if($actiontype == ACTION_TYPE_MESSAGE)
{
@@ -118,11 +114,8 @@
function update_action($actionid,$actiontype,$userid,$subject,$message,$recipient,$maxrepeats,$repeatdelay,$status,$scripts)
{
-// if(!check_right_on_trigger("U",$triggerid))
-// {
-// error("Insufficient permissions");
-// return 0;
-// }
+ // TODO check permission by new value.
+
if($actiontype == ACTION_TYPE_MESSAGE)
{
$scripts = "";
diff --git a/frontends/php/include/audit.inc.php b/frontends/php/include/audit.inc.php
index 6b89c53d..71dbbabd 100644
--- a/frontends/php/include/audit.inc.php
+++ b/frontends/php/include/audit.inc.php
@@ -38,6 +38,7 @@
$str_resource[AUDIT_RESOURCE_IT_SERVICE] = S_IT_SERVICE;
$str_resource[AUDIT_RESOURCE_MAP] = S_MAP;
$str_resource[AUDIT_RESOURCE_SCREEN] = S_SCREEN;
+ $str_resource[AUDIT_RESOURCE_NODE] = S_NODE;
if(isset($str_resource[$resource_type]))
return $str_resource[$resource_type];
diff --git a/frontends/php/include/db.inc.php b/frontends/php/include/db.inc.php
index 5bbd8952..0304d867 100644
--- a/frontends/php/include/db.inc.php
+++ b/frontends/php/include/db.inc.php
@@ -64,20 +64,6 @@
}
}
- /* NOTE:
- LIMIT and OFFSET records
-
- Example: select 6-15 row.
-
- MySQL:
- SELECT a FROM tbl LIMIT 5,10
- SELECT a FROM tbl LIMIT 10 OFFSET 5
- PostgreSQL:
- SELECT a FROM tbl LIMIT 10 OFFSET 5
- Oracle:
- SELECT a FROM tbe WHERE ROWNUM < 15 // ONLY < 15
- SELECT * FROM (SELECT ROWNUM as RN, * FROM tbl) WHERE RN BETWEEN 6 AND 15
- */
function DBstart()
{
@@ -98,6 +84,21 @@
}
}
+ /* NOTE:
+ LIMIT and OFFSET records
+
+ Example: select 6-15 row.
+
+ MySQL:
+ SELECT a FROM tbl LIMIT 5,10
+ SELECT a FROM tbl LIMIT 10 OFFSET 5
+ PostgreSQL:
+ SELECT a FROM tbl LIMIT 10 OFFSET 5
+ Oracle:
+ SELECT a FROM tbe WHERE ROWNUM < 15 // ONLY < 15
+ SELECT * FROM (SELECT ROWNUM as RN, * FROM tbl) WHERE RN BETWEEN 6 AND 15
+ */
+
function DBselect($query, $limit='NO')
{
global $DB,$DB_TYPE;
diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php
index 4eea71f4..7b67f43e 100644
--- a/frontends/php/include/defines.inc.php
+++ b/frontends/php/include/defines.inc.php
@@ -75,6 +75,7 @@
define("AUDIT_RESOURCE_IT_SERVICE", 18);
define("AUDIT_RESOURCE_MAP", 19);
define("AUDIT_RESOURCE_SCREEN", 20);
+ define("AUDIT_RESOURCE_NODE", 21);
define("CONDITION_TYPE_GROUP", 0);
define("CONDITION_TYPE_HOST", 1);
diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php
index e7831b22..eda29d7d 100644
--- a/frontends/php/include/forms.inc.php
+++ b/frontends/php/include/forms.inc.php
@@ -21,14 +21,85 @@
<?php
// TODO !!! Correcr the help links !!! TODO
- include_once "include/defines.inc.php";
- include_once "include/classes/graph.inc.php";
- include_once "include/users.inc.php";
- include_once "include/db.inc.php";
+ require_once "include/defines.inc.php";
+ require_once "include/classes/graph.inc.php";
+ require_once "include/users.inc.php";
+ require_once "include/db.inc.php";
function insert_node_form()
{
- SDI('TODO'); /* TODO node form realization */
+ global $ZBX_CURNODEID;
+
+ $frm_title = S_NODE;
+
+ if(isset($_REQUEST['nodeid']))
+ {
+ $node_data = get_node_by_nodeid($_REQUEST['nodeid']);
+
+ $nodetype = $node_data['nodetype'];
+ $masterid = $node_data['masterid'];
+
+ $frm_title = S_NODE." \"".$node_data["name"]."\"";
+ }
+
+ $frmNode= new CFormTable($frm_title);
+ $frmNode->SetHelp("node.php");
+
+ if(isset($_REQUEST['nodeid']))
+ {
+ $frmNode->AddVar('nodeid', $_REQUEST['nodeid']);
+ }
+
+ if(isset($_REQUEST['nodeid']) && (!isset($_REQUEST["form_refresh"]) || isset($_REQUEST["register"])))
+ {
+ $name = $node_data['name'];
+ $timezone = $node_data['timezone'];
+ $ip = $node_data['ip'];
+ $port = $node_data['port'];
+ $slave_history = $node_data['slave_history'];
+ $slave_trends = $node_data['slave_trends'];
+ }
+ else
+ {
+ $name = get_request('name','');
+ $timezone = get_request('timezone', 0);
+ $ip = get_request('ip','127.0.0.1');
+ $port = get_request('port',10051);
+ $slave_history = get_request('slave_history',90);
+ $slave_trends = get_request('slave_trends',365);
+ if(!isset($nodetype)) $nodetype = get_request('nodetype',0);
+ if(!isset($masterid)) $masterid = get_request('masterid', $ZBX_CURNODEID);
+ }
+
+ $master_node = DBfetch(DBselect('select name from nodes where nodeid='.$masterid));
+
+ $frmNode->AddRow(S_NAME, new CTextBox('name', $name, 40));
+
+ $frmNode->AddRow(S_MASTER_NODE, new CTextBox('master_name', $master_node['name'], 40, 'yes'));
+ $frmNode->AddRow(S_TYPE, new CTextBox('node_type', $nodetype ? S_LOCAL : S_REMOTE , null, 'yes'));
+
+ $cmbTimeZone = new CComboBox('timezone', $timezone);
+ for($i = -12; $i <= 13; $i++)
+ {
+ $cmbTimeZone->AddItem($i, "GMT".sprintf("%+03d:00", $i));
+ }
+ $frmNode->AddRow(S_TIME_ZONE, $cmbTimeZone);
+ $frmNode->AddRow(S_IP, new CTextBox('ip', $ip, 17));
+ $frmNode->AddRow(S_PORT, new CTextBox('port', $port,5));
+ $frmNode->AddRow(S_DO_NOT_KEEP_HISTORY_OLDER_THAN, new CTextBox('slave_history', $slave_history,6));
+ $frmNode->AddRow(S_DO_NOT_KEEP_TRENDS_OLDER_THAN, new CTextBox('slave_trends', $slave_trends,6));
+
+
+ $frmNode->AddItemToBottomRow(new CButton('save',S_SAVE));
+ if(isset($_REQUEST['nodeid']) && !DBfetch(DBselect('select * from nodes where masterid='.$_REQUEST['nodeid'])))
+ {
+ $frmNode->AddItemToBottomRow(SPACE);
+ $frmNode->AddItemToBottomRow(new CButtonDelete("Delete selected node?",
+ url_param("form").url_param("nodeid")));
+ }
+ $frmNode->AddItemToBottomRow(SPACE);
+ $frmNode->AddItemToBottomRow(new CButtonCancel(url_param("config")));
+ $frmNode->Show();
}
function insert_new_message_form()
diff --git a/frontends/php/include/locales/en_gb.inc.php b/frontends/php/include/locales/en_gb.inc.php
index a8b803ab..7459a223 100644
--- a/frontends/php/include/locales/en_gb.inc.php
+++ b/frontends/php/include/locales/en_gb.inc.php
@@ -27,6 +27,19 @@
"S_DATE_FORMAT_YMD"=> "d M Y",
"S_HTML_CHARSET"=> "iso-8859-1",
+// node.php
+ "S_TIME_ZONE"=> "Time zone",
+ "S_DO_NOT_KEEP_HISTORY_OLDER_THAN"=> "Do not keep history older than (in days)",
+ "S_DO_NOT_KEEP_TRENDS_OLDER_THAN"=> "Do not keep trends older than (in days)",
+ "S_MASTER_NODE"=> "Master node",
+ "S_REMOTE"=> "Remote",
+ "S_NODE_UPDATED"=> "Node updated",
+ "S_CANNOT_UPDATE_NODE"=> "Cannot update node",
+ "S_NODE_ADDED"=> "Node added",
+ "S_CANNOT_ADD_NODE"=> "Cannot add node",
+ "S_NODE_DELETED"=> "Node deleted",
+ "S_CANNOT_DELETE_NODE"=> "Cannot delete node",
+
// acknow.php
"S_ACKNOWLEDGES"=> "Acknowledges",
"S_ACKNOWLEDGE"=> "Acknowledge",
diff --git a/frontends/php/include/nodes.inc.php b/frontends/php/include/nodes.inc.php
new file mode 100644
index 00000000..306c66df
--- /dev/null
+++ b/frontends/php/include/nodes.inc.php
@@ -0,0 +1,72 @@
+<?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.
+**/
+ require_once "include/db.inc.php";
+?>
+<?php
+ function add_node($name,$timezone,$ip,$port,$slave_history,$slave_trends)
+ {
+ global $ZBX_CURNODEID;
+
+ $nodeid = DBfetch(DBselect('select max(nodeid) as max from nodes'));
+ $nodeid = $nodeid['max'] + 1;
+ $result = DBexecute('insert into nodes (nodeid,name,timezone,ip,port,slave_history,slave_trends,'.
+ 'event_lastid,history_lastid,nodetype,masterid) values ('.
+ $nodeid.','.zbx_dbstr($name).','.$timezone.','.zbx_dbstr($ip).','.$port.','.$slave_history.','.$slave_trends.','.
+ '0,0,0,'.$ZBX_CURNODEID.')');
+
+ return ($result ? $nodeid : $result);
+ }
+
+ function update_node($nodeid,$name,$timezone,$ip,$port,$slave_history,$slave_trends)
+ {
+ $result = DBexecute('update nodes set name='.zbx_dbstr($name).',timezone='.$timezone.',ip='.zbx_dbstr($ip).',port='.$port.','.
+ 'slave_history='.$slave_history.',slave_trends='.$slave_trends.
+ ' where nodeid='.$nodeid);
+ return $result;
+ }
+
+ function delete_node($nodeid)
+ {
+ $result = false;
+ if(!DBfetch(DBselect('select * from nodes where masterid='.$nodeid)))
+ {
+ $result = DBexecute('delete from nodes where nodeid='.$nodeid);
+ }
+ return $result;
+ }
+
+ function get_node_by_nodeid($nodeid)
+ {
+ return DBfetch(DBselect('select * from nodes where nodeid='.$nodeid));
+ }
+
+ function get_node_path($nodeid, $result='/')
+ {
+ if($node_data = get_node_by_nodeid($nodeid))
+ {
+ if($node_data['masterid'])
+ {
+ $result = get_node_path($node_data['masterid'],$result);
+ }
+ $result .= $node_data['name'].'/';
+ }
+ return $result;
+ }
+?>
diff --git a/frontends/php/items.php b/frontends/php/items.php
index b551b71d..5b8d8aea 100644
--- a/frontends/php/items.php
+++ b/frontends/php/items.php
@@ -107,8 +107,6 @@ include_once "include/page_header.php";
validate_group_with_host(PERM_READ_WRITE,array("always_select_first_host","only_current_node"));
?>
<?php
-SDI($_REQUEST['hostid']);
-
$result = 0;
if(isset($_REQUEST['del_delay_flex']) && isset($_REQUEST['rem_delay_flex']))
{
diff --git a/frontends/php/nodes.php b/frontends/php/nodes.php
index d40662e5..89e78a28 100644
--- a/frontends/php/nodes.php
+++ b/frontends/php/nodes.php
@@ -21,6 +21,7 @@
<?php
require_once "include/config.inc.php";
require_once "include/forms.inc.php";
+ require_once "include/nodes.inc.php";
$page["title"] = "S_NODES";
$page["file"] = "nodes.php";
@@ -35,6 +36,13 @@ include_once "include/page_header.php";
// media form
"nodeid"=> array(T_ZBX_INT, O_NO, null, DB_ID, '{form}=="update"'),
+
+ "name"=> array(T_ZBX_STR, O_OPT, null, NOT_EMPTY, 'isset({save})'),
+ "timezone"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(-12,+13),'isset({save})'),
+ "ip"=> array(T_ZBX_STR, O_OPT, null, DB_ID, 'isset({save})'),
+ "port"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(1,65535),'isset({save})'),
+ "slave_history"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535),'isset({save})'),
+ "slave_trends"=> array(T_ZBX_INT, O_OPT, null, BETWEEN(0,65535),'isset({save})'),
/* actions */
"save"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
"delete"=> array(T_ZBX_STR, O_OPT, P_SYS|P_ACT, NULL, NULL),
@@ -43,7 +51,7 @@ include_once "include/page_header.php";
"form"=> array(T_ZBX_STR, O_OPT, P_SYS, NULL, NULL),
"form_refresh"=> array(T_ZBX_INT, O_OPT, NULL, NULL, NULL)
);
-
+
check_fields($fields);
$accessible_nodes = get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST);
@@ -54,6 +62,47 @@ include_once "include/page_header.php";
}
?>
<?php
+ if(isset($_REQUEST['save']))
+ {
+ $result = false;
+ if(isset($_REQUEST['nodeid']))
+ { /* update */
+ $audit_action = AUDIT_ACTION_UPDATE;
+ $result = update_node($_REQUEST['nodeid'],
+ $_REQUEST['name'], $_REQUEST['timezone'], $_REQUEST['ip'], $_REQUEST['port'],
+ $_REQUEST['slave_history'], $_REQUEST['slave_trends']);
+ $nodeid = $_REQUEST['nodeid'];
+ show_messages($result, S_NODE_UPDATED, S_CANNOT_UPDATE_NODE);
+ }
+ else
+ { /* add */
+ $audit_action = AUDIT_ACTION_ADD;
+ $result = add_node(
+ $_REQUEST['name'], $_REQUEST['timezone'], $_REQUEST['ip'], $_REQUEST['port'],
+ $_REQUEST['slave_history'], $_REQUEST['slave_trends']);
+ $nodeid = $result;
+
+ show_messages($result, S_NODE_ADDED, S_CANNOT_ADD_NODE);
+ }
+ add_audit_if($result,$audit_action,AUDIT_RESOURCE_NODE,'Node ['.$_REQUEST['name'].'] id ['.$nodeid.']');
+ if($result)
+ {
+ unset($_REQUEST['form']);
+ }
+ }
+ elseif(isset($_REQUEST['delete']))
+ {
+ $node_data = get_node_by_nodeid($_REQUEST['nodeid']);
+ $result = delete_node($_REQUEST['nodeid']);
+ show_messages($result, S_NODE_DELETED, S_CANNOT_DELETE_NODE);
+ add_audit_if($result,AUDIT_ACTION_DELETE,'Node ['.$node_data['name'].'] id ['.$node_data['nodeid'].']');
+ if($result)
+ {
+ unset($_REQUEST['form'],$node_data);
+ }
+ }
+?>
+<?php
if(isset($_REQUEST["form"]))
{
insert_node_form();
@@ -65,16 +114,23 @@ include_once "include/page_header.php";
show_table_header(S_NODES_BIG,$form);
$table=new CTableInfo(S_NO_NODES_DEFINED);
- $table->SetHeader(array(S_NAME));
+ $table->SetHeader(array(S_NAME,S_TYPE,S_TIME_ZONE,S_IP.':'.S_PORT));
$db_nodes = DBselect('select * from nodes where nodeid in ('.
get_accessible_nodes_by_user($USER_DETAILS,PERM_READ_LIST).') '.
- ' order by name ');
+ ' order by nodetype desc,name ');
while($row=DBfetch($db_nodes))
{
$table->AddRow(array(
- new CLink($row["name"],"?&form=update&nodeid=".$row["nodeid"],'action'),
+ array(
+ get_node_path($row['masterid']),
+ new CLink(
+ ($row['nodetype'] ? new CSpan($row["name"], 'bold') : $row["name"]),
+ "?&form=update&nodeid=".$row["nodeid"],'action')),
+ $row['nodetype'] ? new CSpan(S_LOCAL,'bold') : S_REMOTE,
+ new CSpan("GMT".sprintf("%+03d:00", $row['timezone']), $row['nodetype'] ? 'bold' : null),
+ new CSpan($row['ip'].':'.$row['port'], $row['nodetype'] ? 'bold' : null)
));
}
$table->Show();