* extras/pandoradb_migrate_v3.2_to_v4.0.sql: Added column "unit"

to "tagente_modulo" table.  

	* include/functions_modules.php
	include/functions_tags.php
	godmode/agentes/module_manager_editor_common.php
	godmode/agentes/configurar_agente.php
	godmode/agentes/module_manager_editor.php
	godmode/tag/tag.php
	godmode/tag/edit_tag.php: Now it's possible to add tags
	to modules.  



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4389 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
juanmanuelr 2011-05-30 11:09:14 +00:00
parent 5064fbe260
commit 0db355822e
8 changed files with 195 additions and 27 deletions

View File

@ -169,3 +169,9 @@ CREATE TABLE IF NOT EXISTS `ttag_event` (
PRIMARY KEY (id_tag, id_evento),
KEY `idx_id_evento` (`id_evento`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- -----------------------------------------------------
-- Table `tagente_modulo`
-- -----------------------------------------------------
ALTER TABLE `tagente_modulo` ADD COLUMN (`unit` text DEFAULT '');

View File

@ -110,6 +110,7 @@ $cascade_protection = 0;
$icon_path = '';
$update_gis_data = 0;
$unit = "";
$id_tag = array();
$create_agent = (bool) get_parameter ('create_agent');
@ -616,6 +617,7 @@ if ($update_module || $create_module) {
$max_critical = (float) get_parameter ('max_critical');
$ff_event = (int) get_parameter ('ff_event');
$unit = (string) get_parameter('unit');
$id_tag = (array) get_parameter('id_tag');
$active_snmp_v3 = get_parameter('active_snmp_v3');
if ($active_snmp_v3) {
@ -668,7 +670,7 @@ if ($update_module) {
'unit' => $unit);
$result = modules_update_agent_module ($id_agent_module,
$values);
$values, false, $id_tag);
if ($result === false) {
echo '<h3 class="error">'.__('There was a problem updating module').'</h3>';
@ -746,7 +748,7 @@ if ($create_module) {
'unit' => $unit
);
$id_agent_module = modules_create_agent_module ($id_agente, $name, $values);
$id_agent_module = modules_create_agent_module ($id_agente, $name, $values, false, $id_tag);
if ($id_agent_module === false) {
echo '<h3 class="error">'.__('There was a problem adding module').'</h3>';
@ -819,6 +821,10 @@ if ($delete_module) { // DELETE agent module !
if (alerts_delete_alert_agent_module($id_borrar_modulo) === false)
$error++;
$result = db_process_delete_temp('ttag_module', 'id_agente_modulo', $id_borrar_modulo);
if ($result === false)
$error++;
//Check for errors
if ($error != 0) {

View File

@ -173,6 +173,8 @@ if ($id_agent_module) {
$min_critical = $module['min_critical'];
$max_critical = $module['max_critical'];
$ff_event = $module['min_ff_event'];
// Select tag info.
$id_tag = tags_get_module_tags ($id_agent_module);
}
else {
if (!isset ($moduletype)) {

View File

@ -229,4 +229,9 @@ $table_advanced->colspan[4][1] = 3;
$table_advanced->data[5][0] = __('Unit');
$table_advanced->data[5][1] = html_print_input_text ('unit', $unit,
'', 20, 65, true);
/* Tags */
$table_advanced->data[6][0] = __('Tag');
$table_advanced->data[6][1] = html_print_select_from_sql ('SELECT id_tag, name FROM ttag ORDER BY name',
'id_tag[]', $id_tag, '',__('None'),'0', true, true, false, false);
?>

View File

@ -19,7 +19,7 @@ check_login ();
require_once ($config['homedir'].'/include/functions_tags.php');
if (! check_acl ($config['id_user'], 0, "PM") && ! is_user_admin ($config['id_user'])) {
db_pandora_audit("ACL Violation", "Trying to access Edit Skin");
db_pandora_audit("ACL Violation", "Trying to access Edit Tag");
require ("general/noaccess.php");
return;
}
@ -44,12 +44,12 @@ if ($update_tag && $id_tag != 0) {
$values['description'] = $description_tag;
$values['url'] = $url_tag;
$result = tags_update_tag($values);
$result = tags_update_tag($values, 'id_tag = ' . $id_tag);
if ($result === false) {
echo '<h3 class="error">'.__('Error updating tag').'</h3>';
} else {
echo '<h3 class="suc">'.__('Successfully updated skin').'</h3>';
echo '<h3 class="suc">'.__('Successfully updated tag').'</h3>';
}
}

View File

@ -45,10 +45,10 @@ if (is_ajax ()) {
echo '<h3>'.$tag['name'].'</h3>';
echo '<strong>'.__('Number of modules').': </strong> ' .
tags_get_local_modules_count($id);
tags_get_local_modules_count($id_tag);
echo '<br>';
echo '<strong>'.__('Number of policy modules').': </strong>' .
tags_get_policy_modules_count($id);
tags_get_policy_modules_count($id_tag);
return;
}
@ -71,14 +71,20 @@ if ($delete != 0) {
}
}
// statements for pagination
$url = ui_get_url_refresh ();
$total_tags = tags_get_tag_count();
$filter['offset'] = (int) get_parameter ('offset');
$filter['limit'] = (int) $config['block_size'];
// Search action: This will filter the display tag view
$result = false;
// Filtered view?
if ($search != 0) {
$result = tags_search_tag($tag_name);
$result = tags_search_tag($tag_name, $filter);
}
else{
$result = tags_search_tag();
$result = tags_search_tag(false, $filter);
}
// Form to add new tags or search tags
@ -100,6 +106,9 @@ echo "<td align=right>";
echo "</form>";
echo "</table>";
// Prepare pagination
ui_pagination ($total_tags, $url);
// Display tags previously filtered or not
$rowPair = true;
$iterator = 0;
@ -133,7 +142,7 @@ if (!empty($result)){
$data = array ();
$data[0] = $tag["name"];
$data[1] = $tag["description"];
$data[1] = ui_print_truncate_text($tag["description"], 25, false);
$data[2] = '<a href="' . $tag["url"] . '">' . $tag["url"] . '</a>';
$data[3] = ' <a class="tag_details"
href="ajax.php?page=godmode/tag/tag&get_tag_tooltip=1&id_tag='.$tag['id_tag'].'">' .

View File

@ -21,6 +21,7 @@
include_once($config['homedir'] . "/include/functions_agents.php");
include_once($config['homedir'] . '/include/functions_users.php');
include_once($config['homedir'] . '/include/functions_tags.php');
/**
* Copy a module defined in an agent to other agent.
@ -172,17 +173,23 @@ function modules_delete_agent_module ($id_agent_module) {
*
* @param mixed Agent module id to be deleted. Accepts an array with ids.
* @param array Values to update.
*
* @param mixed Tag's module array or false.
*
* @return True if the module was updated. False if not.
*/
function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false) {
function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false,
$tags = false) {
if (! is_array ($values) || empty ($values))
return false;
if (isset ($values['nombre']) && empty ($values['nombre']))
return false;
$return_tag = tags_update_module_tag ($id, $tags);
if ($return_tag === false){
return false;
}
if ($onlyNoDeletePending) {
return (@db_process_sql_update ('tagente_modulo', $values,
@ -201,10 +208,12 @@ function modules_update_agent_module ($id, $values, $onlyNoDeletePending = false
* @param int Module name id.
* @param array Extra values for the module.
* @param bool Disable the ACL checking, for default false.
*
* @param mixed Array with tag's ids or false.
*
* @return New module id if the module was created. False if not.
*/
function modules_create_agent_module ($id_agent, $name, $values = false, $disableACL = false) {
function modules_create_agent_module ($id_agent, $name, $values = false, $disableACL = false,
$tags = false) {
global $config;
if (!$disableACL) {
@ -224,6 +233,15 @@ function modules_create_agent_module ($id_agent, $name, $values = false, $disabl
if ($id_agent_module === false)
return false;
$return_tag = tags_insert_module_tag ($id_agent_module, $tags);
if ($return_tag === false){
db_process_sql_delete ('tagente_modulo',
array ('id_agente_modulo' => $id_agent_module));
return false;
}
switch ($config["dbtype"]) {
case "mysql":
$result = db_process_sql_insert ('tagente_estado',

View File

@ -23,10 +23,11 @@
* Find a tag searching by tag's or description name.
*
* @param string $tag_name_description Name or description of the tag that it's currently searched.
*
* @param array $filter Array with pagination parameters.
*
* @return mixed Returns an array with the tag selected by name or false.
*/
function tags_search_tag ($tag_name_description = false) {
function tags_search_tag ($tag_name_description = false, $filter = false) {
global $config;
if ($tag_name_description){
@ -41,15 +42,27 @@ function tags_search_tag ($tag_name_description = false) {
break;
case "oracle":
$sql = 'SELECT * FROM ttag WHERE (UPPER(name) LIKE UPPER (\'%'. $tag_name_description .'%\') OR
UPPER(description) LIKE UPPER (\'%'. $tag_name_description .'%\'))';
UPPER(dbms_lob.substr(description, 4000, 1)) LIKE UPPER (\'%'. $tag_name_description .'%\'))';
break;
}
}
else{
$sql = 'SELECT * FROM ttag';
}
$result = db_get_all_rows_sql ($sql);
switch ($config["dbtype"]) {
case "mysql":
case "postgresql":
$result = db_get_all_rows_sql ($sql . ' LIMIT ' . $filter['offset'] . ',' . $filter['limit']);
break;
case "oracle":
$result = oracle_recode_query ($sql, $filter, 'AND', false);
if ($components != false) {
for ($i=0; $i < count($components); $i++) {
unset($result[$i]['rnum']);
}
}
break;
}
if ($result === false)
return array (); //Return an empty array
else
@ -123,8 +136,8 @@ function tags_get_url($id){
* @return mixed Int with the tag's count or false.
*/
function tags_get_modules_count($id){
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', 'id_tag', $id);
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', 'id_tag', $id);
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
return $num_modules + $num_policy_modules;
}
@ -137,7 +150,7 @@ function tags_get_modules_count($id){
* @return mixed Int with the tag's count or false.
*/
function tags_get_local_modules_count($id){
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', 'id_tag', $id);
$num_modules = (int)db_get_value_filter('count(*)', 'ttag_module', array('id_tag' => $id));
return $num_modules;
}
@ -150,7 +163,7 @@ function tags_get_local_modules_count($id){
* @return mixed Int with the tag's count or false.
*/
function tags_get_policy_modules_count($id){
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', 'id_tag', $id);
$num_policy_modules = (int)db_get_value_filter('count(*)', 'ttag_policy_module', array('id_tag' => $id));
return $num_policy_modules;
}
@ -161,11 +174,12 @@ function tags_get_policy_modules_count($id){
* Updates a tag by id.
*
* @param array $id Int with tag id info.
* @param string $where Where clause to update record.
*
* @return bool True or false if something goes wrong.
*/
function tags_update_tag($values){
return db_process_sql_update ('ttag', $values);
function tags_update_tag($values, $where){
return db_process_sql_update ('ttag', $values, $where);
}
/**
@ -200,3 +214,111 @@ function tags_delete_tag ($id_tag){
}
}
/**
* Get tag's total count.
*
* @return mixed Int with the tag's count.
*/
function tags_get_tag_count(){
return (int)db_get_value('count(*)', 'ttag');
}
/**
* Inserts tag's array of a module.
*
* @param int $id_agent_module Module's id.
* @param array $tags Array with tags to associate to the module.
*
* @return bool True or false if something goes wrong.
*/
function tags_insert_module_tag ($id_agent_module, $tags){
$errn = 0;
$values = array();
foreach ($tags as $tag){
//Protect against default insert
if (empty($tag))
continue;
$values['id_tag'] = $tag;
$values['id_agente_modulo'] = $id_agent_module;
$result_tag = db_process_sql_insert('ttag_module', $values, false);
if ($result_tag === false)
$errn++;
}
if ($errn > 0){
db_process_sql_rollback();
return false;
}
else{
db_process_sql_commit();
return true;
}
}
/**
* Updates tag's array of a module.
*
* @param int $id_agent_module Module's id.
* @param array $tags Array with tags to associate to the module.
*
* @return bool True or false if something goes wrong.
*/
function tags_update_module_tag ($id_agent_module, $tags){
$errn = 0;
/* First delete module tag entries */
$result_tag = db_process_delete_temp ('ttag_module', 'id_agente_modulo', $id_agent_module);
if ($result_tag === false){
db_process_sql_rollback();
return false;
}
$values = array();
foreach ($tags as $tag){
$values['id_tag'] = $tag;
$values['id_agente_modulo'] = $id_agent_module;
$result_tag = db_process_sql_insert('ttag_module', $values, false);
if ($result_tag === false)
$errn++;
}
if ($errn > 0){
db_process_sql_rollback();
return false;
}
else{
db_process_sql_commit();
return true;
}
}
/**
* Select all tags of a module.
*
* @param int $id_agent_module Module's id.
*
* @return mixed Array with module tags or false if something goes wrong.
*/
function tags_get_module_tags ($id_agent_module){
if (empty($id_agent_module))
return false;
$tags = db_get_all_rows_filter('ttag_module', array('id_agente_modulo' => $id_agent_module), false);
if ($tags === false)
return false;
$return = array();
foreach ($tags as $tag){
$return[] = $tag['id_tag'];
}
return $return;
}
?>