From fff2782f9c9353930aa1132ce24ab6aeb8877c74 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 16 Dec 2014 12:59:45 +0100 Subject: [PATCH 01/92] Now the tree images will be in the images folder. The operation/tree folder will be removed when this feature ends --- pandora_console/images/tree/branch.png | Bin 0 -> 216 bytes pandora_console/images/tree/closed.png | Bin 0 -> 196 bytes pandora_console/images/tree/expanded.png | Bin 0 -> 191 bytes pandora_console/images/tree/first_closed.png | Bin 0 -> 193 bytes pandora_console/images/tree/first_expanded.png | Bin 0 -> 189 bytes pandora_console/images/tree/first_leaf.png | Bin 0 -> 159 bytes pandora_console/images/tree/last_closed.png | Bin 0 -> 193 bytes pandora_console/images/tree/last_expanded.png | Bin 0 -> 189 bytes pandora_console/images/tree/last_leaf.png | Bin 0 -> 172 bytes pandora_console/images/tree/leaf.png | Bin 0 -> 221 bytes pandora_console/images/tree/no_branch.png | Bin 0 -> 211 bytes pandora_console/images/tree/one_closed.png | Bin 0 -> 190 bytes pandora_console/images/tree/one_expanded.png | Bin 0 -> 185 bytes 13 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 pandora_console/images/tree/branch.png create mode 100644 pandora_console/images/tree/closed.png create mode 100644 pandora_console/images/tree/expanded.png create mode 100644 pandora_console/images/tree/first_closed.png create mode 100644 pandora_console/images/tree/first_expanded.png create mode 100644 pandora_console/images/tree/first_leaf.png create mode 100644 pandora_console/images/tree/last_closed.png create mode 100644 pandora_console/images/tree/last_expanded.png create mode 100644 pandora_console/images/tree/last_leaf.png create mode 100644 pandora_console/images/tree/leaf.png create mode 100644 pandora_console/images/tree/no_branch.png create mode 100755 pandora_console/images/tree/one_closed.png create mode 100755 pandora_console/images/tree/one_expanded.png diff --git a/pandora_console/images/tree/branch.png b/pandora_console/images/tree/branch.png new file mode 100644 index 0000000000000000000000000000000000000000..dac28141c7ae11959e5bde1813a493c4d41010c9 GIT binary patch literal 216 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5$P6SE-Lv|E6k~CayA#8@b22Z19JTdi#5$LDD5be!&b5&u*lFI7!~_E({&4vK~MVXMsm#F#`j)5C}6~x?A@LD9B#o z>FdgVlaq;0Tf(r8wF4-mQsNp>;+&tGo0?a`5So*kn4;kB>822zn^;s5oLH7xq!0$g wMtTOjW_jHLs^{}`aSY+Oo}7@vz&L9n19Jm|VEMbhQ-LxJp00i_>zopr0QPJ*mjD0& literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/closed.png b/pandora_console/images/tree/closed.png new file mode 100644 index 0000000000000000000000000000000000000000..a0beb9bfd9bcbe2c1d069f772f3a43d90db20d82 GIT binary patch literal 196 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+BFI z1R5F|fV_Ra?_xkIN`m}?862M7NCR<_yxm;OkH}&M25un`X1sK_?hjCq zy~NYkmHj3s6OXxS&(i~|fI{k?E{-7_*OLyg|w6Zds7Gnxt^vB%*sD;7P)z4*}Q$iB}XN@zo literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/expanded.png b/pandora_console/images/tree/expanded.png new file mode 100644 index 0000000000000000000000000000000000000000..a5249e42b42d44547e5771d8118185da1d5e9e8d GIT binary patch literal 191 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+8o& z0u2ofK;EL+lC>ZeB|(0{3=Yq3q=7g|-tI089jvk*Kn`btM`SSr1Gf+eGhVt|_XjA* zUgGKN%6^lRiPxI{m!^(8P)Nzs#W95AdU8TSN&}-(WY5Bd3UbO^3%3RcIP)y&Q<=PR a1H*|hChyp*j=zDb89ZJ6T-G@yGywo(Z!eJm literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/first_closed.png b/pandora_console/images/tree/first_closed.png new file mode 100644 index 0000000000000000000000000000000000000000..7a3673c7c237c6228746c89f627baac53e36ca2a GIT binary patch literal 193 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+Far z1sWO}fV_JTT%Lnelmz(&GdMiEkp|)%y{W;-5;PJ zdx@v7EBj4OCLS~WQf-N^Kp_=R7sn8e>&XcUk_K&UOq>cS2`Np&QQWK(cP2zmuv#I; bRusu_B8AB>|8%h}P(6dEtDnm{r-UW|Y3eWE literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/first_expanded.png b/pandora_console/images/tree/first_expanded.png new file mode 100644 index 0000000000000000000000000000000000000000..ef8d30aaa0bd2f86368cc518c023dd1f3ec3b32c GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+G)$ z0u2ofKwe4B1{siwk|4ie28U-i(macq>jcbj#~{ToMvJ; Xx`fHCxM1p5pjrk`S3j3^P6Ih+L^k;M!Q+(IDCcejR2# w_RR}{LPDM{jv*Y^lM@tV4ceMK*^)dM_~RMkzOQK32Ffycy85}Sb4q9e0O~g-^8f$< literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/last_closed.png b/pandora_console/images/tree/last_closed.png new file mode 100644 index 0000000000000000000000000000000000000000..4e07936700f4413474b78a45aa9534cc6659d40f GIT binary patch literal 193 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+Ad~ z1R5F|fV|r&yE8#5N`m}?862M7NCR<_yxm;OkH}&M25un`X1sK_?hjCq zy~NYkmHj3s6OWm2luJqxP)Nno#W95AdU8TSN&}-(WY5Bd3UU+9pI}knBF3dud~lOO c=@cf0QvpoA9Cs|w1JyHly85}Sb4q9e07SGf!vFvP literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/last_expanded.png b/pandora_console/images/tree/last_expanded.png new file mode 100644 index 0000000000000000000000000000000000000000..84116301672951c3520d81252776210da1afc15b GIT binary patch literal 189 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+8=A z0u2ofK%Ri?-K!uKB|(0{3=Yq3q=7g|-tI089jvk*Kn`btM`SSr1Gf+eGhVt|_XjA* zUgGKN%6^lRiPuV2pgYG8D5T)&;uyklJvkvErGZf?vS;B!1vzD|glzvwB0eR@f}~4={DK)Ap4~_Tagw~{XE z)7O>#CMS~sGxLXkZ?*u1ggjjwLpZJ{C!{biE;Xd1_fU*ppu6{1- HoD!M<5Rxm- literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/leaf.png b/pandora_console/images/tree/leaf.png new file mode 100644 index 0000000000000000000000000000000000000000..52ffb066cbbb6cf4b0acdde4a59698e0c8e29f55 GIT binary patch literal 221 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5$P6SE-Lv|E6k~CayA#8@b22Z19JT{XE z)7O>#CMS~slTdT$Uv{97N{MSkiF1B#Zfaf$LugKFVv2&hr<+1>ZemeMaAH|%kwO>{ z8|fMBn&ov1s9xC9#W95AdU8Sv1LL9-0gFPFJQzfdFr+i3N qcFpp-1ys-D>Eal|aXmRxxSB&0M6M{%=G+?fzL!ODw~ Y;rKiz4|%u#t3bsJp00i_>zopr0Mgtp;{X5v literal 0 HcmV?d00001 diff --git a/pandora_console/images/tree/one_expanded.png b/pandora_console/images/tree/one_expanded.png new file mode 100755 index 0000000000000000000000000000000000000000..577c4bf6ce11e6681c6659e183b4ed56b3893b70 GIT binary patch literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^0zj<5#0(_Uo(seSDaPU;cPEB*=VV?2Ih+ALA+A%m zGc+_b0C{s`mFqw%N`m}?862M7NCR<_yxm;OkH}&M25un`X1sK_?hjCq zy~NYkmHj3U6Q`tt<>G=#Kp`1V7sn8e>&XcUk_K&UOq>cXYFos(k~$i%1adJPxyR(t T>NWQ$P#uG(tDnm{r-UW|iQ6pi literal 0 HcmV?d00001 From 42fdf3bebb0e0c1774e3cd5714c04e5b3687c0eb Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 16 Dec 2014 13:07:20 +0100 Subject: [PATCH 02/92] First commit of new treeview --- pandora_console/operation/tree.php | 7 +++++++ pandora_console/operation/tree2.php | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 pandora_console/operation/tree2.php diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index d941324600..31686037b5 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -14,6 +14,13 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + + +require_once("tree2.php"); +return; +//////////////////////////////////////////////////////////////////////// + + define('ALL', -1); define('NORMAL', 0); define('WARNING', 2); diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php new file mode 100644 index 0000000000..1c77c1d6b7 --- /dev/null +++ b/pandora_console/operation/tree2.php @@ -0,0 +1,18 @@ + \ No newline at end of file From 3e6fde548b40264790b55fc650124384c1e1697c Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Tue, 16 Dec 2014 16:39:00 +0100 Subject: [PATCH 03/92] Working in the new code of treeview --- pandora_console/include/ajax/tree.ajax.php | 33 ++++ pandora_console/include/class/tree.class.php | 158 +++++++++++++++++++ pandora_console/include/constants.php | 122 +++++++------- pandora_console/include/functions_groups.php | 20 ++- pandora_console/operation/tree.php | 2 +- pandora_console/operation/tree2.php | 114 +++++++++++++ 6 files changed, 382 insertions(+), 67 deletions(-) create mode 100644 pandora_console/include/ajax/tree.ajax.php create mode 100644 pandora_console/include/class/tree.class.php mode change 100644 => 100755 pandora_console/include/constants.php diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php new file mode 100644 index 0000000000..40509c6ee1 --- /dev/null +++ b/pandora_console/include/ajax/tree.ajax.php @@ -0,0 +1,33 @@ +set_filter(array( + 'status' => $status, + 'search' => $search)); + echo $tree->get_json(); + return; +} +?> \ No newline at end of file diff --git a/pandora_console/include/class/tree.class.php b/pandora_console/include/class/tree.class.php new file mode 100644 index 0000000000..5a3c8d686d --- /dev/null +++ b/pandora_console/include/class/tree.class.php @@ -0,0 +1,158 @@ +type = $type; + $this->root = $root; + } + + public function set_type($type) { + $this->type = $type; + } + + public function set_filter($filter) { + $this->filter = $filter; + } + + public function get_data() { + switch ($this->type) { + case 'os': + $this->get_data_os(); + break; + case 'group': + $this->get_data_group(); + break; + case 'module_group': + $this->get_data_module_group(); + break; + case 'module': + $this->get_data_module(); + break; + case 'tag': + $this->get_data_tag(); + break; + } + } + + public function get_data_os() { + } + + public function get_data_group() { + $filter = array(); + + if (!empty($this->root)) { + $filter['parent'] = $this->root; + } + else { + $filter['parent'] = 0; + } + if (!empty($this->filter['search'])) { + $filter['nombre'] = "%" . $this->filter['search'] . "%"; + } + + + // First filter by name and father + $groups = db_get_all_rows_filter('tgrupo', + $filter, + array('id_grupo', 'nombre')); + if (empty($groups)) + $groups = array(); + + // Filter by status + $status = AGENT_STATUS_ALL; + if (!empty($this->filter['status'])) { + $status = $this->filter['status']; + } + + if ($status != AGENT_STATUS_ALL) { + foreach ($groups as $iterator => $group) { + $count_ok = groups_monitor_ok( + array($group['id_grupo'])); + $count_critical = groups_monitor_critical( + array($group['id_grupo'])); + $count_warning = groups_monitor_warning( + array($group['id_grupo'])); + $count_unknown = groups_monitor_unknown( + array($group['id_grupo'])); + $count_not_init = groups_monitor_not_init( + array($group['id_grupo'])); + + $remove_group = true; + switch ($status) { + case AGENT_STATUS_NORMAL: + if (($count_critical == 0) && + ($count_warning == 0) && + ($count_unknown == 0) && + ($count_not_init == 0)) { + + $remove_group = false; + } + break; + case AGENT_STATUS_WARNING: + if ($count_warning > 0) + $remove_group = false; + break; + case AGENT_STATUS_CRITICAL: + if ($count_critical > 0) + $remove_group = false; + break; + case AGENT_STATUS_UNKNOWN: + if ($count_unknown > 0) + $remove_group = false; + break; + case AGENT_STATUS_NOT_INIT: + if ($count_not_init > 0) + $remove_group = false; + break; + } + + if ($remove_group) + unset($groups[$iterator]); + } + } + + // Make the data + $this->tree = array(); + foreach ($groups as $group) { + $data = array(); + $data['id'] = $group['id_grupo']; + $data['name'] = $group['nombre']; + + $this->tree[] = $data; + } + } + + public function get_data_module_group() { + } + + public function get_data_module() { + } + + public function get_data_tag() { + } + + public function get_json() { + $this->get_data(); + + return json_encode($this->tree); + } +} +?> diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php old mode 100644 new mode 100755 index 3be630f662..b33ac7fdfa --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -19,25 +19,25 @@ */ /* Enterprise hook constant */ -define ('ENTERPRISE_NOT_HOOK', -1); +define ('ENTERPRISE_NOT_HOOK', -1); /**/ -define('DATE_FORMAT', 'Y/m/d'); -define('DATE_FORMAT_JS', 'yy/mm/d'); -define('TIME_FORMAT', 'H:i:s'); -define('TIME_FORMAT_JS', 'HH:mm:ss'); +define('DATE_FORMAT', 'Y/m/d'); +define('DATE_FORMAT_JS', 'yy/mm/d'); +define('TIME_FORMAT', 'H:i:s'); +define('TIME_FORMAT_JS', 'HH:mm:ss'); /* Events state constants */ -define ('EVENT_NEW', 0); -define ('EVENT_VALIDATE', 1); -define ('EVENT_PROCESS', 2); +define ('EVENT_NEW', 0); +define ('EVENT_VALIDATE', 1); +define ('EVENT_PROCESS', 2); /* Agents disabled status */ -define ('AGENT_ENABLED',0); -define ('AGENT_DISABLED',1); +define ('AGENT_ENABLED', 0); +define ('AGENT_DISABLED', 1); @@ -97,10 +97,10 @@ define('SECONDS_3YEARS', 93312000); /* Separator constats */ -define('SEPARATOR_COLUMN', ';'); -define('SEPARATOR_ROW', chr(10)); //chr(10) = '\n' -define('SEPARATOR_COLUMN_CSV', "#"); -define('SEPARATOR_ROW_CSV', "@\n"); +define('SEPARATOR_COLUMN', ';'); +define('SEPARATOR_ROW', chr(10)); //chr(10) = '\n' +define('SEPARATOR_COLUMN_CSV', "#"); +define('SEPARATOR_ROW_CSV', "@\n"); @@ -108,72 +108,72 @@ define('SEPARATOR_ROW_CSV', "@\n"); switch ($config["dbtype"]) { case "mysql": case "postgresql": - define ('BACKUP_DIR', 'attachment/backups'); - define ('BACKUP_FULLPATH', $config['homedir'] . '/' . BACKUP_DIR); + define ('BACKUP_DIR', 'attachment/backups'); + define ('BACKUP_FULLPATH', $config['homedir'] . '/' . BACKUP_DIR); break; case "oracle": - define ('BACKUP_DIR', 'DATA_PUMP_DIR'); - define ('BACKUP_FULLPATH', 'DATA_PUMP_DIR'); + define ('BACKUP_DIR', 'DATA_PUMP_DIR'); + define ('BACKUP_FULLPATH', 'DATA_PUMP_DIR'); break; } /* Color constants */ -define('COL_CRITICAL','#f85858'); -define('COL_WARNING','#ffea59'); -define('COL_WARNING_DARK','#FFB900'); -define('COL_NORMAL','#6EB432'); -define('COL_NOTINIT','#3BA0FF'); -define('COL_UNKNOWN','#AAAAAA'); -define('COL_ALERTFIRED','#FF8800'); -define('COL_MINOR','#F099A2'); -define('COL_MAJOR','#C97A4A'); -define('COL_INFORMATIONAL','#E4E4E4'); -define('COL_MAINTENANCE','#3BA0FF'); +define('COL_CRITICAL', '#f85858'); +define('COL_WARNING', '#ffea59'); +define('COL_WARNING_DARK', '#FFB900'); +define('COL_NORMAL', '#6EB432'); +define('COL_NOTINIT', '#3BA0FF'); +define('COL_UNKNOWN', '#AAAAAA'); +define('COL_ALERTFIRED', '#FF8800'); +define('COL_MINOR', '#F099A2'); +define('COL_MAJOR', '#C97A4A'); +define('COL_INFORMATIONAL', '#E4E4E4'); +define('COL_MAINTENANCE', '#3BA0FF'); -define('COL_GRAPH1', '#C397F2'); -define('COL_GRAPH2', '#FFE66C'); -define('COL_GRAPH3', '#92CCA3'); -define('COL_GRAPH4', '#EA6D5B'); -define('COL_GRAPH5', '#6BD8DD'); -define('COL_GRAPH6', '#F49B31'); -define('COL_GRAPH7', '#999999'); -define('COL_GRAPH8', '#F2B8C1'); -define('COL_GRAPH9', '#C4E8C1'); -define('COL_GRAPH10', '#C1DBE5'); -define('COL_GRAPH11', '#C9C1e0'); -define('COL_GRAPH12', '#F45B95'); -define('COL_GRAPH13', '#E83128'); +define('COL_GRAPH1', '#C397F2'); +define('COL_GRAPH2', '#FFE66C'); +define('COL_GRAPH3', '#92CCA3'); +define('COL_GRAPH4', '#EA6D5B'); +define('COL_GRAPH5', '#6BD8DD'); +define('COL_GRAPH6', '#F49B31'); +define('COL_GRAPH7', '#999999'); +define('COL_GRAPH8', '#F2B8C1'); +define('COL_GRAPH9', '#C4E8C1'); +define('COL_GRAPH10', '#C1DBE5'); +define('COL_GRAPH11', '#C9C1e0'); +define('COL_GRAPH12', '#F45B95'); +define('COL_GRAPH13', '#E83128'); /* The styles */ /* Size of text in characters for truncate */ -define('GENERIC_SIZE_TEXT', 25); +define('GENERIC_SIZE_TEXT', 25); /* Agent module status */ -define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1); -define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100); -define('AGENT_MODULE_STATUS_NO_DATA', 4); -define('AGENT_MODULE_STATUS_NORMAL', 0); -define('AGENT_MODULE_STATUS_NORMAL_ALERT', 300); -define('AGENT_MODULE_STATUS_NOT_NORMAL', 6); -define('AGENT_MODULE_STATUS_WARNING', 2); -define('AGENT_MODULE_STATUS_WARNING_ALERT', 200); -define('AGENT_MODULE_STATUS_UNKNOWN', 3); -define('AGENT_MODULE_STATUS_NOT_INIT', 5); +define('AGENT_MODULE_STATUS_CRITICAL_BAD', 1); +define('AGENT_MODULE_STATUS_CRITICAL_ALERT', 100); +define('AGENT_MODULE_STATUS_NO_DATA', 4); +define('AGENT_MODULE_STATUS_NORMAL', 0); +define('AGENT_MODULE_STATUS_NORMAL_ALERT', 300); +define('AGENT_MODULE_STATUS_NOT_NORMAL', 6); +define('AGENT_MODULE_STATUS_WARNING', 2); +define('AGENT_MODULE_STATUS_WARNING_ALERT', 200); +define('AGENT_MODULE_STATUS_UNKNOWN', 3); +define('AGENT_MODULE_STATUS_NOT_INIT', 5); /* Agent status */ -define('AGENT_STATUS_ALL', -1); -define('AGENT_STATUS_CRITICAL', 1); -define('AGENT_STATUS_NORMAL', 0); -define('AGENT_STATUS_NOT_INIT', 5); -define('AGENT_STATUS_NOT_NORMAL', 6); -define('AGENT_STATUS_UNKNOWN', 3); -define('AGENT_STATUS_ALERT_FIRED', 4); -define('AGENT_STATUS_WARNING', 2); +define('AGENT_STATUS_ALL', -1); +define('AGENT_STATUS_CRITICAL', 1); +define('AGENT_STATUS_NORMAL', 0); +define('AGENT_STATUS_NOT_INIT', 5); +define('AGENT_STATUS_NOT_NORMAL', 6); +define('AGENT_STATUS_UNKNOWN', 3); +define('AGENT_STATUS_ALERT_FIRED', 4); +define('AGENT_STATUS_WARNING', 2); /* Visual maps contants */ diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index c07aae0ae0..33c24f5e7d 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -278,8 +278,12 @@ function groups_get_parents($parent, $onlyPropagate = false, $groups = null) { continue; } - if (($group['id_grupo'] == $parent) && ($group['propagate'] || !$onlyPropagate)) { - $return = $return + array($group['id_grupo'] => $group) + groups_get_parents($group['parent'], $onlyPropagate, $groups); + if (($group['id_grupo'] == $parent) + && ($group['propagate'] || !$onlyPropagate)) { + + $return = $return + + array($group['id_grupo'] => $group) + + groups_get_parents($group['parent'], $onlyPropagate, $groups); } } @@ -1303,7 +1307,9 @@ function groups_monitor_ok ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(normal_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(normal_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } @@ -1326,7 +1332,9 @@ function groups_monitor_critical ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(critical_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(critical_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } @@ -1372,7 +1380,9 @@ function groups_monitor_unknown ($group_array) { $group_clause = "(" . $group_clause . ")"; //TODO REVIEW ORACLE AND POSTGRES - $count = db_get_sql ("SELECT SUM(unknown_count) FROM tagente WHERE disabled = 0 AND id_grupo IN $group_clause"); + $count = db_get_sql ("SELECT SUM(unknown_count) + FROM tagente + WHERE disabled = 0 AND id_grupo IN $group_clause"); return $count > 0 ? $count : 0; } diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 31686037b5..ca73cd5f1f 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -17,7 +17,7 @@ require_once("tree2.php"); -return; +//~ return; //////////////////////////////////////////////////////////////////////// diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 1c77c1d6b7..e04cfb1945 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -14,5 +14,119 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +global $config; +require_once("include/class/tree.class.php"); + +$tab = get_parameter('tab', 'group'); +$search = get_parameter('search', ''); +$status = get_parameter('status', AGENT_STATUS_ALL); + + +// ---------------------Tabs ------------------------------------------- +$url = 'index.php?' . + 'sec=estado&' . + 'sec2=operation/tree&' . + 'refr=0&' . + 'pure=' . (int)get_parameter('pure', 0) . '&' . + 'tab=%s'; + +$tabs = array(); +$tabs['os'] = array( + 'text' => "" . + html_print_image("images/operating_system.png", true, + array("title" => __('OS'))) . "", + 'active' => ($tab == "os")); + +$tabs['group'] = array( + 'text' => "" . + html_print_image("images/group.png", true, + array("title" => __('Groups'))) . "", + 'active' => ($tab == "group")); + +$tabs['module_group'] = array( + 'text' => "" . + html_print_image("images/module_group.png", true, + array("title" => __('Module groups'))) . "", + 'active' => ($tab == "module_group")); + +$tabs['module'] = array( + 'text' => "" . + html_print_image("images/brick.png", true, + array("title" => __('Modules'))) . "", + 'active' => ($tab == "module")); + +$tabs['tag'] = array( + 'text' => "" . + html_print_image("images/tag.png", true, + array("title" => __('Tags'))) . "", + 'active' => ($tab == "tag")); + +$header_title = ""; +switch ($tab) { + case 'os': + $header_title = + __('Tree view - Sort the agents by OS'); + break; + case 'group': + $header_title = + __('Tree view - Sort the agents by groups'); + break; + case 'module_group': + $header_title = + __('Tree view - Sort the agents by module groups'); + break; + case 'module': + $header_title = + __('Tree view - Sort the agents by modules'); + break; + case 'tag': + $header_title = + __('Tree view - Sort the agents by tags'); + break; +} + +ui_print_page_header( + $header_title, "images/extensions.png", false, "", false, $tabs); +// ---------------------Tabs ------------------------------------------- + + +// --------------------- form filter ----------------------------------- +$table = null; +$table->width = "100%"; + +$table->data[0][0] = __('Agent status'); +$fields = array (); +$fields[AGENT_STATUS_ALL] = __('All'); //default +$fields[AGENT_STATUS_NORMAL] = __('Normal'); +$fields[AGENT_STATUS_WARNING] = __('Warning'); +$fields[AGENT_STATUS_CRITICAL] = __('Critical'); +$fields[AGENT_STATUS_UNKNOWN] = __('Unknown'); +$fields[AGENT_STATUS_NOT_INIT] = __('Not init'); +$table->data[0][1] = html_print_select($fields, + "status", + $status, + '', + '', + 0, + true); +$table->data[0][2] = __('Search agent'); +$table->data[0][3] = html_print_input_text( + "search", $search, '', 40, 30, true); +$table->data[0][4] = html_print_submit_button( + __('Filter'), "uptbutton", false, 'class="sub search"', true); + +html_print_table($table); + +// --------------------- form filter ----------------------------------- + + + +$tree = new Tree($tab); +$tree->set_filter(array( + 'status' => $status, + 'search' => $search)); +$json_tree = $tree->get_json(); + +html_debug_print($json_tree); ?> \ No newline at end of file From b308647144009ebbbb5c1faace84741ddb1a431a Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 16 Dec 2014 18:31:18 +0100 Subject: [PATCH 04/92] Added new style rules to the new tree view --- pandora_console/include/styles/pandora.css | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 596da5ec98..1b797e86a5 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2833,4 +2833,51 @@ table#policy_modules td * { .left_align { text-align: left; +} + +/* Tree view styles */ +.tree-group { + margin-left: 16px; +} + +.tree-node { + white-space: nowrap; + + background-image: url(../../images/tree/branch.png); + background-position: 0px 0px; + background-repeat: repeat-y; +} + +.tree-last { + background: 0 0; +} + +.leaf-icon { + width: 20px; + height: 20px; +} + +.node-content, .leaf-icon { + display: inline-block; +} + +.tree-node.leaf-open>.leaf-icon { + background-image: url(../../images/tree/last_expanded.png); +} + +.tree-node.leaf-closed>.leaf-icon { + background-image: url(../../images/tree/last_closed.png); +} + +.tree-node.leaf-loading>.leaf-icon { + background-image: url(../../images/tree/last_expanded.png); +} + +.tree-node.leaf-empty>.leaf-icon { + background-image: url(../../images/tree/last_leaf.png); +} + +.tree-node>.leaf-icon { + background-position: 0px 0px; + background-repeat: no-repeat; } \ No newline at end of file From 4b24052df4a819202787d0918d532133cb76fec1 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 16 Dec 2014 18:32:01 +0100 Subject: [PATCH 05/92] Added a new controller to process and show the tree data --- .../include/javascript/tree/TreeController.js | 266 ++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 pandora_console/include/javascript/tree/TreeController.js diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js new file mode 100644 index 0000000000..d3649d9318 --- /dev/null +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -0,0 +1,266 @@ +// Pandora FMS - http://pandorafms.com +// ================================================== +// Copyright (c) 2005-2010 Artica Soluciones Tecnologicas +// Please see http://pandorafms.org for full contribution list + +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License +// as published by the Free Software Foundation; version 2 + +// 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. + +TreeController = { + controllers: [], + getController: function () { + var controller = { + index: -1, + recipient: '', + tree: [], + emptyMessage: "Empty", + errorMessage: "Error", + ajaxURL: "ajax.php", + ajaxPage: "include/ajax/tree.ajax.php", + reload: function () { + if (typeof this.recipient == 'undefined' || this.recipient.length == 0) { + return; + } + + function _processGroup (container, elements) { + var $group = $("
    "); + $group + .addClass("tree-group") + .hide(); + + container.append($group); + + var last; + elements.forEach(function(element, index) { + last = index == elements.length - 1 ? true : false; + element.jqObject = _processNode($group, element, last); + }, $group); + + return $group; + } + function _processNode (container, element, last) { + var $node = $("
  • "); + var $leafIcon = $("
    "); + var $content = $("
    "); + + // Leaf icon + $leafIcon.addClass("leaf-icon"); + + // Content + $content.addClass("node-content"); + switch (element.type) { + case 'group': + $content.append(element.name); + break; + case 'agent': + $content.append(element.name); + break; + } + + $node + .addClass("tree-node") + .append($leafIcon) + .append($content); + + if (typeof last != 'undefinded' && last == true) { + $node.addClass("tree-last"); + } + + container.append($node); + + if (typeof element.children != 'undefined' && element.children.length > 0) { + $node.addClass("leaf-closed"); + + // Add children + var $children = _processGroup($node, element.children); + $node.data('children', $children); + + $leafIcon.click(function () { + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + }); + } + else if (typeof element.searchChildren != 'undefined' && element.searchChildren) { + $node.addClass("leaf-closed"); + + $leafIcon.click(function () { + if (! $node.hasClass("children-loaded")) { + $node + .removeClass("leaf-closed") + .removeClass("leaf-error") + .addClass("leaf-loading"); + + $.ajax({ + url: this.ajaxURL, + type: 'POST', + dataType: 'json', + data: { + page: this.ajaxPage, + getChildren: 1, + id: element.id, + type: element.type + }, + complete: function(xhr, textStatus) { + $node.removeClass("leaf-loading"); + }, + success: function(data, textStatus, xhr) { + if (data.success) { + $node.addClass("leaf-open"); + + var $children = _processGroup($node, data.elements); + $children.slideDown(); + + $node.data('children', $children); + } + else { + $node.addClass("leaf-error"); + } + }, + error: function(xhr, textStatus, errorThrown) { + $node.addClass("leaf-error"); + } + }); + } + else { + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + } + }); + } + else { + $node.addClass("leaf-empty"); + } + + return $node; + } + + if (this.recipient.length == 0) { + return; + } + else if (this.tree.length == 0) { + this.recipient.html("
    " + this.emptyMessage + "
    "); + return; + } + + this.recipient.empty(); + + var $loadingImage = $(''); + + var $children = _processGroup(this.recipient, this.tree); + $children.show(); + + this.recipient.data('children', $children); + + // $.ajax({ + // url: this.ajaxURL, + // type: 'POST', + // dataType: 'json', + // data: { + // page: this.ajaxPage, + // getChildren: 1, + // type: element.type + // }, + // complete: function(xhr, textStatus) { + // $loadingImage.remove(); + // }, + // success: function(data, textStatus, xhr) { + // if (data.success) { + // var $children = _processGroup(this.recipient, data.elements); + // $children.show(); + + // this.recipient.data('children', $children); + // } + // else { + // $loadingImage.remove(); + // this.recipient.html("
    " + this.errorMessage + "
    "); + // } + // }, + // error: function(xhr, textStatus, errorThrown) { + // this.recipient.html("
    " + this.errorMessage + "
    "); + // } + // }); + }, + load: function () { + this.reload(); + }, + changeTree: function (tree) { + this.tree = tree; + this.reload(); + }, + addLeaf: function (leaf) { + // this.tree.unshift(leaf); + // this.reload(); + }, + removeLeaf: function (leafID) { + if (leafID != 0 && this.tree.length > 0) { + this.tree.splice(leafID, 1); + this.reload(); + } + }, + init: function (data) { + if (typeof data.recipient != 'undefined' && data.recipient.length > 0) { + this.recipient = data.recipient; + } + if (typeof data.tree != 'undefined' && data.tree.length > 0) { + this.tree = data.tree; + } + if (typeof data.emptyMessage != 'undefined' && data.emptyMessage.length > 0) { + this.emptyMessage = data.emptyMessage; + } + if (typeof data.errorMessage != 'undefined' && data.errorMessage.length > 0) { + this.errorMessage = data.errorMessage; + } + if (typeof data.ajaxURL != 'undefined' && data.ajaxURL.length > 0) { + this.ajaxURL = data.ajaxURL; + } + if (typeof data.ajaxPage != 'undefined' && data.ajaxPage.length > 0) { + this.ajaxPage = data.ajaxPage; + } + + this.index = TreeController.controllers.push(this) - 1; + this.load(); + }, + remove: function () { + if (typeof this.recipient == 'undefined' || this.recipient.length > 0) { + return; + } + + this.recipient.empty(); + if (this.index > -1) { + TreeController.controllers.splice(this.index, 1); + } + } + } + return controller; + } +} \ No newline at end of file From 9857fa477b3713bac28b467b67535e73787ee6ee Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Tue, 16 Dec 2014 19:57:48 +0100 Subject: [PATCH 06/92] Updated the tree style --- .../include/javascript/tree/TreeController.js | 75 ++++++------------- pandora_console/include/styles/pandora.css | 13 ++++ 2 files changed, 37 insertions(+), 51 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index d3649d9318..0ed884d19a 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -28,23 +28,34 @@ TreeController = { return; } - function _processGroup (container, elements) { + function _processGroup (container, elements, rootGroup) { var $group = $("
      "); - $group - .addClass("tree-group") - .hide(); + + if (typeof rootGroup != 'undefinded' && rootGroup == true) { + $group + .addClass("tree-root") + .hide(); + } + else { + rootGroup = false; + $group + .addClass("tree-group") + .hide(); + } container.append($group); - var last; + var lastNode; + var firstNode; elements.forEach(function(element, index) { - last = index == elements.length - 1 ? true : false; - element.jqObject = _processNode($group, element, last); + lastNode = index == elements.length - 1 ? true : false; + firstNode = rootGroup && index == 0 ? true : false; + element.jqObject = _processNode($group, element, lastNode, firstNode); }, $group); return $group; } - function _processNode (container, element, last) { + function _processNode (container, element, lastNode, firstNode) { var $node = $("
    • "); var $leafIcon = $("
      "); var $content = $("
      "); @@ -68,9 +79,12 @@ TreeController = { .append($leafIcon) .append($content); - if (typeof last != 'undefinded' && last == true) { + if (typeof lastNode != 'undefinded' && lastNode == true) { $node.addClass("tree-last"); } + if (typeof firstNode != 'undefinded' && firstNode == true) { + $node.addClass("tree-first"); + } container.append($node); @@ -174,41 +188,10 @@ TreeController = { this.recipient.empty(); - var $loadingImage = $(''); - - var $children = _processGroup(this.recipient, this.tree); + var $children = _processGroup(this.recipient, this.tree, true); $children.show(); this.recipient.data('children', $children); - - // $.ajax({ - // url: this.ajaxURL, - // type: 'POST', - // dataType: 'json', - // data: { - // page: this.ajaxPage, - // getChildren: 1, - // type: element.type - // }, - // complete: function(xhr, textStatus) { - // $loadingImage.remove(); - // }, - // success: function(data, textStatus, xhr) { - // if (data.success) { - // var $children = _processGroup(this.recipient, data.elements); - // $children.show(); - - // this.recipient.data('children', $children); - // } - // else { - // $loadingImage.remove(); - // this.recipient.html("
      " + this.errorMessage + "
      "); - // } - // }, - // error: function(xhr, textStatus, errorThrown) { - // this.recipient.html("
      " + this.errorMessage + "
      "); - // } - // }); }, load: function () { this.reload(); @@ -217,16 +200,6 @@ TreeController = { this.tree = tree; this.reload(); }, - addLeaf: function (leaf) { - // this.tree.unshift(leaf); - // this.reload(); - }, - removeLeaf: function (leafID) { - if (leafID != 0 && this.tree.length > 0) { - this.tree.splice(leafID, 1); - this.reload(); - } - }, init: function (data) { if (typeof data.recipient != 'undefined' && data.recipient.length > 0) { this.recipient = data.recipient; diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 1b797e86a5..34a899ba8f 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2838,6 +2838,7 @@ table#policy_modules td * { /* Tree view styles */ .tree-group { margin-left: 16px; + padding-top: 4px; } .tree-node { @@ -2865,10 +2866,18 @@ table#policy_modules td * { background-image: url(../../images/tree/last_expanded.png); } +.tree-node.tree-first.leaf-open>.leaf-icon { + background-image: url(../../images/tree/first_expanded.png); +} + .tree-node.leaf-closed>.leaf-icon { background-image: url(../../images/tree/last_closed.png); } +.tree-node.tree-first.leaf-closed>.leaf-icon { + background-image: url(../../images/tree/first_closed.png); +} + .tree-node.leaf-loading>.leaf-icon { background-image: url(../../images/tree/last_expanded.png); } @@ -2877,6 +2886,10 @@ table#policy_modules td * { background-image: url(../../images/tree/last_leaf.png); } +.tree-node.tree-first.leaf-empty>.leaf-icon { + background-image: url(../../images/tree/first_leaf.png); +} + .tree-node>.leaf-icon { background-position: 0px 0px; background-repeat: no-repeat; From 9d29ad63e47db1891eef7b4345baad18df6e1ded Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 12:26:41 +0100 Subject: [PATCH 07/92] Added test code --- pandora_console/operation/tree.php | 89 ++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index ca73cd5f1f..3d1dec427a 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -691,6 +691,10 @@ enterprise_hook('close_meta_frame'); ui_include_time_picker(); ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); +ui_require_javascript_file("TreeController", "include/javascript/tree/"); +echo "
      "; +//echo html_print_image ("images/pandora.ico.gif", true); +echo "
      "; ?> From d3e9e98e305cb7d60e1e282725c5099d3e1140e8 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 13:47:40 +0100 Subject: [PATCH 08/92] Improved the visual style --- pandora_console/include/styles/pandora.css | 5 +++++ pandora_console/operation/tree.php | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 34a899ba8f..e032158767 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2836,6 +2836,11 @@ table#policy_modules td * { } /* Tree view styles */ +.tree-root { + margin-top: 0px; + margin-bottom: 0px; +} + .tree-group { margin-left: 16px; padding-top: 4px; diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 3d1dec427a..4997e8e221 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -692,9 +692,7 @@ ui_include_time_picker(); ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); ui_require_javascript_file("TreeController", "include/javascript/tree/"); -echo "
      "; -//echo html_print_image ("images/pandora.ico.gif", true); -echo "
      "; +echo "
      "; ?> \ No newline at end of file From a97074a3b76333d5c9193208af432bf81d7da658 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 19:11:07 +0100 Subject: [PATCH 11/92] Too lazy to explain --- .../include/javascript/tree/TreeController.js | 243 +++++++++++++++++- pandora_console/operation/tree.php | 7 +- 2 files changed, 238 insertions(+), 12 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index d83e4dd5cb..dc248fc571 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -12,6 +12,9 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. +var TreeController; +var TreeNodeDetailController; + TreeController = { controllers: [], getController: function () { @@ -24,20 +27,25 @@ TreeController = { baseURL: "", ajaxURL: "ajax.php", ajaxPage: "include/ajax/tree.ajax.php", + detailRecipient: '', reload: function () { + // Bad recipient if (typeof this.recipient == 'undefined' || this.recipient.length == 0) { return; } - - function _processGroup (container, elements, baseURL, rootGroup) { + + // Load branch + function _processGroup (container, detailContainer, elements, baseURL, rootGroup) { var $group = $("
        "); + // First group if (typeof rootGroup != 'undefinded' && rootGroup == true) { $group .addClass("tree-root") .hide() - .prepend(''); + .prepend(''); } + // Normal group else { rootGroup = false; $group @@ -52,12 +60,13 @@ TreeController = { elements.forEach(function(element, index) { lastNode = index == elements.length - 1 ? true : false; firstNode = rootGroup && index == 0 ? true : false; - element.jqObject = _processNode($group, element, lastNode, firstNode); + element.jqObject = _processNode($group, detailRecipient, element, lastNode, firstNode); }, $group); return $group; } - function _processNode (container, element, lastNode, firstNode) { + // Load leaf + function _processNode (container, detailContainer, element, lastNode, firstNode) { var $node = $("
      • "); var $leafIcon = $("
        "); var $content = $("
        "); @@ -74,6 +83,22 @@ TreeController = { case 'agent': $content.append(element.name); break; + default: + $content.append(element.name); + break; + } + // If exist the detail container, show the data + if (typeof detailContainer != 'undefined' && detailContainer.length > 0) { + $content.click(function (e) { + TreeNodeDetailController.getController().init({ + recipient: controller.detailRecipient, + type: element.type, + id: element.id, + baseURL: controller.baseURL, + ajaxURL: controller.ajaxURL, + ajaxPage: controller.ajaxPage + }); + }); } $node @@ -94,7 +119,7 @@ TreeController = { $node.addClass("leaf-closed"); // Add children - var $children = _processGroup($node, element.children, this.baseURL); + var $children = _processGroup($node, this.detailContainer, element.children, this.baseURL); $node.data('children', $children); $leafIcon.click(function () { @@ -141,7 +166,7 @@ TreeController = { if (data.success) { $node.addClass("leaf-open"); - var $children = _processGroup($node, data.elements, this.baseURL); + var $children = _processGroup($node, this.detailContainer, data.elements, this.baseURL); $children.slideDown(); $node.data('children', $children); @@ -190,7 +215,7 @@ TreeController = { this.recipient.empty(); - var $children = _processGroup(this.recipient, this.tree, this.baseURL, true); + var $children = _processGroup(this.recipient, this.detailContainer, this.tree, this.baseURL, true); $children.show(); this.recipient.data('children', $children); @@ -206,6 +231,9 @@ TreeController = { if (typeof data.recipient != 'undefined' && data.recipient.length > 0) { this.recipient = data.recipient; } + if (typeof data.detailRecipient != 'undefined' && data.detailRecipient.length > 0) { + this.detailRecipient = data.detailRecipient; + } if (typeof data.tree != 'undefined' && data.tree.length > 0) { this.tree = data.tree; } @@ -229,11 +257,10 @@ TreeController = { this.load(); }, remove: function () { - if (typeof this.recipient == 'undefined' || this.recipient.length > 0) { - return; + if (typeof this.recipient != 'undefined' && this.recipient.length > 0) { + this.recipient.empty(); } - this.recipient.empty(); if (this.index > -1) { TreeController.controllers.splice(this.index, 1); } @@ -241,4 +268,198 @@ TreeController = { } return controller; } +} + +// The controllers will be inside the 'controllers' object, +// ordered by ['type']['id'] +TreeNodeDetailController = { + controllers: {}, + controllerExist: function (type, id) { + if (typeof this.controllers[type][id] != 'undefined') { + return true; + } + else { + return false; + } + }, + removeControllers: function () { + TreeNodeDetailController.controllers.forEach(function(elements, type) { + elements.forEach(function(element, id) { + element.remove(); + }); + }); + }, + getController: function () { + var controller = { + recipient: '', + type: 'none', + id: -1, + emptyMessage: "Empty", + errorMessage: "Error", + baseURL: "", + ajaxURL: "ajax.php", + ajaxPage: "include/ajax/tree.ajax.php", + container: '', + reload: function () { + // Label + var $label = $("
        "); + $label + .addClass("tree-element-detail-label") + .click(function (e) { + if ($label.hasClass('tree-element-detail-loaded')) + controller.toggle(); + }); + + // Content + var $content = $("
        "); + $content.addClass("tree-element-detail-content"); + + $label.addClass('tree-element-detail-loading'); + $.ajax({ + url: this.ajaxURL, + type: 'POST', + dataType: 'json', + data: { + page: this.ajaxURL, + getDetail: 1, + type: this.type, + id: this.id + }, + complete: function(xhr, textStatus) { + $label.removeClass('tree-element-detail-loading'); + }, + success: function(data, textStatus, xhr) { + if (data.success) { + $label.addClass('tree-element-detail-loaded'); + $content.append(data.html); + controller.open(); + } + else { + $label.addClass('tree-element-detail-error'); + $content.html(controller.errorMessage); + } + }, + error: function(xhr, textStatus, errorThrown) { + $label.addClass('tree-element-detail-error'); + $content.html(controller.errorMessage); + } + }); + + + // Container + this.container = $("
        "); + this.container + .addClass("tree-element-detail") + .append($label) + .data('label', $label) + .append($content) + .data('content', $content) + .hide(); + + this.recipient.append(this.container); + this.open(); + }, + load: function () { + this.reload(); + }, + toggle: function () { + if (typeof this.container != 'undefined' && this.container.length > 0) { + return false; + } + if (this.container.isClosed) { + this.open(); + } + else { + this.close(); + } + }, + open: function () { + if (typeof this.container != 'undefined' && this.container.length > 0) { + return false; + } + if (this.container.isClosed) { + this.container.data('content').slideLeft(); + this.container.isClosed = false; + } + }, + close: function () { + if (typeof this.container != 'undefined' && this.container.length > 0) { + return false; + } + if (!this.container.isClosed) { + this.container.data('content').slideRight(); + this.container.isClosed = true; + } + }, + init: function (data) { + // Remove the other controllers + TreeNodeDetailController.removeControllers(); + + // Required + if (typeof data.recipient != 'undefined' && data.recipient.length > 0) { + this.recipient = data.recipient; + } + else { + return false; + } + // Required + if (typeof data.type != 'undefined' && data.type.length > 0) { + this.type = data.type; + } + else { + return false; + } + // Required + if (typeof data.id != 'undefined' && data.id.length > 0) { + this.id = data.id; + } + else { + return false; + } + if (typeof data.emptyMessage != 'undefined' && data.emptyMessage.length > 0) { + this.emptyMessage = data.emptyMessage; + } + if (typeof data.errorMessage != 'undefined' && data.errorMessage.length > 0) { + this.errorMessage = data.errorMessage; + } + if (typeof data.baseURL != 'undefined' && data.baseURL.length > 0) { + this.baseURL = data.baseURL; + } + if (typeof data.ajaxURL != 'undefined' && data.ajaxURL.length > 0) { + this.ajaxURL = data.ajaxURL; + } + if (typeof data.ajaxPage != 'undefined' && data.ajaxPage.length > 0) { + this.ajaxPage = data.ajaxPage; + } + + TreeNodeDetailController.controllers[this.type][this.id] = this; + this.load(); + }, + remove: function () { + if (typeof this.recipient != 'undefined' && this.recipient.length > 0) { + this.recipient.empty(); + } + if (this.type != 'none' && this.id > -1) { + delete TreeNodeDetailController.controllers[this.type][this.id]; + } + }, + closeOther: function () { + TreeNodeDetailController.controllers.forEach(function(elements, type) { + elements.forEach(function(element, id) { + if (this.type != type && this.id != id) + element.close(); + }, this); + }, this); + }, + removeOther: function () { + TreeNodeDetailController.controllers.forEach(function(elements, type) { + elements.forEach(function(element, id) { + if (this.type != type && this.id != id) + element.remove(); + }, this); + }, this); + } + } + return controller; + } } \ No newline at end of file diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index 4997e8e221..60d139ddaa 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -693,6 +693,7 @@ ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascri ui_require_javascript_file("TreeController", "include/javascript/tree/"); echo "
        "; +echo "
        "; ?> From a9b096131dc518e52ec1de5e6846e537fa57a560 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 19:45:09 +0100 Subject: [PATCH 12/92] Fixes --- .../include/javascript/tree/TreeController.js | 19 +++++++++++-------- pandora_console/include/styles/pandora.css | 4 ++++ pandora_console/operation/tree.php | 5 ++--- pandora_console/operation/tree2.php | 6 ++++-- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index fa35444678..d0a6757273 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -26,7 +26,7 @@ TreeController = { errorMessage: "Error", baseURL: "", ajaxURL: "ajax.php", - ajaxPage: "include/ajax/tree.ajax.php", + ajaxPage: "include/ajax/tree.ajax", detailRecipient: '', reload: function () { // Bad recipient @@ -60,7 +60,7 @@ TreeController = { elements.forEach(function(element, index) { lastNode = index == elements.length - 1 ? true : false; firstNode = rootGroup && index == 0 ? true : false; - element.jqObject = _processNode($group, detailRecipient, element, lastNode, firstNode); + element.jqObject = _processNode($group, detailContainer, element, lastNode, firstNode); }, $group); return $group; @@ -119,7 +119,7 @@ TreeController = { $node.addClass("leaf-closed"); // Add children - var $children = _processGroup($node, this.detailContainer, element.children, this.baseURL); + var $children = _processGroup($node, detailContainer, element.children, this.baseURL); $node.data('children', $children); $leafIcon.click(function () { @@ -142,7 +142,9 @@ TreeController = { else if (typeof element.searchChildren != 'undefined' && element.searchChildren) { $node.addClass("leaf-closed"); - $leafIcon.click(function () { + $leafIcon.click(function (e) { + e.preventDefault(); + if (! $node.hasClass("children-loaded")) { $node .removeClass("leaf-closed") @@ -150,23 +152,24 @@ TreeController = { .addClass("leaf-loading"); $.ajax({ - url: this.ajaxURL, + url: controller.ajaxURL, type: 'POST', dataType: 'json', data: { - page: this.ajaxPage, + page: controller.ajaxPage, getChildren: 1, id: element.id, type: element.type }, complete: function(xhr, textStatus) { $node.removeClass("leaf-loading"); + $node.addClass("children-loaded") }, success: function(data, textStatus, xhr) { if (data.success) { $node.addClass("leaf-open"); - var $children = _processGroup($node, this.detailContainer, data.elements, this.baseURL); + var $children = _processGroup($node, detailContainer, data.tree, controller.baseURL); $children.slideDown(); $node.data('children', $children); @@ -298,7 +301,7 @@ TreeNodeDetailController = { errorMessage: "Error", baseURL: "", ajaxURL: "ajax.php", - ajaxPage: "include/ajax/tree.ajax.php", + ajaxPage: "include/ajax/tree.ajax", container: '', reload: function () { // Label diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index e032158767..31bbda4342 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2895,6 +2895,10 @@ table#policy_modules td * { background-image: url(../../images/tree/first_leaf.png); } +.tree-node.leaf-error>.leaf-icon { + background-image: url(../../images/tree/last_leaf.png); +} + .tree-node>.leaf-icon { background-position: 0px 0px; background-repeat: no-repeat; diff --git a/pandora_console/operation/tree.php b/pandora_console/operation/tree.php index d20ee435cd..cf0b52f1da 100755 --- a/pandora_console/operation/tree.php +++ b/pandora_console/operation/tree.php @@ -1056,8 +1056,7 @@ echo "
        "; recipient: $("div#tree-controller-recipient"), detailRecipient: $("div#tree-controller-detail-recipient"), tree: tree, - baseURL: "", - ajaxURL: "/ajax.php", - ajaxPage: "/include/ajax/tree.ajax.php" + baseURL: "/", + ajaxURL: "/ajax.php" }); diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 144f0793fd..74918881a8 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -139,7 +139,7 @@ echo ""; $.ajax({ type: "POST", - url: "", + url: "/ajax.php", data: parameters, success: function(data) { if (data.success) { @@ -148,7 +148,9 @@ echo ""; treeController.init({ recipient: $("div#tree-controller-recipient"), page: page, - tree: data.tree + tree: data.tree, + baseURL: "/", + ajaxURL: "/ajax.php" }); } }, From a098b2f6590ca57321b19e2dbadaae923dba7497 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 19:46:33 +0100 Subject: [PATCH 13/92] Fixes --- .../include/javascript/tree/TreeController.js | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index d0a6757273..07e92c1f7b 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -28,12 +28,13 @@ TreeController = { ajaxURL: "ajax.php", ajaxPage: "include/ajax/tree.ajax", detailRecipient: '', + filter: {}, reload: function () { // Bad recipient if (typeof this.recipient == 'undefined' || this.recipient.length == 0) { return; } - + // Load branch function _processGroup (container, detailContainer, elements, baseURL, rootGroup) { var $group = $("
          "); @@ -52,9 +53,9 @@ TreeController = { .addClass("tree-group") .hide(); } - + container.append($group); - + var lastNode; var firstNode; elements.forEach(function(element, index) { @@ -62,7 +63,7 @@ TreeController = { firstNode = rootGroup && index == 0 ? true : false; element.jqObject = _processNode($group, detailContainer, element, lastNode, firstNode); }, $group); - + return $group; } // Load leaf @@ -70,10 +71,10 @@ TreeController = { var $node = $("
        • "); var $leafIcon = $("
          "); var $content = $("
          "); - + // Leaf icon $leafIcon.addClass("leaf-icon"); - + // Content $content.addClass("node-content"); switch (element.type) { @@ -100,28 +101,28 @@ TreeController = { }); }); } - + $node .addClass("tree-node") .append($leafIcon) .append($content); - + if (typeof lastNode != 'undefinded' && lastNode == true) { $node.addClass("tree-last"); } if (typeof firstNode != 'undefinded' && firstNode == true) { $node.addClass("tree-first"); } - + container.append($node); - + if (typeof element.children != 'undefined' && element.children.length > 0) { $node.addClass("leaf-closed"); - + // Add children var $children = _processGroup($node, detailContainer, element.children, this.baseURL); $node.data('children', $children); - + $leafIcon.click(function () { if ($node.hasClass("leaf-open")) { $node @@ -141,7 +142,7 @@ TreeController = { } else if (typeof element.searchChildren != 'undefined' && element.searchChildren) { $node.addClass("leaf-closed"); - + $leafIcon.click(function (e) { e.preventDefault(); @@ -150,7 +151,7 @@ TreeController = { .removeClass("leaf-closed") .removeClass("leaf-error") .addClass("leaf-loading"); - + $.ajax({ url: controller.ajaxURL, type: 'POST', @@ -159,7 +160,8 @@ TreeController = { page: controller.ajaxPage, getChildren: 1, id: element.id, - type: element.type + type: element.type, + filter: controller.filter }, complete: function(xhr, textStatus) { $node.removeClass("leaf-loading"); @@ -171,7 +173,7 @@ TreeController = { var $children = _processGroup($node, detailContainer, data.tree, controller.baseURL); $children.slideDown(); - + $node.data('children', $children); } else { @@ -204,10 +206,10 @@ TreeController = { else { $node.addClass("leaf-empty"); } - + return $node; } - + if (this.recipient.length == 0) { return; } @@ -215,12 +217,12 @@ TreeController = { this.recipient.html("
          " + this.emptyMessage + "
          "); return; } - + this.recipient.empty(); var $children = _processGroup(this.recipient, this.detailContainer, this.tree, this.baseURL, true); $children.show(); - + this.recipient.data('children', $children); }, load: function () { @@ -255,6 +257,9 @@ TreeController = { if (typeof data.ajaxPage != 'undefined' && data.ajaxPage.length > 0) { this.ajaxPage = data.ajaxPage; } + if (typeof data.filter != 'undefined' && data.filter.length > 0) { + this.filter = data.filter; + } this.index = TreeController.controllers.push(this) - 1; this.load(); From 8b43643fa114fdc56dfa10eee6532ef85390daf3 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Wed, 17 Dec 2014 19:56:42 +0100 Subject: [PATCH 14/92] Changed code for to run with Alex's code --- pandora_console/include/ajax/tree.ajax.php | 8 ++++---- pandora_console/include/class/Tree.class.php | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 4fecccb8a9..59b050aea2 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -18,14 +18,14 @@ require_once("include/class/Tree.class.php"); $getChildren = (bool)get_parameter('getChildren', 0); if ($getChildren) { + $type = get_parameter('type', 'group'); $filter = get_parameter('filter', - array('type' => 'groupz', - 'search' => '', + array('search' => '', 'status' => AGENT_STATUS_ALL)); - $root = (int)get_parameter('root', 0); + $id = (int)get_parameter('id', 0); $method = get_parameter('method', 'on_demand'); - $tree = new Tree($filter['type'], $method, $root); + $tree = new Tree($type, $method, $id); $tree->setFilter(array( 'status' => $filter['status'], 'search' => $filter['search'])); diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 22a851fe17..289ce15203 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -18,7 +18,7 @@ class Tree { private $tree = array(); private $filter = array(); private $root = null; - private $children = "on_demand"; + private $childrenMethod = "on_demand"; public function __construct($type, $childrenMethod = "on_demand", $root = null) { $this->type = $type; From 2828c76ffa175128b24cc3ffa405bf017fdd39cd Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 17 Dec 2014 20:12:21 +0100 Subject: [PATCH 15/92] More fixes --- .../include/javascript/tree/TreeController.js | 32 ++++++++++--------- pandora_console/operation/tree2.php | 13 +++++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 07e92c1f7b..939f3f9205 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -36,7 +36,7 @@ TreeController = { } // Load branch - function _processGroup (container, detailContainer, elements, baseURL, rootGroup) { + function _processGroup (container, elements, rootGroup) { var $group = $("
            "); // First group @@ -44,7 +44,7 @@ TreeController = { $group .addClass("tree-root") .hide() - .prepend(''); + .prepend(''); } // Normal group else { @@ -61,13 +61,13 @@ TreeController = { elements.forEach(function(element, index) { lastNode = index == elements.length - 1 ? true : false; firstNode = rootGroup && index == 0 ? true : false; - element.jqObject = _processNode($group, detailContainer, element, lastNode, firstNode); + element.jqObject = _processNode($group, element, lastNode, firstNode); }, $group); return $group; } // Load leaf - function _processNode (container, detailContainer, element, lastNode, firstNode) { + function _processNode (container, element, lastNode, firstNode) { var $node = $("
          • "); var $leafIcon = $("
            "); var $content = $("
            "); @@ -89,7 +89,7 @@ TreeController = { break; } // If exist the detail container, show the data - if (typeof detailContainer != 'undefined' && detailContainer.length > 0) { + if (typeof controller.detailRecipient != 'undefined' && controller.detailRecipient.length > 0) { $content.click(function (e) { TreeNodeDetailController.getController().init({ recipient: controller.detailRecipient, @@ -120,7 +120,7 @@ TreeController = { $node.addClass("leaf-closed"); // Add children - var $children = _processGroup($node, detailContainer, element.children, this.baseURL); + var $children = _processGroup($node, element.children); $node.data('children', $children); $leafIcon.click(function () { @@ -171,7 +171,7 @@ TreeController = { if (data.success) { $node.addClass("leaf-open"); - var $children = _processGroup($node, detailContainer, data.tree, controller.baseURL); + var $children = _processGroup($node, data.tree); $children.slideDown(); $node.data('children', $children); @@ -210,20 +210,20 @@ TreeController = { return $node; } - if (this.recipient.length == 0) { + if (controller.recipient.length == 0) { return; } - else if (this.tree.length == 0) { - this.recipient.html("
            " + this.emptyMessage + "
            "); + else if (controller.tree.length == 0) { + controller.recipient.html("
            " + controller.emptyMessage + "
            "); return; } - this.recipient.empty(); + controller.recipient.empty(); - var $children = _processGroup(this.recipient, this.detailContainer, this.tree, this.baseURL, true); + var $children = _processGroup(this.recipient, this.tree, true); $children.show(); - this.recipient.data('children', $children); + controller.recipient.data('children', $children); }, load: function () { this.reload(); @@ -257,7 +257,7 @@ TreeController = { if (typeof data.ajaxPage != 'undefined' && data.ajaxPage.length > 0) { this.ajaxPage = data.ajaxPage; } - if (typeof data.filter != 'undefined' && data.filter.length > 0) { + if (typeof data.filter != 'undefined') { this.filter = data.filter; } @@ -328,7 +328,7 @@ TreeNodeDetailController = { type: 'POST', dataType: 'json', data: { - page: this.ajaxURL, + page: this.ajaxPage, getDetail: 1, type: this.type, id: this.id @@ -440,6 +440,8 @@ TreeNodeDetailController = { this.ajaxPage = data.ajaxPage; } + if (typeof TreeNodeDetailController.controllers[this.type] == 'undefined') + TreeNodeDetailController.controllers[this.type] = {}; TreeNodeDetailController.controllers[this.type][this.id] = this; this.load(); }, diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 74918881a8..ae2e8efb1a 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -124,6 +124,8 @@ ui_require_javascript_file("TreeController", "include/javascript/tree/"); html_print_image('images/spinner.gif', false, array('class' => "loading_tree")); echo "
            "; echo "
            "; +echo "
            "; +echo "
            "; ?> \ No newline at end of file From cbd9621770842c12572629ffe73abcffae7b65a4 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 18 Dec 2014 09:55:54 +0100 Subject: [PATCH 16/92] Minor changes --- pandora_console/include/ajax/tree.ajax.php | 40 ++++++++++++------- .../include/javascript/tree/TreeController.js | 22 ++++++---- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 59b050aea2..7ae8529cf3 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -13,23 +13,33 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -require_once("include/class/Tree.class.php"); +// Only accesible by ajax +if (is_ajax ()) { + global $config; -$getChildren = (bool)get_parameter('getChildren', 0); - -if ($getChildren) { - $type = get_parameter('type', 'group'); - $filter = get_parameter('filter', - array('search' => '', - 'status' => AGENT_STATUS_ALL)); - $id = (int)get_parameter('id', 0); - $method = get_parameter('method', 'on_demand'); + // Login check + check_login (); - $tree = new Tree($type, $method, $id); - $tree->setFilter(array( - 'status' => $filter['status'], - 'search' => $filter['search'])); - echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); + require_once("include/class/Tree.class.php"); + + $getChildren = (bool)get_parameter('getChildren', 0); + + if ($getChildren) { + $type = get_parameter('type', 'group'); + $filter = get_parameter('filter', + array('search' => '', + 'status' => AGENT_STATUS_ALL)); + $id = (int)get_parameter('id', 0); + $method = get_parameter('method', 'on_demand'); + + $tree = new Tree($type, $method, $id); + $tree->setFilter(array( + 'status' => $filter['status'], + 'search' => $filter['search'])); + echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); + return; + } + return; } ?> \ No newline at end of file diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 939f3f9205..000480216d 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -116,11 +116,11 @@ TreeController = { container.append($node); - if (typeof element.children != 'undefined' && element.children.length > 0) { + if (typeof element.tree != 'undefined' && element.tree.length > 0) { $node.addClass("leaf-closed"); // Add children - var $children = _processGroup($node, element.children); + var $children = _processGroup($node, element.tree); $node.data('children', $children); $leafIcon.click(function () { @@ -146,7 +146,7 @@ TreeController = { $leafIcon.click(function (e) { e.preventDefault(); - if (! $node.hasClass("children-loaded")) { + if (! $node.hasClass("children-loaded") && ! $node.hasClass("leaf-empty")) { $node .removeClass("leaf-closed") .removeClass("leaf-error") @@ -169,12 +169,18 @@ TreeController = { }, success: function(data, textStatus, xhr) { if (data.success) { - $node.addClass("leaf-open"); - var $children = _processGroup($node, data.tree); - $children.slideDown(); + if (typeof element.tree != 'undefined' && element.tree.length > 0) { + $node.addClass("leaf-open"); - $node.data('children', $children); + var $children = _processGroup($node, data.tree); + $children.slideDown(); + + $node.data('children', $children); + } + else { + $node.addClass("leaf-empty"); + } } else { $node.addClass("leaf-error"); @@ -185,7 +191,7 @@ TreeController = { } }); } - else { + else if (! $node.hasClass("leaf-empty")) { if ($node.hasClass("leaf-open")) { $node .removeClass("leaf-open") From 2b28d813f8b9ea92da96f041d5154c23585ae541 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 18 Dec 2014 11:04:41 +0100 Subject: [PATCH 17/92] Fixes --- pandora_console/include/class/Tree.class.php | 2 +- .../include/javascript/tree/TreeController.js | 2 +- pandora_console/operation/tree2.php | 37 ++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 289ce15203..adbee1c738 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -70,7 +70,7 @@ class Tree { // First filter by name and father $groups = db_get_all_rows_filter('tgrupo', $filter, - array('id_grupo', 'nombre')); + array('id_grupo', 'nombre'));html_debug_print($groups, true); if (empty($groups)) $groups = array(); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 000480216d..366e8c07de 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -151,7 +151,7 @@ TreeController = { .removeClass("leaf-closed") .removeClass("leaf-error") .addClass("leaf-loading"); - + $.ajax({ url: controller.ajaxURL, type: 'POST', diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index ae2e8efb1a..99d38859b1 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -116,7 +116,9 @@ $table->data[0][3] = html_print_input_text( $table->data[0][4] = html_print_submit_button( __('Filter'), "uptbutton", false, 'class="sub search"', true); +echo ''; // --------------------- form filter ----------------------------------- @@ -128,16 +130,32 @@ echo "
            "; echo "
            "; ?> \ No newline at end of file From ece029697201e17563dc5433e0f02c123856245d Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 18 Dec 2014 11:09:46 +0100 Subject: [PATCH 18/92] Fix --- pandora_console/operation/tree2.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 99d38859b1..3e12011356 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -131,7 +131,7 @@ echo ""; ?> From f5d9903745e3eafb51b98ae1da735683953d33d1 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 18 Dec 2014 14:43:45 +0100 Subject: [PATCH 29/92] Minor fixes --- pandora_console/operation/tree2.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 1ec7696986..095d30e61a 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -126,9 +126,9 @@ ui_require_javascript_file("TreeController", "include/javascript/tree/"); html_print_image('images/spinner.gif', false, array('class' => "loading_tree", 'style' => 'display: none;')); -echo "
            "; +echo "
            "; echo "
            "; -echo "
            "; +echo "
            "; echo "
            "; ?> '; + ui_include_time_picker(); ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); - $module_id = get_parameter ('id_module'); - $period = get_parameter ("period", 86400); + $module_id = (int) get_parameter('id_module'); + $period = (int) get_parameter("period", 86400); $group = agents_get_agentmodule_group ($module_id); - $agentId = get_parameter("id_agent"); - $server_name = get_parameter('server_name'); + $agentId = (int) get_parameter("id_agent"); + $server_name = (string) get_parameter('server_name'); if (defined ('METACONSOLE')) { $server = metaconsole_get_connection ($server_name); From d8aee5f0fc6862f974e8536b4692294506991e73 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 11:45:31 +0100 Subject: [PATCH 71/92] Improved the search filter and added new info icons to the modules in the tree view --- pandora_console/include/class/Tree.class.php | 146 +- .../include/javascript/tree/TreeController.js | 38 +- pandora_console/include/styles/pandora.css | 17 +- pandora_console/install.php | 1222 ----------------- pandora_console/operation/tree2.php | 91 ++ 5 files changed, 240 insertions(+), 1274 deletions(-) delete mode 100644 pandora_console/install.php diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 6f630cc080..32ed1d03e6 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -88,6 +88,12 @@ class Tree { $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; } + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['search'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + } + $list_os = os_get_os(); // Transform the os array to use the item id as key @@ -109,6 +115,7 @@ class Tree { WHERE ta.id_agente = tam.id_agente AND ta.disabled = 0 AND tam.disabled = 0 + $agent_search $group_acl ORDER BY ta.id_os ASC, ta.nombre ASC"; $data = db_process_sql($sql); @@ -233,9 +240,9 @@ class Tree { $filter = array(); $filter['parent'] = $parent; - if (!empty($this->filter['search'])) { - $filter['nombre'] = "%" . $this->filter['search'] . "%"; - } + // if (!empty($this->filter['search'])) { + // $filter['nombre'] = "%" . $this->filter['search'] . "%"; + // } // ACL groups if (isset($this->userGroups) && $this->userGroups === false) return array(); @@ -244,15 +251,15 @@ class Tree { $filter['id_grupo'] = array_keys($this->userGroups); // First filter by name and father - $groups = db_get_all_rows_filter('tgrupo', $filter, array('id_grupo', 'nombre')); + $groups = db_get_all_rows_filter('tgrupo', $filter, array('id_grupo', 'nombre', 'icon')); if (empty($groups)) $groups = array(); // Filter by status - $filter_status = AGENT_STATUS_ALL; - if (!empty($this->filter['status'])) { - $filter_status = $this->filter['status']; - } + // $filter_status = AGENT_STATUS_ALL; + // if (!empty($this->filter['status'])) { + // $filter_status = $this->filter['status']; + // } foreach ($groups as $iterator => $group) { // Counters @@ -269,39 +276,39 @@ class Tree { } $groups[$iterator]['status'] = $group_stats['status']; - $groups[$iterator]['icon'] = groups_get_icon($group['id_grupo']) . '.png'; + $groups[$iterator]['icon'] = !empty($group['icon']) ? $group['icon'] . '.png' : 'without_group.png'; - // Filter by status - if ($filter_status != AGENT_STATUS_ALL) { - $remove_group = true; - switch ($filter_status) { - case AGENT_STATUS_NORMAL: - if ($groups[$iterator]['status'] === "ok") - $remove_group = false; - break; - case AGENT_STATUS_WARNING: - if ($groups[$iterator]['status'] === "warning") - $remove_group = false; - break; - case AGENT_STATUS_CRITICAL: - if ($groups[$iterator]['status'] === "critical") - $remove_group = false; - break; - case AGENT_STATUS_UNKNOWN: - if ($groups[$iterator]['status'] === "unknown") - $remove_group = false; - break; - case AGENT_STATUS_NOT_INIT: - if ($groups[$iterator]['status'] === "not_init") - $remove_group = false; - break; - } + // // Filter by status + // if ($filter_status != AGENT_STATUS_ALL) { + // $remove_group = true; + // switch ($filter_status) { + // case AGENT_STATUS_NORMAL: + // if ($groups[$iterator]['status'] === "ok") + // $remove_group = false; + // break; + // case AGENT_STATUS_WARNING: + // if ($groups[$iterator]['status'] === "warning") + // $remove_group = false; + // break; + // case AGENT_STATUS_CRITICAL: + // if ($groups[$iterator]['status'] === "critical") + // $remove_group = false; + // break; + // case AGENT_STATUS_UNKNOWN: + // if ($groups[$iterator]['status'] === "unknown") + // $remove_group = false; + // break; + // case AGENT_STATUS_NOT_INIT: + // if ($groups[$iterator]['status'] === "not_init") + // $remove_group = false; + // break; + // } - if ($remove_group) { - unset($groups[$iterator]); - continue; - } - } + // if ($remove_group) { + // unset($groups[$iterator]); + // continue; + // } + // } if (is_null($limit)) { $groups[$iterator]['children'] = @@ -309,9 +316,7 @@ class Tree { } else if ($limit >= 1) { $groups[$iterator]['children'] = - $this->getGroupsRecursive( - $group['id_grupo'], - ($limit - 1)); + $this->getGroupsRecursive($group['id_grupo'], ($limit - 1)); } switch ($this->countAgentStatusMethod) { @@ -368,8 +373,11 @@ class Tree { } protected function processModule (&$module) { + global $config; + $module['type'] = 'module'; $module['id'] = (int) $module['id_agente_modulo']; + $module['agentID'] = (int) $module['id_agente']; $module['name'] = $module['nombre']; $module['id_module_type'] = (int) $module['id_tipo_modulo']; // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); @@ -398,6 +406,23 @@ class Tree { $module['status'] = "ok"; break; } + + // Link to the Module graph + $graphType = return_graphtype($module['id']); + $winHandle = dechex(crc32($module['id'] . $module['name'])); + + $moduleGraphURL = $config['homeurl'] . + "/operation/agentes/stat_win.php?" . + "type=$graphType&" . + "period=86400&" . + "id=" . $module['id'] . "&" . + "label=" . rawurlencode(urlencode(base64_encode($module['name']))) . "&" . + "refresh=600"; + + $module['moduleGraph'] = array( + 'url' => $moduleGraphURL, + 'handle' => $winHandle + ); } protected function processModules ($modules_aux, &$modules) { @@ -441,12 +466,19 @@ class Tree { $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; } + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['search'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + } + $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, tam.id_tipo_modulo, ta.id_agente, ta.nombre AS agent_name FROM tagente ta, tagente_modulo tam WHERE ta.id_agente = tam.id_agente AND ta.disabled = 0 AND tam.disabled = 0 + $agent_search $group_acl ORDER BY tam.nombre ASC, ta.nombre ASC"; $data = db_process_sql($sql); @@ -540,8 +572,10 @@ class Tree { $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); + $agent['statusRaw'] = agents_get_status($agent['id']); + // Status - switch (agents_get_status($agent['id'])) { + switch ($agent['statusRaw']) { case AGENT_STATUS_NORMAL: $agent['status'] = "ok"; break; @@ -608,11 +642,13 @@ class Tree { if (!isset($this->userGroups[$parent])) return array(); } - $filter = array( - 'id_grupo' => $parent, - 'status' => $this->filter['status'], - 'nombre' => "%" . $this->filter['search'] . "%" - ); + $filter = array(); + $filter['id_grupo'] = $parent; + if (isset($this->filter['status']) && $this->filter['status'] != -1) + $filter['status'] = $this->filter['status']; + if (!empty($this->filter['search'])) + $filter['nombre'] = "%" . $this->filter['search'] . "%"; + $agents = agents_get_agents($filter, array('id_agente', 'nombre')); if (empty($agents)) { $agents = array(); @@ -645,6 +681,12 @@ class Tree { $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; } + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['search'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + } + $module_groups = modules_get_modulegroups(); if (!empty($module_groups)) { @@ -655,6 +697,7 @@ class Tree { WHERE ta.id_agente = tam.id_agente AND ta.disabled = 0 AND tam.disabled = 0 + $agent_search $group_acl ORDER BY tam.nombre ASC, ta.nombre ASC"; $data = db_process_sql($sql); @@ -789,6 +832,12 @@ class Tree { $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; } + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['search'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + } + $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, tam.id_tipo_modulo, tam.id_module_group, ta.id_agente, ta.nombre AS agent_name, @@ -799,6 +848,7 @@ class Tree { AND ttm.id_tag = tt.id_tag AND ta.disabled = 0 AND tam.disabled = 0 + $agent_search $group_acl ORDER BY tt.name ASC, ta.nombre ASC"; $data = db_process_sql($sql); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index dd390608d1..62d640f013 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -309,7 +309,43 @@ TreeController = { $content.append(element.name); break; case 'module': - $content.append(element.name); + // Graph pop-up + var $graphImage = $(' '); + $graphImage + .addClass('module-graph') + .click(function (e) { + e.preventDefault(); + + try { + winopeng(element.moduleGraph.url, element.moduleGraph.handle); + } + catch (error) { + console.log(error); + } + }); + + // Data pop-up + var $dataImage = $(' '); + $dataImage + .addClass('module-data') + .click(function (e) { + e.preventDefault(); + + try { + if ($("#module_details_window").length > 0) + show_module_detail_dialog(element.id, element.agentID, '', 0, 86400); + } + catch (error) { + console.log(error); + } + }); + + $content + .append($graphImage) + .append($dataImage) + .append(element.name); break; case 'os': if (typeof element.icon != 'undefined' && element.icon.length > 0) { diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index d69c0539a9..e112980478 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2931,15 +2931,26 @@ table#policy_modules td * { max-width: 20px; } -.tree-node-counters, .tree-node-counter { +.tree-node>.node-content>img.module-data, +.tree-node>.node-content>img.module-graph { + cursor: pointer; + padding-right: 3px; +} + +.tree-node>.node-content>.tree-node-counters, +.tree-node>.node-content>.tree-node-counters>.tree-node-counter { display: inline; } -.tree-node-counters { +.tree-node>.node-content>.tree-node-counters { } -.tree-node-counter { +.tree-node>.node-content>img { + vertical-align: middle; +} + +.tree-node>.node-content>.tree-node-counters>.tree-node-counter { font-weight: bold; font-size: 7pt; cursor: default; diff --git a/pandora_console/install.php b/pandora_console/install.php deleted file mode 100644 index 5d8a573401..0000000000 --- a/pandora_console/install.php +++ /dev/null @@ -1,1222 +0,0 @@ - - - - - Pandora FMS - Installation Wizard - - - - - - - - - - - - - -
            - -
            - - - -"; - echo " $label "; - echo ""; - if (!extension_loaded($ext)) { - echo ""; - return 1; - } - else { - echo ""; - return 0; - } - echo ""; -} - -function check_include ( $ext, $label ) { - echo ""; - echo " $label "; - echo ""; - if (!include($ext)) { - echo ""; - return 1; - } - else { - echo ""; - return 0; - } - echo ""; -} - -function check_exists ( $file, $label ) { - echo ""; - echo " $label "; - echo ""; - if (!file_exists ($file)) { - echo " "; - return 1; - } - else { - echo " "; - return 0; - } - echo ""; -} - -function check_generic ( $ok, $label ) { - echo ""; - echo " $label "; - echo ""; - if ($ok == 0 ) { - echo " "; - return 1; - } - else { - echo " "; - return 0; - } - echo ""; -} - -function check_writable ( $fullpath, $label ) { - echo ""; - echo " $label "; - echo ""; - if (file_exists($fullpath)) - if (is_writable($fullpath)) { - echo " "; - echo ""; - return 0; - } - else { - echo " "; - echo ""; - return 1; - } - else { - echo " "; - echo ""; - return 1; - } - -} - -function check_variable ( $var, $value, $label, $mode ) { - echo ""; - echo " $label "; - echo ""; - if ($mode == 1) { - if ($var >= $value) { - echo " "; - return 0; - } - else { - echo " "; - return 1; - } - } - elseif ($var == $value) { - echo " "; - return 0; - } - else { - echo " "; - return 1; - } - echo ""; -} - -function parse_mysql_dump($url) { - if (file_exists($url)) { - $file_content = file($url); - $query = ""; - foreach($file_content as $sql_line) { - if (trim($sql_line) != "" && strpos($sql_line, "--") === false) { - $query .= $sql_line; - if(preg_match("/;[\040]*\$/", $sql_line)) { - if (!$result = mysql_query($query)) { - echo mysql_error(); //Uncomment for debug - echo "
            $query
            "; - return 0; - } - $query = ""; - } - } - } - return 1; - } - else - return 0; -} - -function parse_postgresql_dump($connection, $url, $debug = false) { - if (file_exists($url)) { - $file_content = file($url); - - $query = ""; - - foreach ($file_content as $sql_line) { - $clean_line = trim($sql_line); - $comment = preg_match("/^(\s|\t)*--.*$/", $clean_line); - if ($comment) { - continue; - } - - if (empty($clean_line)) { - continue; - } - - $query .= $clean_line; - - //Check if the end of query with the the semicolon and any returns in the end of line - if(preg_match("/;[\040]*\$/", $clean_line)) { - //And execute and clean buffer - pg_send_query($connection, $query); - - $result = pg_get_result($connection); - - if ($debug) { - var_dump($query); - var_dump(pg_result_error($result)); - } - - if (pg_result_status($result) == PGSQL_FATAL_ERROR) { - echo pg_result_error($result); - echo "
            $query
            "; - - return 0; - } - - $query = ""; - } - } - - return 1; - } - else { - return 0; - } -} - -function parse_oracle_dump($connection, $url, $debug = false) { - if (file_exists($url)) { - $file_content = file($url); - - $query = ""; - $plsql_block = false; - - foreach ($file_content as $sql_line) { - $clean_line = trim($sql_line); - $comment = preg_match("/^(\s|\t)*--.*$/", $clean_line); - if ($comment) { - continue; - } - - if (empty($clean_line)) { - continue; - } - - //Support for PL/SQL blocks - if (preg_match("/^BEGIN$/", $clean_line)) { - $query .= $clean_line . ' '; - $plsql_block = true; - } - else{ - $query .= $clean_line; - } - - //Check query's end with a back slash and any returns in the end of line or if it's a PL/SQL block 'END;;' string - if ((preg_match("/;[\040]*\$/", $clean_line) && !$plsql_block) || - (preg_match("/^END;;[\040]*\$/", $clean_line) && $plsql_block)) { - $plsql_block = false; - //Execute and clean buffer - - //Delete the last semicolon from current query - $query = substr($query, 0, strlen($query) - 1); - $sql = oci_parse($connection, $query); - $result = oci_execute($sql); - - if ($debug) { - var_dump($query); - } - - if (!$result) { - $e = oci_error($sql); - echo "
            Errors creating schema:
            "; - echo htmlentities($e['message'], ENT_QUOTES); - echo "
            $query
            "; - echo "
            "; - - return 0; - } - - $query = ""; - oci_free_statement($sql); - } - } - - return 1; - } - else { - return 0; - } -} - -function oracle_drop_all_objects ($connection) { - //Drop all objects of the current installation - $stmt = oci_parse($connection, - "BEGIN " . - "FOR cur_rec IN (SELECT object_name, object_type " . - "FROM user_objects " . - "WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SNAPSHOT', 'MATERIALIZED VIEW')) LOOP " . - "BEGIN " . - "IF cur_rec.object_type = 'TABLE' THEN " . - "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\" CASCADE CONSTRAINTS'; " . - "ELSE " . - "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'; " . - "END IF; " . - "EXCEPTION " . - "WHEN OTHERS THEN " . - "DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'); " . - "END; " . - "END LOOP; " . - "END; "); - - $result = oci_execute($stmt); - oci_free_statement($stmt); - - return 0; -} - -function random_name ($size) { - $temp = ""; - for ($a=0;$a< $size;$a++) - $temp = $temp. chr(rand(122,97)); - - return $temp; -} - -function print_logo_status ($step, $step_total) { - global $banner; - - return " -
            -
            -
            - $banner -
            -
            - Install step $step of $step_total -
            -
            "; -} - -// -// This function adjusts path settings in pandora db for FreeBSD. -// -// All packages and configuration files except operating system's base files -// are installed under /usr/local in FreeBSD. So, path settings in pandora db -// for some programs should be changed from the Linux default. -// -function adjust_paths_for_freebsd($engine, $connection = false) { - - $adjust_sql = array( - "update trecon_script set script = REPLACE(script,'/usr/share','/usr/local/share');", - "update tconfig set value = REPLACE(value,'/usr/bin','/usr/local/bin') where token='netflow_daemon' OR token='netflow_nfdump' OR token='netflow_nfexpire';", - "update talert_commands set command = REPLACE(command,'/usr/bin','/usr/local/bin');", - "update talert_commands set command = REPLACE(command,'/usr/share', '/usr/local/share');", - "update tplugin set execute = REPLACE(execute,'/usr/share','/usr/local/share');", - "update tevent_response set target = REPLACE(target,'/usr/share','/usr/local/share');" - ); - - for ($i = 0; $i < count ($adjust_sql); $i++) { - switch ($engine) { - case 'mysql': - $result = mysql_query($adjust_sql[$i]); - break; - case 'oracle': - //Delete the last semicolon from current query - $query = substr($adjust_sql[$i], 0, strlen($adjust_sql[$i]) - 1); - $sql = oci_parse($connection, $query); - $result = oci_execute($sql); - break; - case 'pgsql': - pg_send_query($connection, $adjust_sql[$i]); - $result = pg_get_result($connection); - break; - } - if (!$result) { - return 0; - } - } - - return 1; -} - -function install_step1() { - global $banner; - - echo " -
            -
            - " . print_logo_status (1,6) . " -
            -

            Welcome to Pandora FMS installation Wizard

            -

            This wizard helps you to quick install Pandora FMS console and main database in your system.

            -

            In four steps, this installer will check all dependencies and will create your configuration, ready to use.

            -

            For more information, please refer to documentation.
            - Pandora FMS Development Team

            - "; - if (file_exists("include/config.php")) { - echo "
            Warning: You already have a config.php file. - Configuration and database would be overwritten if you continued.
            "; - } - echo "
            "; - echo ""; - $writable = check_writable ( "include", "Checking if ./include is writable"); - if (file_exists("include/config.php")) - $writable += check_writable ( "include/config.php", "Checking if include/config.php is writable"); - echo "
            "; - - echo "
            Warning: This installer will overwrite and destroy - your existing Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database.
            -
            "; - - echo "
            Upgrade: - If you want to upgrade from Pandora FMS 4.x to 5.0 version, please use the migration tool inside /extras directory in this setup. -
            "; - - if ($writable == 0) { - echo "
            "; - echo ""; - } - else { - echo "
            ERROR:You need to setup permissions to be able to write in ./include directory
            "; - echo "
            "; - } - - echo "
            "; - echo " -
            -
            - Pandora FMS is an OpenSource Software project registered at - SourceForge -
            -
            "; -} - -function install_step1_licence() { - echo " -
            -
            - " . print_logo_status (2,6) . " -
            -

            GPL2 Licence terms agreement

            -

            Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms.. -

            For more information, please refer to our website at http://pandorafms.org and contact us if you have any kind of question about the usage of Pandora FMS

            -

            If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

            - "; - - if (!file_exists("COPYING")) { - echo "
            Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; - echo "
            "; - } - else { - echo "
            "; - echo ""; - echo "

            "; - echo "

            "; - } - echo "
            "; - - echo "
            -
            -
            - Pandora FMS is an OpenSource Software project registered at - SourceForge -
            -
            "; -} - -function install_step2() { - - echo " -
            -
            - " . print_logo_status (3,6) . " -
            "; - echo "

            Checking software dependencies

            "; - echo ""; - $res = 0; - $res += check_variable(phpversion(),"5.2","PHP version >= 5.2",1); - $res += check_extension("gd","PHP GD extension"); - $res += check_extension("ldap","PHP LDAP extension"); - $res += check_extension("snmp","PHP SNMP extension"); - $res += check_extension("session","PHP session extension"); - $res += check_extension("gettext","PHP gettext extension"); - $res += check_extension("mbstring","PHP Multibyte String"); - $res += check_extension("zip","PHP Zip"); - $res += check_extension("zlib","PHP Zlib extension"); - $res += check_extension("curl","CURL (Client URL Library)"); - if (PHP_OS == "FreeBSD") { - $res += check_exists ("/usr/local/bin/twopi","Graphviz Binary"); - } - else if (PHP_OS == "NetBSD") { - $res += check_exists ("/usr/pkg/bin/twopi","Graphviz Binary"); - } - else { - $res += check_exists ("/usr/bin/twopi","Graphviz Binary"); - } - - echo ""; - check_extension("mysql", "PHP MySQL extension"); - check_extension("pgsql", "PHP PostgreSQL extension"); - check_extension("oci8", "PHP Oracle extension"); - echo "
            "; - echo "DB Engines"; - echo ""; - echo "
            "; - - if ($res > 0) { - echo " -
            You have some incomplete - dependencies. Please correct them or this installer - will not be able to finish your installation. -
            -
            - Remember, if you install any PHP module to comply - with these dependences, you need to restart - your HTTP/Apache server after it to use the new - modules. -
            -
            - Ignore it. Force install Step #3 -
            "; - echo "
            "; - } - else { - echo "
            "; - echo "
            -
            -
            "; - } - echo " -
            -
            -
            -
            - Pandora FMS is an OpenSource Software project registered at - SourceForge -
            - "; -} - - -function install_step3() { - $options = ''; - if (extension_loaded("mysql")) { - $options .= ""; - } - if (extension_loaded("pgsql")) { - $options .= ""; - } - if (extension_loaded("oci8")) { - $options .= ""; - } - - $error = false; - if (empty($options)) { - $error = true; - } - - echo " -
            -
            - " . print_logo_status (4,6) . " -
            -

            Environment and database setup

            -

            - This wizard will create your Pandora FMS database, - and populate it with all the data needed to run for the first time. -

            -

            - You need a privileged user to create database schema, this is usually root user. - Information about root user will not be used or stored anymore. -

            -

            - You can also deploy the scheme into an existing Database. - In this case you need a privileged Database user and password of that instance. -

            -

            - Now, please, complete all details to configure your database and environment setup. -

            -
            - Warning: This installer will overwrite and destroy your existing - Pandora FMS configuration and Database. Before continue, - please be sure that you have no valuable Pandora FMS data in your Database. -

            -
            "; - - if (extension_loaded("oci8")) { - echo "
            For Oracle installation an existing Database with a privileged user is needed.
            "; - } - if (!$error) { - echo ""; - } - - echo ""; - echo "
            "; - echo "DB Engine
            "; - - - if ($error) { - echo " -
            - Warning: You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies. -
            "; - } - else { - echo ""; - - echo "
            "; - echo " Installation in
            "; - echo ""; - } - echo "
            DB User with privileges
            - - -
            DB Password for this user
            - - -
            DB Hostname
            - - -
            DB Name (pandora by default)
            - - -
            - Drop Database if exists
            - - - -
            Full path to HTTP publication directory
            - For example /var/www/pandora_console/ -
            - - -
            URL path to Pandora FMS Console
            - For example '/pandora_console' -
            - -
            - "; - - - echo "
            "; - - if (!$error) { - echo ""; - } - - echo ""; - - echo "
            "; - echo "
            -
            - Pandora FMS is an OpenSource Software project registered at - SourceForge -
            -
            "; -} - -function install_step4() { - $pandora_config = "include/config.php"; - - if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) || - (! isset($_POST["pass"])) || (!isset($_POST['engine'])) || (! isset($_POST["db_action"])) ) { - $dbpassword = ""; - $dbuser = ""; - $dbhost = ""; - $dbname = ""; - $engine = ""; - $dbaction = ""; - } - else { - $engine = $_POST['engine']; - $dbpassword = $_POST["pass"]; - $dbuser = $_POST["user"]; - $dbhost = $_POST["host"]; - $dbaction = $_POST["db_action"]; - if (isset($_POST["drop"])) - $dbdrop = $_POST["drop"]; - else - $dbdrop = 0; - - $dbname = $_POST["dbname"]; - if (isset($_POST["url"])) - $url = $_POST["url"]; - else - $url = "http://localhost"; - if (isset($_POST["path"])) { - $path = $_POST["path"]; - $path = str_replace("\\", "/", $path); // Windows compatibility - } - else - $path = "/var/www"; - } - $everything_ok = 0; - $step1=0; - $step2=0; - $step3=0; - $step4=0; $step5=0; $step6=0; $step7=0; - - echo " -
            -
            - " . print_logo_status(5,6) . " -
            -

            Creating database and default configuration file

            - "; - switch ($engine) { - case 'mysql': - if (! mysql_connect ($dbhost, $dbuser, $dbpassword)) { - check_generic ( 0, "Connection with Database"); - } - else { - check_generic ( 1, "Connection with Database"); - - // Drop database if needed and don't want to install over an existing DB - if ($dbdrop == 1) { - mysql_query ("DROP DATABASE IF EXISTS `$dbname`"); - } - - // Create schema - if ($dbaction == 'db_new' || $dbdrop == 1) { - $step1 = mysql_query ("CREATE DATABASE `$dbname`"); - check_generic ($step1, "Creating database '$dbname'"); - } - else { - $step = 1; - } - if ($step1 == 1) { - $step2 = mysql_select_db($dbname); - check_generic ($step2, "Opening database '$dbname'"); - - $step3 = parse_mysql_dump("pandoradb.sql"); - check_generic ($step3, "Creating schema"); - - $step4 = parse_mysql_dump("pandoradb_data.sql"); - check_generic ($step4, "Populating database"); - if (PHP_OS == "FreeBSD") { - $step_freebsd = adjust_paths_for_freebsd ($engine); - check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); - } - - $random_password = random_name (8); - $host = 'localhost'; - if ($dbhost != 'localhost') - $host = $_SERVER['SERVER_ADDR']; - $step5 = mysql_query ("GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host - IDENTIFIED BY '".$random_password."'"); - mysql_query ("FLUSH PRIVILEGES"); - check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
            Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
            "); - - $step6 = is_writable("include"); - check_generic ($step6, "Write permissions to save config file in './include'"); - - $cfgin = fopen ("include/config.inc.php","r"); - $cfgout = fopen ($pandora_config,"w"); - $config_contents = fread ($cfgin, filesize("include/config.inc.php")); - $dbtype = 'mysql'; - $config_new = ''; - $step7 = fputs ($cfgout, $config_new); - $step7 = $step7 + fputs ($cfgout, $config_contents); - if ($step7 > 0) - $step7 = 1; - fclose ($cfgin); - fclose ($cfgout); - chmod ($pandora_config, 0600); - check_generic ($step7, "Created new config file at '".$pandora_config."'"); - } - } - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - break; - case 'oracle': - $connection = oci_connect($dbuser, $dbpassword, '//' . $dbhost . '/' . $dbname); - if (!$connection) { - check_generic(0, "Connection with Database"); - } - else { - check_generic(1, "Connection with Database"); - - // Drop all objects if needed - if ($dbdrop == 1) { - oracle_drop_all_objects($connection); - } - - $step1 = parse_oracle_dump($connection, "pandoradb.oracle.sql"); - - check_generic($step1, "Creating schema"); - - if ($step1) { - $step2 = parse_oracle_dump($connection, "pandoradb.data.oracle.sql"); - } - - check_generic ($step2, "Populating database"); - - if (PHP_OS == "FreeBSD") - { - $step_freebsd = adjust_paths_for_freebsd ($engine, $connection); - check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); - } - - echo ""; - - if ($step2) { - $step3 = is_writable("include"); - } - - check_generic ($step3, "Write permissions to save config file in './include'"); - - if ($step3) { - $cfgin = fopen ("include/config.inc.php","r"); - $cfgout = fopen ($pandora_config,"w"); - $config_contents = fread ($cfgin, filesize("include/config.inc.php")); - $dbtype = 'oracle'; - $config_new = ''; - $step4 = fputs ($cfgout, $config_new); - $step4 = $step4 + fputs ($cfgout, $config_contents); - if ($step4 > 0) - $step4 = 1; - fclose ($cfgin); - fclose ($cfgout); - chmod ($pandora_config, 0600); - } - - check_generic ($step4, "Created new config file at '" . $pandora_config . "'"); - - if (($step4 + $step3 + $step2 + $step1) == 4) { - $everything_ok = 1; - } - - } - break; - case 'pgsql': - $step1 = $step2 = $step3 = $step4 = $step5 = $step6 = $step7 = 0; - - $connection = pg_connect("host='" . $dbhost . "' dbname='postgres' user='" . $dbuser . "' password='" . $dbpassword . "'"); - if ($connection === false) { - check_generic(0, "Connection with Database"); - } - else { - check_generic(1, "Connection with Database"); - - // Drop database if needed - if ($dbdrop == 1 && $dbaction == 'db_exist') { - $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); - } - - if ($dbaction != 'db_exist' || $dbdrop == 1) { - pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); - $result = pg_get_result($connection); - if (pg_result_status($result) != PGSQL_FATAL_ERROR) { - $step1 = 1; - } - - check_generic ($step1, "Creating database '$dbname'"); - } - else { - $step1 = 1; - } - - check_generic ($step1, "Creating database '$dbname'"); - - if ($step1 == 1) { - //Reopen DB because I don't know how to use DB in PostgreSQL - pg_close($connection); - - $connection = pg_connect("host='" . $dbhost . "' dbname='" . $dbname . - "' user='" . $dbuser . "' password='" . $dbpassword . "'"); - - if ($connection !== false) { - $step2 = 1; - } - } - - check_generic ($step2, "Opening database '$dbname'"); - - if ($step2) { - $step3 = parse_postgresql_dump($connection, "pandoradb.postgreSQL.sql"); - } - - check_generic($step3, "Creating schema"); - - if ($step3) { - $step4 = parse_postgresql_dump($connection, "pandoradb.data.postgreSQL.sql"); - } - - check_generic ($step4, "Populating database"); - - if (PHP_OS == "FreeBSD") - { - $step_freebsd = adjust_paths_for_freebsd ($engine, $connection); - check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); - } - - if ($step4) { - $random_password = random_name (8); - - pg_query($connection, "DROP USER pandora"); - pg_send_query($connection, "CREATE USER pandora WITH PASSWORD '" . $random_password . "'"); - $result = pg_get_result($connection); - - if (pg_result_status($result) != PGSQL_FATAL_ERROR) { - //Set the privileges for DB - pg_send_query($connection, "GRANT ALL PRIVILEGES ON DATABASE pandora TO pandora;"); - $result = pg_get_result($connection); - - $setDBPrivileges = 0; - if (pg_result_status($result) != PGSQL_FATAL_ERROR) { - $setDBPrivileges = 1; - } - - if ($setDBPrivileges) { - //Set the privileges for each tables. - pg_send_query($connection, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"); - $result = pg_get_result($connection); - - $tables = array(); - while ($row = pg_fetch_assoc($result)) { - $tables[] = $row['table_name']; - } - - $correct = 1; - foreach ($tables as $table) { - pg_send_query($connection, "GRANT ALL PRIVILEGES ON TABLE " . $table . " TO pandora;"); - $result = pg_get_result($connection); - - if (pg_result_status($result) == PGSQL_FATAL_ERROR) { - $correct = 0; - break; - } - - //For each table make owner pandora - pg_send_query($connection, "ALTER TABLE " . $table . " OWNER TO pandora;"); - $result = pg_get_result($connection); - - if (pg_result_status($result) == PGSQL_FATAL_ERROR) { - $correct = 0; - break; - } - - //INI ----- Grant for secuences - pg_send_query($connection, "SELECT column_name FROM information_schema.columns WHERE table_name = '" . $table . "';"); - $result2 = pg_get_result($connection); - - $columns = array(); - while ($row = pg_fetch_assoc($result2)) { - $columns[] = $row['column_name']; - } - - //Check for each column if it have a sequence to grant - foreach ($columns as $column) { - pg_send_query($connection, "SELECT pg_get_serial_sequence('" . $table . "', '" . $column . "');"); - $result3 = pg_get_result($connection); - - $sequence = pg_fetch_assoc($result3); - if (!empty($sequence['pg_get_serial_sequence'])) { - pg_send_query($connection, "GRANT ALL PRIVILEGES ON SEQUENCE " . $sequence['pg_get_serial_sequence'] . " to pandora;"); - $result4 = pg_get_result($connection); - - if (pg_result_status($result4) == PGSQL_FATAL_ERROR) { - $correct = 0; - break; - } - } - } - //END ----- Grant for secuences - - } - - if ($correct) { - $step5 = 1; - } - } - } - } - - check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
            Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
            "); - - if ($step5) { - $step6 = is_writable("include"); - } - - check_generic ($step6, "Write permissions to save config file in './include'"); - - if ($step6) { - $cfgin = fopen ("include/config.inc.php","r"); - $cfgout = fopen ($pandora_config,"w"); - $config_contents = fread ($cfgin, filesize("include/config.inc.php")); - $dbtype = 'postgresql'; - $config_new = ''; - $step7 = fputs ($cfgout, $config_new); - $step7 = $step7 + fputs ($cfgout, $config_contents); - if ($step7 > 0) - $step7 = 1; - fclose ($cfgin); - fclose ($cfgout); - chmod ($pandora_config, 0600); - } - - check_generic ($step7, "Created new config file at '".$pandora_config."'"); - - if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { - $everything_ok = 1; - } - } - break; - } - echo "
            Please, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file and set database password.
            "; - - if ($everything_ok == 1) { - echo "
            "; - echo ""; - } - else { - $info = "
            There were some problems. - Installation was not completed. -

            Please correct failures before trying again. - All database "; - if ($engine == 'oracle') - $info .= "objects "; - else - $info .= "schemes "; - - $info .= "created in this step have been dropped.

            -
            "; - echo $info; - - switch ($engine) { - case 'mysql': - if (mysql_error() != "") { - echo "
            ERROR: ". mysql_error().".
            "; - } - - if ($step1 == 1) { - mysql_query ("DROP DATABASE $dbname"); - } - break; - case 'pgsql': - break; - case 'oracle': - oracle_drop_all_objects($connection); - break; - } - echo "
            "; - } - - echo "
            "; - echo " -
            -
            - Pandora FMS is an Open Source Software project registered at - SourceForge -
            - "; -} - - -function install_step5() { - echo " -
            -
            - " . print_logo_status (6,6) . " -
            -

            Installation complete

            -

            For security, you now must manually delete this installer - ('install.php') file before trying to access to your Pandora FMS console. -

            You should also install Pandora FMS Servers before trying to monitor anything; - please read documentation on how to install it.

            -

            Default user is 'admin' with password 'pandora', - please change it both as soon as possible.

            -

            Don't forget to check http://pandorafms.com - for updates. -


            Click here to access to your Pandora FMS console. -

            -
            "; - echo "
            -
            - Pandora FMS is an OpenSource Software project registered at - SourceForge -
            -
            "; -} -?> diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index e386827a5b..760f6e86e3 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -132,6 +132,8 @@ html_print_table($table); echo ''; // --------------------- form filter ----------------------------------- +ui_include_time_picker(); +ui_require_jquery_file("ui.datepicker-" . get_user_language(), "include/javascript/i18n/"); ui_require_javascript_file("TreeController", "include/javascript/tree/"); html_print_image('images/spinner.gif', false, @@ -234,4 +236,93 @@ echo ""; }); } + // Show the modal window of an module + var moduleDetailsWindow = $("
            "); + moduleDetailsWindow + .hide() + .prop("id", "module_details_window") + .appendTo('body'); + + function show_module_detail_dialog(module_id, id_agent, server_name, offset, period) { + var params = {}; + + if (period == -1) { + period = $('#period').val(); + params.selection_mode = $('input[name=selection_mode]:checked').val(); + params.date_from = $('#text-date_from').val(); + params.time_from = $('#text-time_from').val(); + params.date_to = $('#text-date_to').val(); + params.time_to = $('#text-time_to').val(); + } + + params.page = "include/ajax/module"; + params.get_module_detail = 1; + params.server_name = server_name; + params.id_agent = id_agent; + params.id_module = module_id; + params.offset = offset; + params.period = period; + + $.ajax({ + type: "POST", + url: "", + data: params, + dataType: "html", + success: function(data) { + $("#module_details_window").hide () + .empty () + .append (data) + .dialog ({ + resizable: true, + draggable: true, + modal: true, + overlay: { + opacity: 0.5, + background: "black" + }, + width: 650, + height: 500 + }) + .show (); + refresh_pagination_callback(module_id, id_agent, server_name); + datetime_picker_callback(); + forced_title_callback(); + } + }); + } + + function datetime_picker_callback() { + $("#text-time_from, #text-time_to").timepicker({ + showSecond: true, + timeFormat: '', + timeOnlyTitle: '', + timeText: '', + hourText: '', + minuteText: '', + secondText: '', + currentText: '', + closeText: ''}); + + $.datepicker.setDefaults($.datepicker.regional[ ""]); + $("#text-date_from, #text-date_to").datepicker({dateFormat: ""}); + + } + + function refresh_pagination_callback (module_id, id_agent, server_name) { + + $(".binary_dialog").click( function() { + + var classes = $(this).attr('class'); + classes = classes.split(' '); + var offset_class = classes[2]; + offset_class = offset_class.split('_'); + var offset = offset_class[1]; + + var period = $('#period').val(); + + show_module_detail_dialog(module_id, id_agent, server_name, offset, period); + return false; + }); + } + \ No newline at end of file From 1f1672f5c2d814e5c2e9431992d42202dfa57b1c Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 13:16:57 +0100 Subject: [PATCH 72/92] Changed the 'forced_title' feature of the function "html_print_image" --- pandora_console/include/functions_html.php | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/pandora_console/include/functions_html.php b/pandora_console/include/functions_html.php index 4360409e56..c296f5b5b2 100644 --- a/pandora_console/include/functions_html.php +++ b/pandora_console/include/functions_html.php @@ -1752,24 +1752,17 @@ function html_print_image ($src, $return = false, $options = false, else { $options['class'] = 'forced_title'; } - - if (!isset ($options['id'])) { - $options['id'] = uniqid(); - } - - $params = array( - 'id' => 'forced_title_' . $options['id'], - 'class' => 'forced_title_layer', - 'content' => $options["title"], - 'hidden' => true); - $output = html_print_div($params, true) . $output; + + // New way to show the force_title (cleaner and better performance) + $output .= 'title="'.io_safe_input_html($options["title"]).'" '; + $output .= 'data-use_title_for_force_title="1" '; } //Valid attributes (invalid attributes get skipped) - $attrs = array ("height", "longdesc", "usemap","width","id", - "class","lang","xml:lang", "onclick", "ondblclick", + $attrs = array ("height", "longdesc", "usemap", "width", "id", + "class", "lang", "xml:lang", "onclick", "ondblclick", "onmousedown", "onmouseup", "onmouseover", "onmousemove", - "onmouseout", "onkeypress", "onkeydown", "onkeyup","pos_tree"); + "onmouseout", "onkeypress", "onkeydown", "onkeyup", "pos_tree"); foreach ($attrs as $attribute) { if (isset ($options[$attribute])) { From 3cbb91a308e8939d6067806e614d3e9cdab06cb6 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 13:18:27 +0100 Subject: [PATCH 73/92] Added the server type image to the modules in the tree view --- pandora_console/include/class/Tree.class.php | 26 +++++++++++++------ .../include/javascript/tree/TreeController.js | 12 ++++++++- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 32ed1d03e6..71710fe035 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -34,6 +34,9 @@ class Tree { $this->childrenMethod = $childrenMethod; $this->countModuleStatusMethod = $countModuleStatusMethod; $this->countAgentStatusMethod = $countAgentStatusMethod; + + global $config; + include_once($config['homedir']."/include/functions_servers.php"); } public function setType($type) { @@ -109,7 +112,7 @@ class Tree { } if (!empty($list_os)) { $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, ta.id_os, + tam.id_tipo_modulo, ta.id_os, tam.id_modulo, ta.id_agente, ta.nombre AS agent_name FROM tagente ta, tagente_modulo tam WHERE ta.id_agente = tam.id_agente @@ -141,6 +144,7 @@ class Tree { $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); @@ -377,7 +381,6 @@ class Tree { $module['type'] = 'module'; $module['id'] = (int) $module['id_agente_modulo']; - $module['agentID'] = (int) $module['id_agente']; $module['name'] = $module['nombre']; $module['id_module_type'] = (int) $module['id_tipo_modulo']; // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); @@ -407,6 +410,9 @@ class Tree { break; } + // HTML of the server type image + $module['serverTypeHTML'] = servers_show_type($module['server_type']); + // Link to the Module graph $graphType = return_graphtype($module['id']); $winHandle = dechex(crc32($module['id'] . $module['name'])); @@ -438,7 +444,7 @@ class Tree { $modules = array(); $modules_aux = agents_get_modules($parent, - array('id_agente_modulo', 'nombre', 'id_tipo_modulo'), $filter); + array('id_agente_modulo', 'nombre', 'id_tipo_modulo', 'id_modulo'), $filter); if (empty($modules_aux)) $modules_aux = array(); @@ -472,7 +478,8 @@ class Tree { $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; } - $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, tam.id_tipo_modulo, + $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, + tam.id_tipo_modulo, tam.id_modulo, ta.id_agente, ta.nombre AS agent_name FROM tagente ta, tagente_modulo tam WHERE ta.id_agente = tam.id_agente @@ -501,9 +508,10 @@ class Tree { $this->processAgent(&$agent, array(), false); $module = array(); - $module['id_agente_modulo'] = $value['id_agente_modulo']; + $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; $module['nombre'] = $value['module_name']; - $module['id_tipo_modulo'] = $value['id_tipo_modulo']; + $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); @@ -691,7 +699,7 @@ class Tree { if (!empty($module_groups)) { $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, tam.id_module_group, + tam.id_tipo_modulo, tam.id_module_group, tam.id_modulo, ta.id_agente, ta.nombre AS agent_name FROM tagente ta, tagente_modulo tam WHERE ta.id_agente = tam.id_agente @@ -723,6 +731,7 @@ class Tree { $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['id_module_group'] = (int) $value['id_module_group']; + $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); @@ -839,7 +848,7 @@ class Tree { } $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, tam.id_module_group, + tam.id_tipo_modulo, tam.id_module_group, tam.id_modulo, ta.id_agente, ta.nombre AS agent_name, tt.name AS tag_name, tt.id_tag FROM tagente ta, tagente_modulo tam, ttag_module ttm, ttag tt @@ -873,6 +882,7 @@ class Tree { $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['id_module_group'] = (int) $value['id_module_group']; + $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 62d640f013..51c0d69579 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -309,6 +309,16 @@ TreeController = { $content.append(element.name); break; case 'module': + // Server type + if (typeof element.serverTypeHTML != 'undefined' + && element.serverTypeHTML.length > 0 + && element.serverTypeHTML != '--') { + var $serverTypeImage = $(element.serverTypeHTML); + $serverTypeImage.addClass("module-server-type"); + + $content.append($serverTypeImage) + } + // Graph pop-up var $graphImage = $(' '); @@ -335,7 +345,7 @@ TreeController = { try { if ($("#module_details_window").length > 0) - show_module_detail_dialog(element.id, element.agentID, '', 0, 86400); + show_module_detail_dialog(element.id, '', '', 0, 86400); } catch (error) { console.log(error); From 69f7a362b46a77e73cef31fa1f67bdc1d47c5ead Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 13:19:01 +0100 Subject: [PATCH 74/92] Modified the tree view styles --- pandora_console/include/styles/pandora.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index e112980478..85b0dcb385 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2937,6 +2937,10 @@ table#policy_modules td * { padding-right: 3px; } +.tree-node>.node-content>img.module-server-type { + padding-right: 3px; +} + .tree-node>.node-content>.tree-node-counters, .tree-node>.node-content>.tree-node-counters>.tree-node-counter { display: inline; From 3bddad1c2377e90ca2e9353176c9a6607c8e6e51 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 13:41:20 +0100 Subject: [PATCH 75/92] Improved the tree view styles --- pandora_console/include/styles/pandora.css | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 85b0dcb385..2bd0142f67 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2860,8 +2860,7 @@ table#policy_modules td * { background: 0 0; } .node-content { - padding: 3px; - height: 20px; + height: 25px; } .node-content:hover { @@ -2873,7 +2872,7 @@ table#policy_modules td * { } .leaf-icon { - width: 20px; + width: 18px; height: 20px; } From 1df4f77d2f790cc035524e7e70d4dc5d8cf5be4c Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 13:41:47 +0100 Subject: [PATCH 76/92] Fixed an error on the module groups tree view --- pandora_console/include/class/Tree.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 71710fe035..cd72a3b2c5 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -707,7 +707,7 @@ class Tree { AND tam.disabled = 0 $agent_search $group_acl - ORDER BY tam.nombre ASC, ta.nombre ASC"; + ORDER BY tam.id_module_group ASC, tam.nombre ASC, ta.nombre ASC"; $data = db_process_sql($sql); } @@ -786,7 +786,7 @@ class Tree { // Create new module group $actual_module_group_root = array(); - $actual_module_group_root['id'] = (int) $module['id_module_group']; + $actual_module_group_root['id'] = $module['id_module_group']; $actual_module_group_root['type'] = $this->type; if (isset($module_groups[$module['id_module_group']])) { From a7b99927085a76550ff54ea3a8018237932fd219 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 15:07:01 +0100 Subject: [PATCH 77/92] Fixed an error on the groups tree view --- pandora_console/include/class/Tree.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index cd72a3b2c5..94d43ffd93 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -383,8 +383,9 @@ class Tree { $module['id'] = (int) $module['id_agente_modulo']; $module['name'] = $module['nombre']; $module['id_module_type'] = (int) $module['id_tipo_modulo']; + $module['server_type'] = (int) $module['id_modulo']; // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); - $module['value'] = modules_get_last_value($module['id']); + // $module['value'] = modules_get_last_value($module['id']); // Status switch (modules_get_status($module['id'])) { From ed9a746ecc80740d4daebcfe5419eb6dfba7bb21 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 16:39:35 +0100 Subject: [PATCH 78/92] Fixed an acl error --- pandora_console/include/class/Tree.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 94d43ffd93..b55ab9ba76 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -34,6 +34,13 @@ class Tree { $this->childrenMethod = $childrenMethod; $this->countModuleStatusMethod = $countModuleStatusMethod; $this->countAgentStatusMethod = $countAgentStatusMethod; + + $userGroups = users_get_groups(); + + if (empty($userGroups)) + $this->userGroups = false; + else + $this->userGroups = $userGroups; global $config; include_once($config['homedir']."/include/functions_servers.php"); From 33798499d6042602e86c119765e0a91646f243fc Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 18:23:01 +0100 Subject: [PATCH 79/92] Fixed some errors on the tree node detail controller --- .../include/javascript/tree/TreeController.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 51c0d69579..d495789347 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -638,6 +638,16 @@ TreeNodeDetailController = { var $content = $("
            "); $content.addClass("tree-element-detail-content"); + // Container + this.container = $("
            "); + this.container + .addClass("tree-element-detail") + .append($label) + .data('label', $label) + .append($content) + .data('content', $content) + .hide(); + $label.addClass('tree-element-detail-loading'); $.ajax({ url: this.ajaxURL, @@ -655,7 +665,8 @@ TreeNodeDetailController = { success: function(data, textStatus, xhr) { if (data.success) { $label.addClass('tree-element-detail-loaded'); - $content.append(data.html); + $content.html(data.html); + controller.open(); } else { @@ -669,17 +680,6 @@ TreeNodeDetailController = { } }); - - // Container - this.container = $("
            "); - this.container - .addClass("tree-element-detail") - .append($label) - .data('label', $label) - .append($content) - .data('content', $content) - .hide(); - this.recipient.append(this.container); this.open(); }, @@ -734,7 +734,7 @@ TreeNodeDetailController = { return false; } // Required - if (typeof data.id != 'undefined' && data.id.length > 0) { + if (typeof data.id != 'undefined' && (data.id.length > 0 || !isNaN(data.id))) { this.id = data.id; } else { From 06af8cdbd7123aaf4862515d359ab7d2186a37eb Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 8 Jan 2015 19:16:02 +0100 Subject: [PATCH 80/92] Recovered the install.php file --- pandora_console/install.php | 1222 +++++++++++++++++++++++++++++++++++ 1 file changed, 1222 insertions(+) create mode 100644 pandora_console/install.php diff --git a/pandora_console/install.php b/pandora_console/install.php new file mode 100644 index 0000000000..5d8a573401 --- /dev/null +++ b/pandora_console/install.php @@ -0,0 +1,1222 @@ + + + + + Pandora FMS - Installation Wizard + + + + + + + + + + + + + +
            + +
            + + + +"; + echo " $label "; + echo ""; + if (!extension_loaded($ext)) { + echo ""; + return 1; + } + else { + echo ""; + return 0; + } + echo ""; +} + +function check_include ( $ext, $label ) { + echo ""; + echo " $label "; + echo ""; + if (!include($ext)) { + echo ""; + return 1; + } + else { + echo ""; + return 0; + } + echo ""; +} + +function check_exists ( $file, $label ) { + echo ""; + echo " $label "; + echo ""; + if (!file_exists ($file)) { + echo " "; + return 1; + } + else { + echo " "; + return 0; + } + echo ""; +} + +function check_generic ( $ok, $label ) { + echo ""; + echo " $label "; + echo ""; + if ($ok == 0 ) { + echo " "; + return 1; + } + else { + echo " "; + return 0; + } + echo ""; +} + +function check_writable ( $fullpath, $label ) { + echo ""; + echo " $label "; + echo ""; + if (file_exists($fullpath)) + if (is_writable($fullpath)) { + echo " "; + echo ""; + return 0; + } + else { + echo " "; + echo ""; + return 1; + } + else { + echo " "; + echo ""; + return 1; + } + +} + +function check_variable ( $var, $value, $label, $mode ) { + echo ""; + echo " $label "; + echo ""; + if ($mode == 1) { + if ($var >= $value) { + echo " "; + return 0; + } + else { + echo " "; + return 1; + } + } + elseif ($var == $value) { + echo " "; + return 0; + } + else { + echo " "; + return 1; + } + echo ""; +} + +function parse_mysql_dump($url) { + if (file_exists($url)) { + $file_content = file($url); + $query = ""; + foreach($file_content as $sql_line) { + if (trim($sql_line) != "" && strpos($sql_line, "--") === false) { + $query .= $sql_line; + if(preg_match("/;[\040]*\$/", $sql_line)) { + if (!$result = mysql_query($query)) { + echo mysql_error(); //Uncomment for debug + echo "
            $query
            "; + return 0; + } + $query = ""; + } + } + } + return 1; + } + else + return 0; +} + +function parse_postgresql_dump($connection, $url, $debug = false) { + if (file_exists($url)) { + $file_content = file($url); + + $query = ""; + + foreach ($file_content as $sql_line) { + $clean_line = trim($sql_line); + $comment = preg_match("/^(\s|\t)*--.*$/", $clean_line); + if ($comment) { + continue; + } + + if (empty($clean_line)) { + continue; + } + + $query .= $clean_line; + + //Check if the end of query with the the semicolon and any returns in the end of line + if(preg_match("/;[\040]*\$/", $clean_line)) { + //And execute and clean buffer + pg_send_query($connection, $query); + + $result = pg_get_result($connection); + + if ($debug) { + var_dump($query); + var_dump(pg_result_error($result)); + } + + if (pg_result_status($result) == PGSQL_FATAL_ERROR) { + echo pg_result_error($result); + echo "
            $query
            "; + + return 0; + } + + $query = ""; + } + } + + return 1; + } + else { + return 0; + } +} + +function parse_oracle_dump($connection, $url, $debug = false) { + if (file_exists($url)) { + $file_content = file($url); + + $query = ""; + $plsql_block = false; + + foreach ($file_content as $sql_line) { + $clean_line = trim($sql_line); + $comment = preg_match("/^(\s|\t)*--.*$/", $clean_line); + if ($comment) { + continue; + } + + if (empty($clean_line)) { + continue; + } + + //Support for PL/SQL blocks + if (preg_match("/^BEGIN$/", $clean_line)) { + $query .= $clean_line . ' '; + $plsql_block = true; + } + else{ + $query .= $clean_line; + } + + //Check query's end with a back slash and any returns in the end of line or if it's a PL/SQL block 'END;;' string + if ((preg_match("/;[\040]*\$/", $clean_line) && !$plsql_block) || + (preg_match("/^END;;[\040]*\$/", $clean_line) && $plsql_block)) { + $plsql_block = false; + //Execute and clean buffer + + //Delete the last semicolon from current query + $query = substr($query, 0, strlen($query) - 1); + $sql = oci_parse($connection, $query); + $result = oci_execute($sql); + + if ($debug) { + var_dump($query); + } + + if (!$result) { + $e = oci_error($sql); + echo "
            Errors creating schema:
            "; + echo htmlentities($e['message'], ENT_QUOTES); + echo "
            $query
            "; + echo "
            "; + + return 0; + } + + $query = ""; + oci_free_statement($sql); + } + } + + return 1; + } + else { + return 0; + } +} + +function oracle_drop_all_objects ($connection) { + //Drop all objects of the current installation + $stmt = oci_parse($connection, + "BEGIN " . + "FOR cur_rec IN (SELECT object_name, object_type " . + "FROM user_objects " . + "WHERE object_type IN ('TABLE', 'VIEW', 'PACKAGE', 'PROCEDURE', 'FUNCTION', 'SEQUENCE', 'SNAPSHOT', 'MATERIALIZED VIEW')) LOOP " . + "BEGIN " . + "IF cur_rec.object_type = 'TABLE' THEN " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\" CASCADE CONSTRAINTS'; " . + "ELSE " . + "EXECUTE IMMEDIATE 'DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'; " . + "END IF; " . + "EXCEPTION " . + "WHEN OTHERS THEN " . + "DBMS_OUTPUT.put_line('FAILED: DROP ' || cur_rec.object_type || ' \"' || cur_rec.object_name || '\"'); " . + "END; " . + "END LOOP; " . + "END; "); + + $result = oci_execute($stmt); + oci_free_statement($stmt); + + return 0; +} + +function random_name ($size) { + $temp = ""; + for ($a=0;$a< $size;$a++) + $temp = $temp. chr(rand(122,97)); + + return $temp; +} + +function print_logo_status ($step, $step_total) { + global $banner; + + return " +
            +
            +
            + $banner +
            +
            + Install step $step of $step_total +
            +
            "; +} + +// +// This function adjusts path settings in pandora db for FreeBSD. +// +// All packages and configuration files except operating system's base files +// are installed under /usr/local in FreeBSD. So, path settings in pandora db +// for some programs should be changed from the Linux default. +// +function adjust_paths_for_freebsd($engine, $connection = false) { + + $adjust_sql = array( + "update trecon_script set script = REPLACE(script,'/usr/share','/usr/local/share');", + "update tconfig set value = REPLACE(value,'/usr/bin','/usr/local/bin') where token='netflow_daemon' OR token='netflow_nfdump' OR token='netflow_nfexpire';", + "update talert_commands set command = REPLACE(command,'/usr/bin','/usr/local/bin');", + "update talert_commands set command = REPLACE(command,'/usr/share', '/usr/local/share');", + "update tplugin set execute = REPLACE(execute,'/usr/share','/usr/local/share');", + "update tevent_response set target = REPLACE(target,'/usr/share','/usr/local/share');" + ); + + for ($i = 0; $i < count ($adjust_sql); $i++) { + switch ($engine) { + case 'mysql': + $result = mysql_query($adjust_sql[$i]); + break; + case 'oracle': + //Delete the last semicolon from current query + $query = substr($adjust_sql[$i], 0, strlen($adjust_sql[$i]) - 1); + $sql = oci_parse($connection, $query); + $result = oci_execute($sql); + break; + case 'pgsql': + pg_send_query($connection, $adjust_sql[$i]); + $result = pg_get_result($connection); + break; + } + if (!$result) { + return 0; + } + } + + return 1; +} + +function install_step1() { + global $banner; + + echo " +
            +
            + " . print_logo_status (1,6) . " +
            +

            Welcome to Pandora FMS installation Wizard

            +

            This wizard helps you to quick install Pandora FMS console and main database in your system.

            +

            In four steps, this installer will check all dependencies and will create your configuration, ready to use.

            +

            For more information, please refer to documentation.
            + Pandora FMS Development Team

            + "; + if (file_exists("include/config.php")) { + echo "
            Warning: You already have a config.php file. + Configuration and database would be overwritten if you continued.
            "; + } + echo "
            "; + echo ""; + $writable = check_writable ( "include", "Checking if ./include is writable"); + if (file_exists("include/config.php")) + $writable += check_writable ( "include/config.php", "Checking if include/config.php is writable"); + echo "
            "; + + echo "
            Warning: This installer will overwrite and destroy + your existing Pandora FMS configuration and Database. Before continue, + please be sure that you have no valuable Pandora FMS data in your Database.
            +
            "; + + echo "
            Upgrade: + If you want to upgrade from Pandora FMS 4.x to 5.0 version, please use the migration tool inside /extras directory in this setup. +
            "; + + if ($writable == 0) { + echo "
            "; + echo ""; + } + else { + echo "
            ERROR:You need to setup permissions to be able to write in ./include directory
            "; + echo "
            "; + } + + echo "
            "; + echo " +
            +
            + Pandora FMS is an OpenSource Software project registered at + SourceForge +
            + "; +} + +function install_step1_licence() { + echo " +
            +
            + " . print_logo_status (2,6) . " +
            +

            GPL2 Licence terms agreement

            +

            Pandora FMS is an OpenSource software project licensed under the GPL2 licence. Pandora FMS includes, as well, another software also licensed under LGPL and BSD licenses. Before continue, you must accept the licence terms.. +

            For more information, please refer to our website at http://pandorafms.org and contact us if you have any kind of question about the usage of Pandora FMS

            +

            If you dont accept the licence terms, please, close your browser and delete Pandora FMS files.

            + "; + + if (!file_exists("COPYING")) { + echo "
            Licence file 'COPYING' is not present in your distribution. This means you have some 'partial' Pandora FMS distribution. We cannot continue without accepting the licence file."; + echo "
            "; + } + else { + echo "
            "; + echo ""; + echo "

            "; + echo "

            "; + } + echo "
            "; + + echo "
            +
            +
            + Pandora FMS is an OpenSource Software project registered at + SourceForge +
            +
            "; +} + +function install_step2() { + + echo " +
            +
            + " . print_logo_status (3,6) . " +
            "; + echo "

            Checking software dependencies

            "; + echo ""; + $res = 0; + $res += check_variable(phpversion(),"5.2","PHP version >= 5.2",1); + $res += check_extension("gd","PHP GD extension"); + $res += check_extension("ldap","PHP LDAP extension"); + $res += check_extension("snmp","PHP SNMP extension"); + $res += check_extension("session","PHP session extension"); + $res += check_extension("gettext","PHP gettext extension"); + $res += check_extension("mbstring","PHP Multibyte String"); + $res += check_extension("zip","PHP Zip"); + $res += check_extension("zlib","PHP Zlib extension"); + $res += check_extension("curl","CURL (Client URL Library)"); + if (PHP_OS == "FreeBSD") { + $res += check_exists ("/usr/local/bin/twopi","Graphviz Binary"); + } + else if (PHP_OS == "NetBSD") { + $res += check_exists ("/usr/pkg/bin/twopi","Graphviz Binary"); + } + else { + $res += check_exists ("/usr/bin/twopi","Graphviz Binary"); + } + + echo ""; + check_extension("mysql", "PHP MySQL extension"); + check_extension("pgsql", "PHP PostgreSQL extension"); + check_extension("oci8", "PHP Oracle extension"); + echo "
            "; + echo "DB Engines"; + echo ""; + echo "
            "; + + if ($res > 0) { + echo " +
            You have some incomplete + dependencies. Please correct them or this installer + will not be able to finish your installation. +
            +
            + Remember, if you install any PHP module to comply + with these dependences, you need to restart + your HTTP/Apache server after it to use the new + modules. +
            +
            + Ignore it. Force install Step #3 +
            "; + echo "
            "; + } + else { + echo "
            "; + echo "
            +
            +
            "; + } + echo " +
            +
            + +
            + Pandora FMS is an OpenSource Software project registered at + SourceForge +
            + "; +} + + +function install_step3() { + $options = ''; + if (extension_loaded("mysql")) { + $options .= ""; + } + if (extension_loaded("pgsql")) { + $options .= ""; + } + if (extension_loaded("oci8")) { + $options .= ""; + } + + $error = false; + if (empty($options)) { + $error = true; + } + + echo " +
            +
            + " . print_logo_status (4,6) . " +
            +

            Environment and database setup

            +

            + This wizard will create your Pandora FMS database, + and populate it with all the data needed to run for the first time. +

            +

            + You need a privileged user to create database schema, this is usually root user. + Information about root user will not be used or stored anymore. +

            +

            + You can also deploy the scheme into an existing Database. + In this case you need a privileged Database user and password of that instance. +

            +

            + Now, please, complete all details to configure your database and environment setup. +

            +
            + Warning: This installer will overwrite and destroy your existing + Pandora FMS configuration and Database. Before continue, + please be sure that you have no valuable Pandora FMS data in your Database. +

            +
            "; + + if (extension_loaded("oci8")) { + echo "
            For Oracle installation an existing Database with a privileged user is needed.
            "; + } + if (!$error) { + echo ""; + } + + echo ""; + echo "
            "; + echo "DB Engine
            "; + + + if ($error) { + echo " +
            + Warning: You haven't a any DB engine with PHP. Please check the previous step to DB engine dependencies. +
            "; + } + else { + echo ""; + + echo "
            "; + echo " Installation in
            "; + echo ""; + } + echo "
            DB User with privileges
            + + +
            DB Password for this user
            + + +
            DB Hostname
            + + +
            DB Name (pandora by default)
            + + +
            + Drop Database if exists
            + + + +
            Full path to HTTP publication directory
            + For example /var/www/pandora_console/ +
            + + +
            URL path to Pandora FMS Console
            + For example '/pandora_console' +
            + +
            + "; + + + echo "
            "; + + if (!$error) { + echo ""; + } + + echo ""; + + echo "
            "; + echo "
            +
            + Pandora FMS is an OpenSource Software project registered at + SourceForge +
            +
            "; +} + +function install_step4() { + $pandora_config = "include/config.php"; + + if ( (! isset($_POST["user"])) || (! isset($_POST["dbname"])) || (! isset($_POST["host"])) || + (! isset($_POST["pass"])) || (!isset($_POST['engine'])) || (! isset($_POST["db_action"])) ) { + $dbpassword = ""; + $dbuser = ""; + $dbhost = ""; + $dbname = ""; + $engine = ""; + $dbaction = ""; + } + else { + $engine = $_POST['engine']; + $dbpassword = $_POST["pass"]; + $dbuser = $_POST["user"]; + $dbhost = $_POST["host"]; + $dbaction = $_POST["db_action"]; + if (isset($_POST["drop"])) + $dbdrop = $_POST["drop"]; + else + $dbdrop = 0; + + $dbname = $_POST["dbname"]; + if (isset($_POST["url"])) + $url = $_POST["url"]; + else + $url = "http://localhost"; + if (isset($_POST["path"])) { + $path = $_POST["path"]; + $path = str_replace("\\", "/", $path); // Windows compatibility + } + else + $path = "/var/www"; + } + $everything_ok = 0; + $step1=0; + $step2=0; + $step3=0; + $step4=0; $step5=0; $step6=0; $step7=0; + + echo " +
            +
            + " . print_logo_status(5,6) . " +
            +

            Creating database and default configuration file

            + "; + switch ($engine) { + case 'mysql': + if (! mysql_connect ($dbhost, $dbuser, $dbpassword)) { + check_generic ( 0, "Connection with Database"); + } + else { + check_generic ( 1, "Connection with Database"); + + // Drop database if needed and don't want to install over an existing DB + if ($dbdrop == 1) { + mysql_query ("DROP DATABASE IF EXISTS `$dbname`"); + } + + // Create schema + if ($dbaction == 'db_new' || $dbdrop == 1) { + $step1 = mysql_query ("CREATE DATABASE `$dbname`"); + check_generic ($step1, "Creating database '$dbname'"); + } + else { + $step = 1; + } + if ($step1 == 1) { + $step2 = mysql_select_db($dbname); + check_generic ($step2, "Opening database '$dbname'"); + + $step3 = parse_mysql_dump("pandoradb.sql"); + check_generic ($step3, "Creating schema"); + + $step4 = parse_mysql_dump("pandoradb_data.sql"); + check_generic ($step4, "Populating database"); + if (PHP_OS == "FreeBSD") { + $step_freebsd = adjust_paths_for_freebsd ($engine); + check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); + } + + $random_password = random_name (8); + $host = 'localhost'; + if ($dbhost != 'localhost') + $host = $_SERVER['SERVER_ADDR']; + $step5 = mysql_query ("GRANT ALL PRIVILEGES ON `$dbname`.* to pandora@$host + IDENTIFIED BY '".$random_password."'"); + mysql_query ("FLUSH PRIVILEGES"); + check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
            Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
            "); + + $step6 = is_writable("include"); + check_generic ($step6, "Write permissions to save config file in './include'"); + + $cfgin = fopen ("include/config.inc.php","r"); + $cfgout = fopen ($pandora_config,"w"); + $config_contents = fread ($cfgin, filesize("include/config.inc.php")); + $dbtype = 'mysql'; + $config_new = ''; + $step7 = fputs ($cfgout, $config_new); + $step7 = $step7 + fputs ($cfgout, $config_contents); + if ($step7 > 0) + $step7 = 1; + fclose ($cfgin); + fclose ($cfgout); + chmod ($pandora_config, 0600); + check_generic ($step7, "Created new config file at '".$pandora_config."'"); + } + } + + if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { + $everything_ok = 1; + } + break; + case 'oracle': + $connection = oci_connect($dbuser, $dbpassword, '//' . $dbhost . '/' . $dbname); + if (!$connection) { + check_generic(0, "Connection with Database"); + } + else { + check_generic(1, "Connection with Database"); + + // Drop all objects if needed + if ($dbdrop == 1) { + oracle_drop_all_objects($connection); + } + + $step1 = parse_oracle_dump($connection, "pandoradb.oracle.sql"); + + check_generic($step1, "Creating schema"); + + if ($step1) { + $step2 = parse_oracle_dump($connection, "pandoradb.data.oracle.sql"); + } + + check_generic ($step2, "Populating database"); + + if (PHP_OS == "FreeBSD") + { + $step_freebsd = adjust_paths_for_freebsd ($engine, $connection); + check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); + } + + echo ""; + + if ($step2) { + $step3 = is_writable("include"); + } + + check_generic ($step3, "Write permissions to save config file in './include'"); + + if ($step3) { + $cfgin = fopen ("include/config.inc.php","r"); + $cfgout = fopen ($pandora_config,"w"); + $config_contents = fread ($cfgin, filesize("include/config.inc.php")); + $dbtype = 'oracle'; + $config_new = ''; + $step4 = fputs ($cfgout, $config_new); + $step4 = $step4 + fputs ($cfgout, $config_contents); + if ($step4 > 0) + $step4 = 1; + fclose ($cfgin); + fclose ($cfgout); + chmod ($pandora_config, 0600); + } + + check_generic ($step4, "Created new config file at '" . $pandora_config . "'"); + + if (($step4 + $step3 + $step2 + $step1) == 4) { + $everything_ok = 1; + } + + } + break; + case 'pgsql': + $step1 = $step2 = $step3 = $step4 = $step5 = $step6 = $step7 = 0; + + $connection = pg_connect("host='" . $dbhost . "' dbname='postgres' user='" . $dbuser . "' password='" . $dbpassword . "'"); + if ($connection === false) { + check_generic(0, "Connection with Database"); + } + else { + check_generic(1, "Connection with Database"); + + // Drop database if needed + if ($dbdrop == 1 && $dbaction == 'db_exist') { + $result = pg_query($connection, "DROP DATABASE \"" . $dbname . "\";"); + } + + if ($dbaction != 'db_exist' || $dbdrop == 1) { + pg_send_query($connection, "CREATE DATABASE \"" . $dbname . "\" WITH ENCODING 'utf8';"); + $result = pg_get_result($connection); + if (pg_result_status($result) != PGSQL_FATAL_ERROR) { + $step1 = 1; + } + + check_generic ($step1, "Creating database '$dbname'"); + } + else { + $step1 = 1; + } + + check_generic ($step1, "Creating database '$dbname'"); + + if ($step1 == 1) { + //Reopen DB because I don't know how to use DB in PostgreSQL + pg_close($connection); + + $connection = pg_connect("host='" . $dbhost . "' dbname='" . $dbname . + "' user='" . $dbuser . "' password='" . $dbpassword . "'"); + + if ($connection !== false) { + $step2 = 1; + } + } + + check_generic ($step2, "Opening database '$dbname'"); + + if ($step2) { + $step3 = parse_postgresql_dump($connection, "pandoradb.postgreSQL.sql"); + } + + check_generic($step3, "Creating schema"); + + if ($step3) { + $step4 = parse_postgresql_dump($connection, "pandoradb.data.postgreSQL.sql"); + } + + check_generic ($step4, "Populating database"); + + if (PHP_OS == "FreeBSD") + { + $step_freebsd = adjust_paths_for_freebsd ($engine, $connection); + check_generic ($step_freebsd, "Adjusting paths in database for FreeBSD"); + } + + if ($step4) { + $random_password = random_name (8); + + pg_query($connection, "DROP USER pandora"); + pg_send_query($connection, "CREATE USER pandora WITH PASSWORD '" . $random_password . "'"); + $result = pg_get_result($connection); + + if (pg_result_status($result) != PGSQL_FATAL_ERROR) { + //Set the privileges for DB + pg_send_query($connection, "GRANT ALL PRIVILEGES ON DATABASE pandora TO pandora;"); + $result = pg_get_result($connection); + + $setDBPrivileges = 0; + if (pg_result_status($result) != PGSQL_FATAL_ERROR) { + $setDBPrivileges = 1; + } + + if ($setDBPrivileges) { + //Set the privileges for each tables. + pg_send_query($connection, "SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';"); + $result = pg_get_result($connection); + + $tables = array(); + while ($row = pg_fetch_assoc($result)) { + $tables[] = $row['table_name']; + } + + $correct = 1; + foreach ($tables as $table) { + pg_send_query($connection, "GRANT ALL PRIVILEGES ON TABLE " . $table . " TO pandora;"); + $result = pg_get_result($connection); + + if (pg_result_status($result) == PGSQL_FATAL_ERROR) { + $correct = 0; + break; + } + + //For each table make owner pandora + pg_send_query($connection, "ALTER TABLE " . $table . " OWNER TO pandora;"); + $result = pg_get_result($connection); + + if (pg_result_status($result) == PGSQL_FATAL_ERROR) { + $correct = 0; + break; + } + + //INI ----- Grant for secuences + pg_send_query($connection, "SELECT column_name FROM information_schema.columns WHERE table_name = '" . $table . "';"); + $result2 = pg_get_result($connection); + + $columns = array(); + while ($row = pg_fetch_assoc($result2)) { + $columns[] = $row['column_name']; + } + + //Check for each column if it have a sequence to grant + foreach ($columns as $column) { + pg_send_query($connection, "SELECT pg_get_serial_sequence('" . $table . "', '" . $column . "');"); + $result3 = pg_get_result($connection); + + $sequence = pg_fetch_assoc($result3); + if (!empty($sequence['pg_get_serial_sequence'])) { + pg_send_query($connection, "GRANT ALL PRIVILEGES ON SEQUENCE " . $sequence['pg_get_serial_sequence'] . " to pandora;"); + $result4 = pg_get_result($connection); + + if (pg_result_status($result4) == PGSQL_FATAL_ERROR) { + $correct = 0; + break; + } + } + } + //END ----- Grant for secuences + + } + + if ($correct) { + $step5 = 1; + } + } + } + } + + check_generic ($step5, "Established privileges for user pandora. A new random password has been generated: $random_password
            Please write it down, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file
            "); + + if ($step5) { + $step6 = is_writable("include"); + } + + check_generic ($step6, "Write permissions to save config file in './include'"); + + if ($step6) { + $cfgin = fopen ("include/config.inc.php","r"); + $cfgout = fopen ($pandora_config,"w"); + $config_contents = fread ($cfgin, filesize("include/config.inc.php")); + $dbtype = 'postgresql'; + $config_new = ''; + $step7 = fputs ($cfgout, $config_new); + $step7 = $step7 + fputs ($cfgout, $config_contents); + if ($step7 > 0) + $step7 = 1; + fclose ($cfgin); + fclose ($cfgout); + chmod ($pandora_config, 0600); + } + + check_generic ($step7, "Created new config file at '".$pandora_config."'"); + + if (($step7 + $step6 + $step5 + $step4 + $step3 + $step2 + $step1) == 7) { + $everything_ok = 1; + } + } + break; + } + echo "
            Please, you will need to setup your Pandora FMS server, editing the /etc/pandora/pandora_server.conf file and set database password.
            "; + + if ($everything_ok == 1) { + echo "
            "; + echo ""; + } + else { + $info = "
            There were some problems. + Installation was not completed. +

            Please correct failures before trying again. + All database "; + if ($engine == 'oracle') + $info .= "objects "; + else + $info .= "schemes "; + + $info .= "created in this step have been dropped.

            +
            "; + echo $info; + + switch ($engine) { + case 'mysql': + if (mysql_error() != "") { + echo "
            ERROR: ". mysql_error().".
            "; + } + + if ($step1 == 1) { + mysql_query ("DROP DATABASE $dbname"); + } + break; + case 'pgsql': + break; + case 'oracle': + oracle_drop_all_objects($connection); + break; + } + echo "
            "; + } + + echo "
            "; + echo " +
            +
            + Pandora FMS is an Open Source Software project registered at + SourceForge +
            + "; +} + + +function install_step5() { + echo " +
            +
            + " . print_logo_status (6,6) . " +
            +

            Installation complete

            +

            For security, you now must manually delete this installer + ('install.php') file before trying to access to your Pandora FMS console. +

            You should also install Pandora FMS Servers before trying to monitor anything; + please read documentation on how to install it.

            +

            Default user is 'admin' with password 'pandora', + please change it both as soon as possible.

            +

            Don't forget to check http://pandorafms.com + for updates. +


            Click here to access to your Pandora FMS console. +

            +
            "; + echo "
            +
            + Pandora FMS is an OpenSource Software project registered at + SourceForge +
            +
            "; +} +?> From 58c4b49020a2d4e2208b1f357af5b2af5aeab31e Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 11:01:17 +0100 Subject: [PATCH 81/92] Added new constants and functions to get the status images in their 'ball' type --- pandora_console/include/constants.php | 25 ++++++++++++ pandora_console/include/functions_agents.php | 40 +++++++++++++++++++- 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/constants.php b/pandora_console/include/constants.php index b33ac7fdfa..d6ad8bca8f 100755 --- a/pandora_console/include/constants.php +++ b/pandora_console/include/constants.php @@ -260,6 +260,31 @@ define ('STATUS_SERVER_OK', 'server_ok.png'); define ('STATUS_SERVER_DOWN', 'server_down.png'); +/* Status images (ball) */ +//For modules +define ('STATUS_MODULE_OK_BALL', 'module_ok_ball.png'); +define ('STATUS_MODULE_CRITICAL_BALL', 'module_critical_ball.png'); +define ('STATUS_MODULE_WARNING_BALL', 'module_warning_ball.png'); +define ('STATUS_MODULE_NO_DATA_BALL', 'module_no_data_ball.png'); +define ('STATUS_MODULE_UNKNOWN_BALL', 'module_unknown_ball.png'); +//For agents +define ('STATUS_AGENT_CRITICAL_BALL', 'agent_critical_ball.png'); +define ('STATUS_AGENT_WARNING_BALL', 'agent_warning_ball.png'); +define ('STATUS_AGENT_DOWN_BALL', 'agent_down_ball.png'); +define ('STATUS_AGENT_UNKNOWN_BALL', 'agent_unknown_ball.png'); +define ('STATUS_AGENT_OK_BALL', 'agent_ok_ball.png'); +define ('STATUS_AGENT_NO_DATA_BALL', 'agent_no_data_ball.png'); +define ('STATUS_AGENT_NO_MONITORS_BALL', 'agent_no_monitors_ball.png'); +define ('STATUS_AGENT_NOT_INIT_BALL', 'agent_notinit_ball.png'); +//For alerts +define ('STATUS_ALERT_FIRED_BALL', 'alert_fired_ball.png'); +define ('STATUS_ALERT_NOT_FIRED_BALL', 'alert_not_fired_ball.png'); +define ('STATUS_ALERT_DISABLED_BALL', 'alert_disabled_ball.png'); +//For servers +define ('STATUS_SERVER_OK_BALL', 'server_ok_ball.png'); +define ('STATUS_SERVER_DOWN_BALL', 'server_down_ball.png'); + + /* Events criticity */ define ('EVENT_CRIT_MAINTENANCE', 0); diff --git a/pandora_console/include/functions_agents.php b/pandora_console/include/functions_agents.php index 9bc2cbc8ec..da7cbc39aa 100644 --- a/pandora_console/include/functions_agents.php +++ b/pandora_console/include/functions_agents.php @@ -2028,6 +2028,18 @@ function agents_tree_view_alert_img ($alert_fired) { } } +//Returns the alert ball image to display tree view + +function agents_tree_view_alert_img_ball ($alert_fired) { + + if ($alert_fired) { + return ui_print_status_image (STATUS_ALERT_FIRED_BALL, __('Alert fired'), true); + } + else { + return ui_print_status_image (STATUS_ALERT_NOT_FIRED_BALL, __('Alert not fired'), true); + } +} + //Returns the status image to display tree view function agents_tree_view_status_img ($critical, $warning, $unknown, $total, $notinit) { @@ -2048,7 +2060,33 @@ function agents_tree_view_status_img ($critical, $warning, $unknown, $total, $no __('At least one module is in UKNOWN status'), true); } else { - return ui_print_status_image (STATUS_AGENT_OK, __('All Monitors OK'), true); + return ui_print_status_image (STATUS_AGENT_OK, + __('All Monitors OK'), true); + } +} + +//Returns the status ball image to display tree view + +function agents_tree_view_status_img_ball ($critical, $warning, $unknown, $total, $notinit) { + if ($total == 0 || $total == $notinit) { + return ui_print_status_image (STATUS_AGENT_NO_MONITORS_BALL, + __('No Monitors'), true); + } + if ($critical > 0) { + return ui_print_status_image (STATUS_AGENT_CRITICAL_BALL, + __('At least one module in CRITICAL status'), true); + } + else if ($warning > 0) { + return ui_print_status_image (STATUS_AGENT_WARNING_BALL, + __('At least one module in WARNING status'), true); + } + else if ($unknown > 0) { + return ui_print_status_image (STATUS_AGENT_DOWN_BALL, + __('At least one module is in UKNOWN status'), true); + } + else { + return ui_print_status_image (STATUS_AGENT_OK_BALL, + __('All Monitors OK'), true); } } From 0d2422ee2e74f95876316cd1e57562bdc2a33a40 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 11:03:36 +0100 Subject: [PATCH 82/92] Minor visual changes --- pandora_console/include/styles/pandora.css | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index 2bd0142f67..f433683b12 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2860,7 +2860,7 @@ table#policy_modules td * { background: 0 0; } .node-content { - height: 25px; + height: 21px; } .node-content:hover { @@ -2927,7 +2927,7 @@ table#policy_modules td * { .tree-node>.node-content>img { max-height: 20px; - max-width: 20px; + /*max-width: 20px;*/ } .tree-node>.node-content>img.module-data, @@ -2936,7 +2936,10 @@ table#policy_modules td * { padding-right: 3px; } -.tree-node>.node-content>img.module-server-type { +.tree-node>.node-content>img.module-server-type, +.tree-node>.node-content>img.agent-status, +.tree-node>.node-content>img.agent-alerts-fired, +.tree-node>.node-content>img.module-status { padding-right: 3px; } From 63af87933f15f59bcad387bb98e7cc128c346de5 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 11:04:16 +0100 Subject: [PATCH 83/92] Modifications on the search filter --- pandora_console/operation/tree2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandora_console/operation/tree2.php b/pandora_console/operation/tree2.php index 760f6e86e3..3b270a505b 100644 --- a/pandora_console/operation/tree2.php +++ b/pandora_console/operation/tree2.php @@ -167,7 +167,7 @@ echo ""; parameters['getChildren'] = 1; parameters['filter'] = {}; parameters['type'] = ""; - parameters['filter']['search'] = $("input#text-search").val(); + parameters['filter']['searchAgent'] = $("input#text-search").val(); parameters['filter']['status'] = $("select#status").val(); parameters['childrenMethod'] = 'live'; parameters['countModuleStatusMethod'] = 'live'; From 2c2011c0c7804060c5e3f14fc647116e759a1c1b Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 11:07:16 +0100 Subject: [PATCH 84/92] Improvements in the data retrieving and management --- pandora_console/include/class/Tree.class.php | 902 ++++++++++--------- 1 file changed, 468 insertions(+), 434 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index b55ab9ba76..8f5319ac60 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -53,198 +53,230 @@ class Tree { public function setFilter($filter) { $this->filter = $filter; } + + protected function processModule (&$module) { + global $config; + + $module['type'] = 'module'; + $module['id'] = (int) $module['id_agente_modulo']; + $module['name'] = $module['nombre']; + $module['id_module_type'] = (int) $module['id_tipo_modulo']; + $module['server_type'] = (int) $module['id_modulo']; + // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); + // $module['value'] = modules_get_last_value($module['id']); + + // Status + switch (modules_get_status($module['id'])) { + case AGENT_MODULE_STATUS_CRITICAL_BAD: + case AGENT_MODULE_STATUS_CRITICAL_ALERT: + $module['status'] = "critical"; + break; + case AGENT_MODULE_STATUS_WARNING: + case AGENT_MODULE_STATUS_WARNING_ALERT: + $module['status'] = "warning"; + break; + case AGENT_MODULE_STATUS_UNKNOWN: + $module['status'] = "unknown"; + break; + case AGENT_MODULE_STATUS_NO_DATA: + case AGENT_MODULE_STATUS_NOT_INIT: + $module['status'] = "not_init"; + break; + case AGENT_MODULE_STATUS_NORMAL: + case AGENT_MODULE_STATUS_NORMAL_ALERT: + default: + $module['status'] = "ok"; + break; + } + + // HTML of the server type image + $module['serverTypeHTML'] = servers_show_type($module['server_type']); + + // Link to the Module graph + $graphType = return_graphtype($module['id']); + $winHandle = dechex(crc32($module['id'] . $module['name'])); + + $moduleGraphURL = $config['homeurl'] . + "/operation/agentes/stat_win.php?" . + "type=$graphType&" . + "period=86400&" . + "id=" . $module['id'] . "&" . + "label=" . rawurlencode(urlencode(base64_encode($module['name']))) . "&" . + "refresh=600"; + + $module['moduleGraph'] = array( + 'url' => $moduleGraphURL, + 'handle' => $winHandle + ); + } + + protected function processModules ($modules_aux, &$modules) { + if (!empty($modules_aux)) { + foreach ($modules_aux as $module) { + $this->processModule($module); + $modules[] = $module; + } + } + } + + protected function getModules ($parent = 0, $filter = array()) { + $modules = array(); + + $modules_aux = agents_get_modules($parent, + array('id_agente_modulo', 'nombre', 'id_tipo_modulo', 'id_modulo'), $filter); + + if (empty($modules_aux)) + $modules_aux = array(); + + // Process the modules + $this->processModules($modules_aux, $modules); + + return $modules; + } - public function getData() { - switch ($this->type) { - case 'os': - $this->getDataOS(); + protected function processAgent (&$agent, $modulesFilter = array(), $searchChildren = true) { + $agent['type'] = 'agent'; + $agent['id'] = (int) $agent['id_agente']; + $agent['name'] = $agent['nombre']; + + // Counters + $agent['counters'] = array(); + + if (isset($agent['unknown_count'])) + $agent['counters']['unknown'] = $agent['unknown_count']; + else + $agent['counters']['unknown'] = agents_monitor_unknown($agent['id']); + + if (isset($agent['critical_count'])) + $agent['counters']['critical'] = $agent['critical_count']; + else + $agent['counters']['critical'] = agents_monitor_critical($agent['id']); + + if (isset($agent['warning_count'])) + $agent['counters']['warning'] = $agent['warning_count']; + else + $agent['counters']['warning'] = agents_monitor_warning($agent['id']); + + if (isset($agent['notinit_count'])) + $agent['counters']['not_init'] = $agent['notinit_count']; + else + $agent['counters']['not_init'] = agents_monitor_notinit($agent['id']); + + if (isset($agent['normal_count'])) + $agent['counters']['ok'] = $agent['normal_count']; + else + $agent['counters']['ok'] = agents_monitor_ok($agent['id']); + + if (isset($agent['total_count'])) + $agent['counters']['total'] = $agent['total_count']; + else + $agent['counters']['total'] = agents_monitor_total($agent['id']); + + if (isset($agent['fired_count'])) + $agent['counters']['alerts'] = $agent['fired_count']; + else + $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); + + // Status image + $agent['statusImageHTML'] = agents_tree_view_status_img_ball( + $agent['counters']['critical'], + $agent['counters']['warning'], + $agent['counters']['unknown'], + $agent['counters']['total'], + $agent['counters']['not_init']); + + // Alerts fired image + $agent["alertImageHTML"] = agents_tree_view_alert_img_ball($agent['counters']['alerts']); + + // Status + $agent['statusRaw'] = agents_get_status($agent['id']); + switch ($agent['statusRaw']) { + case AGENT_STATUS_NORMAL: + $agent['status'] = "ok"; break; - case 'group': - $this->getDataGroup(); + case AGENT_STATUS_WARNING: + $agent['status'] = "warning"; break; - case 'module_group': - $this->getDataModuleGroup(); + case AGENT_STATUS_CRITICAL: + $agent['status'] = "critical"; break; - case 'module': - $this->getDataModules(); + case AGENT_STATUS_UNKNOWN: + $agent['status'] = "unknown"; break; - case 'tag': - $this->getDataTag(); + case AGENT_STATUS_NOT_INIT: + $agent['status'] = "not_init"; break; default: - $this->getDataExtended(); + $agent['status'] = "none"; + break; } - } - - protected function getDataExtended () { - // Override this method to add new types - } - - private function getDataOS() { - // Get the parent - if (empty($this->root)) - $parent = 0; - else - $parent = $this->root; + // Children + $agent['children'] = array(); + if ($agent['counters']['total'] > 0) { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 1; + break; + case 'live': + $agent['searchChildren'] = 0; - // ACL Group - if (isset($this->userGroups) && $this->userGroups === false) - return array(); - - $group_acl = ""; - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } - - // Agent name filter - $agent_search = ""; - if (!empty($this->filter['search'])) { - $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; - } - - $list_os = os_get_os(); - - // Transform the os array to use the item id as key - if (!empty($list_os)) { - $list_os_aux = array(); - foreach ($list_os as $os) { - $list_os_aux[$os['id_os']] = $os; - } - if (!empty($list_os_aux)) { - $list_os = $list_os_aux; - unset($list_os_aux); + if ($searchChildren) + $agent['children'] = $this->getModules($agent['id'], $modulesFilter); + break; } } - if (!empty($list_os)) { - $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, ta.id_os, tam.id_modulo, - ta.id_agente, ta.nombre AS agent_name - FROM tagente ta, tagente_modulo tam - WHERE ta.id_agente = tam.id_agente - AND ta.disabled = 0 - AND tam.disabled = 0 - $agent_search - $group_acl - ORDER BY ta.id_os ASC, ta.nombre ASC"; - $data = db_process_sql($sql); - } - - if (empty($data)) { - $data = array(); - } - - $nodes = array(); - $actual_os_root = array( - 'id' => null, - 'name' => '', - 'icon' => '', - 'children' => array(), - 'counters' => array() - ); - $actual_agent = array(); - foreach ($data as $key => $value) { - - // Module - $module = array(); - $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; - $module['nombre'] = $value['module_name']; - $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; - $module['server_type'] = (int) $value['id_modulo']; - - $this->processModule($module); - - // OS item - if ($actual_os_root['id'] === (int)$value['id_os']) { - // Agent - if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) { - // Add the last agent to the os item - if (!empty($actual_agent)) - $actual_os_root['children'][] = $actual_agent; - - // Create the new agent - $actual_agent = array(); - $actual_agent['id_agente'] = (int) $value['id_agente']; - $actual_agent['nombre'] = $value['agent_name']; - $actual_agent['children'] = array(); - - $this->processAgent(&$actual_agent, array(), false); - - // Add the module to the agent - $actual_agent['children'][] = $module; - - // Increase counters - $actual_os_root['counters']['total']++; - - if (isset($actual_os_root['counters'][$actual_agent['status']])) - $actual_os_root['counters'][$actual_agent['status']]++; - } - else { - // Add the module to the agent - $actual_agent['children'][] = $module; - } + else { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 0; + break; + case 'live': + $agent['searchChildren'] = 0; + break; } - else { - // The first iteration doesn't enter here - if ($actual_os_root['id'] !== null) { - // Add the agent to the os item - $actual_os_root['children'][] = $actual_agent; - // Add the os the branch - $nodes[] = $actual_os_root; - } + } + } - // Create new os item - $actual_os_root = array(); - $actual_os_root['id'] = (int) $value['id_os']; - $actual_os_root['type'] = $this->type; + protected function processAgents (&$agents, $modulesFilter = array()) { + if (!empty($agents)) { + foreach ($agents as $iterator => $agent) { + $this->processAgent($agents[$iterator], $modulesFilter); + } + } + } - if (isset($list_os[$actual_os_root['id']])) { - $actual_os_root['name'] = $list_os[$actual_os_root['id']]['name']; - $actual_os_root['icon'] = $list_os[$actual_os_root['id']]['icon_name']; - } - else { - $actual_os_root['name'] = __('Other'); - $actual_os_root['icon'] = 'so_other.png'; + protected function getAgents ($parent = 0, $parentType = '') { + switch ($parentType) { + case 'group': + // ACL Groups + if (isset($this->userGroups) && $this->userGroups === false) + return array(); + + if (!empty($this->userGroups) && !empty($parent)) { + if (!isset($this->userGroups[$parent])) + return array(); } + $filter = array(); + $filter['id_grupo'] = $parent; + if (isset($this->filter['status']) && $this->filter['status'] != -1) + $filter['status'] = $this->filter['status']; + if (!empty($this->filter['search'])) + $filter['nombre'] = "%" . $this->filter['search'] . "%"; - // Create the new agent - $actual_agent = array(); - $actual_agent['id_agente'] = (int) $value['id_agente']; - $actual_agent['nombre'] = $value['agent_name']; - $actual_agent['children'] = array(); - - $this->processAgent(&$actual_agent, array(), false); - - // Add the module to the agent - $actual_agent['children'][] = $module; - - // Initialize counters - $actual_os_root['counters'] = array(); - $actual_os_root['counters']['total'] = 0; - $actual_os_root['counters']['alerts'] = 0; - $actual_os_root['counters']['critical'] = 0; - $actual_os_root['counters']['warning'] = 0; - $actual_os_root['counters']['unknown'] = 0; - $actual_os_root['counters']['not_init'] = 0; - $actual_os_root['counters']['ok'] = 0; - - // Increase counters - $actual_os_root['counters']['total']++; - - if (isset($actual_os_root['counters'][$actual_agent['status']])) - $actual_os_root['counters'][$actual_agent['status']]++; - } + $agents = agents_get_agents($filter, array('id_agente', 'nombre')); + if (empty($agents)) { + $agents = array(); + } + break; + default: + return array(); + break; } - // If there is an agent and an os item opened and not saved - if ($actual_os_root['id'] !== null) { - // Add the last agent to the os item - $actual_os_root['children'][] = $actual_agent; - // Add the last os to the branch - $nodes[] = $actual_os_root; - } - - $this->tree = $nodes; + + $this->processAgents($agents); + + return $agents; } protected function getGroupsRecursive($parent, $limit = null, $get_agents = true) { @@ -368,6 +400,32 @@ class Tree { return $groups; } + public function getData() { + switch ($this->type) { + case 'os': + $this->getDataOS(); + break; + case 'group': + $this->getDataGroup(); + break; + case 'module_group': + $this->getDataModuleGroup(); + break; + case 'module': + $this->getDataModules(); + break; + case 'tag': + $this->getDataTag(); + break; + default: + $this->getDataExtended(); + } + } + + protected function getDataExtended () { + // Override this method to add new types + } + private function getDataGroup() { // Get the parent if (empty($this->root)) @@ -383,93 +441,7 @@ class Tree { $this->tree = $groups; } - protected function processModule (&$module) { - global $config; - - $module['type'] = 'module'; - $module['id'] = (int) $module['id_agente_modulo']; - $module['name'] = $module['nombre']; - $module['id_module_type'] = (int) $module['id_tipo_modulo']; - $module['server_type'] = (int) $module['id_modulo']; - // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); - // $module['value'] = modules_get_last_value($module['id']); - - // Status - switch (modules_get_status($module['id'])) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: - case AGENT_MODULE_STATUS_CRITICAL_ALERT: - $module['status'] = "critical"; - break; - case AGENT_MODULE_STATUS_WARNING: - case AGENT_MODULE_STATUS_WARNING_ALERT: - $module['status'] = "warning"; - break; - case AGENT_MODULE_STATUS_UNKNOWN: - $module['status'] = "unknown"; - break; - case AGENT_MODULE_STATUS_NO_DATA: - case AGENT_MODULE_STATUS_NOT_INIT: - $module['status'] = "not_init"; - break; - case AGENT_MODULE_STATUS_NORMAL: - case AGENT_MODULE_STATUS_NORMAL_ALERT: - default: - $module['status'] = "ok"; - break; - } - - // HTML of the server type image - $module['serverTypeHTML'] = servers_show_type($module['server_type']); - - // Link to the Module graph - $graphType = return_graphtype($module['id']); - $winHandle = dechex(crc32($module['id'] . $module['name'])); - - $moduleGraphURL = $config['homeurl'] . - "/operation/agentes/stat_win.php?" . - "type=$graphType&" . - "period=86400&" . - "id=" . $module['id'] . "&" . - "label=" . rawurlencode(urlencode(base64_encode($module['name']))) . "&" . - "refresh=600"; - - $module['moduleGraph'] = array( - 'url' => $moduleGraphURL, - 'handle' => $winHandle - ); - } - - protected function processModules ($modules_aux, &$modules) { - if (!empty($modules_aux)) { - foreach ($modules_aux as $module) { - $this->processModule($module); - $modules[] = $module; - } - } - } - - protected function getModules ($parent = 0, $filter = array()) { - $modules = array(); - - $modules_aux = agents_get_modules($parent, - array('id_agente_modulo', 'nombre', 'id_tipo_modulo', 'id_modulo'), $filter); - - if (empty($modules_aux)) - $modules_aux = array(); - - // Process the modules - $this->processModules($modules_aux, $modules); - - return $modules; - } - private function getDataModules() { - // Get the parent - if (empty($this->root)) - $parent = 0; - else - $parent = $this->root; - // ACL Group if (isset($this->userGroups) && $this->userGroups === false) return array(); @@ -482,18 +454,28 @@ class Tree { // Agent name filter $agent_search = ""; - if (!empty($this->filter['search'])) { - $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; } - - $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, + + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, tam.id_tipo_modulo, tam.id_modulo, - ta.id_agente, ta.nombre AS agent_name - FROM tagente ta, tagente_modulo tam - WHERE ta.id_agente = tam.id_agente - AND ta.disabled = 0 - AND tam.disabled = 0 + ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count + FROM tagente_modulo AS tam + INNER JOIN tagente AS ta + ON ta.id_agente = tam.id_agente + AND ta.disabled = 0 + WHERE tam.disabled = 0 $agent_search + $module_search $group_acl ORDER BY tam.nombre ASC, ta.nombre ASC"; $data = db_process_sql($sql); @@ -510,7 +492,7 @@ class Tree { ); foreach ($data as $key => $value) { $agent = array(); - $agent['id_agente'] = $value['id_agente']; + $agent['id_agente'] = (int) $value['id_agente']; $agent['nombre'] = $value['agent_name']; $this->processAgent(&$agent, array(), false); @@ -566,127 +548,7 @@ class Tree { $this->tree = $modules; } - protected function processAgent (&$agent, $modulesFilter = array(), $searchChildren = true) { - $agent['type'] = 'agent'; - $agent['id'] = (int) $agent['id_agente']; - $agent['name'] = $agent['nombre']; - - // Counters - $agent['counters'] = array(); - $agent['counters']['unknown'] = - agents_monitor_unknown($agent['id']); - $agent['counters']['critical'] = - agents_monitor_critical($agent['id']); - $agent['counters']['warning'] = - agents_monitor_warning($agent['id']); - $agent['counters']['not_init'] = - agents_monitor_notinit($agent['id']); - $agent['counters']['ok'] = - agents_monitor_ok($agent['id']); - $agent['counters']['total'] = - agents_monitor_total($agent['id']); - $agent['counters']['alerts'] = - agents_get_alerts_fired($agent['id']); - - $agent['statusRaw'] = agents_get_status($agent['id']); - - // Status - switch ($agent['statusRaw']) { - case AGENT_STATUS_NORMAL: - $agent['status'] = "ok"; - break; - case AGENT_STATUS_WARNING: - $agent['status'] = "warning"; - break; - case AGENT_STATUS_CRITICAL: - $agent['status'] = "critical"; - break; - case AGENT_STATUS_UNKNOWN: - $agent['status'] = "unknown"; - break; - case AGENT_STATUS_NOT_INIT: - $agent['status'] = "not_init"; - break; - default: - $agent['status'] = "none"; - break; - } - - // Children - $agent['children'] = array(); - if ($agent['counters']['total'] > 0) { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 1; - break; - case 'live': - $agent['searchChildren'] = 0; - - if ($searchChildren) - $agent['children'] = $this->getModules($agent['id'], $modulesFilter); - break; - } - } - else { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 0; - break; - case 'live': - $agent['searchChildren'] = 0; - break; - } - } - } - - protected function processAgents (&$agents, $modulesFilter = array()) { - if (!empty($agents)) { - foreach ($agents as $iterator => $agent) { - $this->processAgent($agents[$iterator], $modulesFilter); - } - } - } - - protected function getAgents ($parent = 0, $parentType = '') { - switch ($parentType) { - case 'group': - // ACL Groups - if (isset($this->userGroups) && $this->userGroups === false) - return array(); - - if (!empty($this->userGroups) && !empty($parent)) { - if (!isset($this->userGroups[$parent])) - return array(); - } - $filter = array(); - $filter['id_grupo'] = $parent; - if (isset($this->filter['status']) && $this->filter['status'] != -1) - $filter['status'] = $this->filter['status']; - if (!empty($this->filter['search'])) - $filter['nombre'] = "%" . $this->filter['search'] . "%"; - - $agents = agents_get_agents($filter, array('id_agente', 'nombre')); - if (empty($agents)) { - $agents = array(); - } - break; - default: - return array(); - break; - } - - $this->processAgents($agents); - - return $agents; - } - private function getDataModuleGroup() { - // Get the parent - if (empty($this->root)) - $parent = 0; - else - $parent = $this->root; - // ACL Group if (isset($this->userGroups) && $this->userGroups === false) return array(); @@ -699,25 +561,34 @@ class Tree { // Agent name filter $agent_search = ""; - if (!empty($this->filter['search'])) { - $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; } - - $module_groups = modules_get_modulegroups(); - - if (!empty($module_groups)) { - $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, tam.id_module_group, tam.id_modulo, - ta.id_agente, ta.nombre AS agent_name - FROM tagente ta, tagente_modulo tam - WHERE ta.id_agente = tam.id_agente + + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, + ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tmg.id_mg, tmg.name AS module_group_name + FROM tagente_modulo AS tam + INNER JOIN tagente AS ta + ON ta.id_agente = tam.id_agente AND ta.disabled = 0 - AND tam.disabled = 0 - $agent_search - $group_acl - ORDER BY tam.id_module_group ASC, tam.nombre ASC, ta.nombre ASC"; - $data = db_process_sql($sql); - } + LEFT JOIN tmodule_group AS tmg + ON tmg.id_mg = tam.id_module_group + WHERE tam.disabled = 0 + $agent_search + $module_search + $group_acl + ORDER BY tmg.name ASC, tmg.id_mg ASC, ta.nombre ASC, tam.nombre ASC"; + $data = db_process_sql($sql); if (empty($data)) { $data = array(); @@ -725,7 +596,7 @@ class Tree { $nodes = array(); $actual_module_group_root = array( - 'id' => null, + 'id' => -1, 'name' => '', 'children' => array(), 'counters' => array() @@ -738,7 +609,7 @@ class Tree { $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; - $module['id_module_group'] = (int) $value['id_module_group']; + $module['id_module_group'] = (int) $value['id_mg']; $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); @@ -774,7 +645,7 @@ class Tree { } else { // The first iteration doesn't enter here - if ($actual_module_group_root['id'] !== null) { + if ($actual_module_group_root['id'] !== -1) { // Add the agent to the module group $actual_module_group_root['children'][] = $actual_agent; // Add the module group to the branch @@ -797,8 +668,8 @@ class Tree { $actual_module_group_root['id'] = $module['id_module_group']; $actual_module_group_root['type'] = $this->type; - if (isset($module_groups[$module['id_module_group']])) { - $actual_module_group_root['name'] = $module_groups[$module['id_module_group']]; + if (!empty($value['module_group_name'])) { + $actual_module_group_root['name'] = $value['module_group_name']; } else { $actual_module_group_root['name'] = __('Not assigned'); @@ -822,7 +693,7 @@ class Tree { } } // If there is an agent and a module group opened and not saved - if ($actual_module_group_root['id'] !== null) { + if ($actual_module_group_root['id'] !== -1) { // Add the last agent to the module group $actual_module_group_root['children'][] = $actual_agent; // Add the last module group to the branch @@ -832,13 +703,7 @@ class Tree { $this->tree = $nodes; } - private function getDataTag() { - // Get the parent - if (empty($this->root)) - $parent = 0; - else - $parent = $this->root; - + private function getDataOS() { // ACL Group if (isset($this->userGroups) && $this->userGroups === false) return array(); @@ -851,23 +716,193 @@ class Tree { // Agent name filter $agent_search = ""; - if (!empty($this->filter['search'])) { - $agent_search = " AND ta.nombre LIKE '%".$this->filter['search']."%' "; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; } - $sql = "SELECT tam.nombre AS module_name, tam.id_agente_modulo, - tam.id_tipo_modulo, tam.id_module_group, tam.id_modulo, - ta.id_agente, ta.nombre AS agent_name, - tt.name AS tag_name, tt.id_tag - FROM tagente ta, tagente_modulo tam, ttag_module ttm, ttag tt - WHERE ta.id_agente = tam.id_agente - AND tam.id_agente_modulo = ttm.id_agente_modulo - AND ttm.id_tag = tt.id_tag - AND ta.disabled = 0 - AND tam.disabled = 0 + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, + ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tos.id_os, tos.name AS os_name, tos.icon_name AS os_icon + FROM tagente_modulo AS tam + INNER JOIN tagente AS ta + ON ta.id_agente = tam.id_agente + AND ta.disabled = 0 + LEFT JOIN tconfig_os AS tos + ON tos.id_os = ta.id_os + WHERE tam.disabled = 0 $agent_search + $module_search $group_acl - ORDER BY tt.name ASC, ta.nombre ASC"; + ORDER BY tos.icon_name ASC, tos.id_os ASC, ta.nombre ASC, tam.nombre"; + $data = db_process_sql($sql); + + if (empty($data)) { + $data = array(); + } + + $nodes = array(); + $actual_os_root = array( + 'id' => -1, + 'name' => '', + 'icon' => '', + 'children' => array(), + 'counters' => array() + ); + $actual_agent = array(); + foreach ($data as $key => $value) { + + // Module + $module = array(); + $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; + $module['nombre'] = $value['module_name']; + $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['server_type'] = (int) $value['id_modulo']; + + $this->processModule($module); + + // OS item + if ($actual_os_root['id'] === (int)$value['id_os']) { + // Agent + if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) { + // Add the last agent to the os item + if (!empty($actual_agent)) + $actual_os_root['children'][] = $actual_agent; + + // Create the new agent + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + $actual_agent['children'] = array(); + + $this->processAgent(&$actual_agent, array(), false); + + // Add the module to the agent + $actual_agent['children'][] = $module; + + // Increase counters + $actual_os_root['counters']['total']++; + + if (isset($actual_os_root['counters'][$actual_agent['status']])) + $actual_os_root['counters'][$actual_agent['status']]++; + } + else { + // Add the module to the agent + $actual_agent['children'][] = $module; + } + } + else { + // The first iteration doesn't enter here + if ($actual_os_root['id'] !== -1) { + // Add the agent to the os item + $actual_os_root['children'][] = $actual_agent; + // Add the os the branch + $nodes[] = $actual_os_root; + } + + // Create new os item + $actual_os_root = array(); + $actual_os_root['id'] = (int) $value['id_os']; + $actual_os_root['type'] = $this->type; + + if (!empty($actual_os_root['id'])) { + $actual_os_root['name'] = $value['os_name']; + $actual_os_root['icon'] = $value['os_icon']; + } + else { + $actual_os_root['name'] = __('None'); + $actual_os_root['icon'] = 'so_other.png'; + } + + // Create the new agent + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + $actual_agent['children'] = array(); + + $this->processAgent(&$actual_agent, array(), false); + + // Add the module to the agent + $actual_agent['children'][] = $module; + + // Initialize counters + $actual_os_root['counters'] = array(); + $actual_os_root['counters']['total'] = 0; + $actual_os_root['counters']['alerts'] = 0; + $actual_os_root['counters']['critical'] = 0; + $actual_os_root['counters']['warning'] = 0; + $actual_os_root['counters']['unknown'] = 0; + $actual_os_root['counters']['not_init'] = 0; + $actual_os_root['counters']['ok'] = 0; + + // Increase counters + $actual_os_root['counters']['total']++; + + if (isset($actual_os_root['counters'][$actual_agent['status']])) + $actual_os_root['counters'][$actual_agent['status']]++; + } + } + // If there is an agent and an os item opened and not saved + if ($actual_os_root['id'] !== -1) { + // Add the last agent to the os item + $actual_os_root['children'][] = $actual_agent; + // Add the last os to the branch + $nodes[] = $actual_os_root; + } + + $this->tree = $nodes; + } + + private function getDataTag() { + // ACL Group + if (isset($this->userGroups) && $this->userGroups === false) + return array(); + + $group_acl = ""; + if (!empty($this->userGroups)) { + $user_groups_str = implode(",", array_keys($this->userGroups)); + $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; + } + + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; + } + + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, + ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tt.id_tag, tt.name AS tag_name + FROM tagente_modulo AS tam + INNER JOIN tagente AS ta + ON ta.id_agente = tam.id_agente + AND ta.disabled = 0 + INNER JOIN ttag_module AS ttm + ON ttm.id_agente_modulo = tam.id_agente_modulo + INNER JOIN ttag AS tt + ON tt.id_tag = ttm.id_tag + WHERE tam.disabled = 0 + $agent_search + $module_search + $group_acl + ORDER BY tt.name ASC, tt.id_tag ASC, ta.nombre ASC, tam.nombre ASC"; $data = db_process_sql($sql); if (empty($data)) { @@ -889,7 +924,6 @@ class Tree { $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; - $module['id_module_group'] = (int) $value['id_module_group']; $module['server_type'] = (int) $value['id_modulo']; $this->processModule($module); From f7de0555b2414ac3c6b7ae60b7c5f60a390b2bce Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 11:08:05 +0100 Subject: [PATCH 85/92] Now the tree shows more data of the items --- .../include/javascript/tree/TreeController.js | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index d495789347..0c2391bd81 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -306,9 +306,33 @@ TreeController = { $content.append(element.name); break; case 'agent': + // Status image + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("agent-status"); + + $content.append($statusImage); + } + // Alerts fired image + if (typeof element.alertImageHTML != 'undefined' + && element.alertImageHTML.length > 0) { + var $alertImage = $(element.alertImageHTML); + $alertImage.addClass("agent-alerts-fired"); + + $content.append($alertImage); + } $content.append(element.name); break; case 'module': + // Status image + if (typeof element.statusImageHTML != 'undefined' + && element.statusImageHTML.length > 0) { + var $statusImage = $(element.statusImageHTML); + $statusImage.addClass("module-status"); + + $content.append($statusImage); + } // Server type if (typeof element.serverTypeHTML != 'undefined' && element.serverTypeHTML.length > 0 @@ -316,7 +340,7 @@ TreeController = { var $serverTypeImage = $(element.serverTypeHTML); $serverTypeImage.addClass("module-server-type"); - $content.append($serverTypeImage) + $content.append($serverTypeImage); } // Graph pop-up From 25ce2a3ab9b5aace7d98ed7532b52ec8dd56ad6f Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Mon, 12 Jan 2015 12:47:54 +0100 Subject: [PATCH 86/92] Improved the data management --- pandora_console/include/class/Tree.class.php | 98 ++++++++++++++++---- 1 file changed, 82 insertions(+), 16 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 8f5319ac60..538a33e716 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -63,32 +63,61 @@ class Tree { $module['id_module_type'] = (int) $module['id_tipo_modulo']; $module['server_type'] = (int) $module['id_modulo']; // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); - // $module['value'] = modules_get_last_value($module['id']); + + if (!isset($module['status'])) + $module['status'] = modules_get_status($module['id']); + if (!isset($module['value'])) + $module['value'] = modules_get_last_value($module['id']); // Status - switch (modules_get_status($module['id'])) { - case AGENT_MODULE_STATUS_CRITICAL_BAD: + switch ($module['status']) { case AGENT_MODULE_STATUS_CRITICAL_ALERT: - $module['status'] = "critical"; + $module['alert'] = 1; + case AGENT_MODULE_STATUS_CRITICAL_BAD: + $statusType = STATUS_MODULE_CRITICAL_BALL; + $statusTitle = __('CRITICAL'); + $module['statusText'] = "critical"; break; - case AGENT_MODULE_STATUS_WARNING: case AGENT_MODULE_STATUS_WARNING_ALERT: - $module['status'] = "warning"; + $module['alert'] = 1; + case AGENT_MODULE_STATUS_WARNING: + $statusType = STATUS_MODULE_WARNING_BALL; + $statusTitle = __('WARNING'); + $module['statusText'] = "warning"; break; case AGENT_MODULE_STATUS_UNKNOWN: - $module['status'] = "unknown"; + $statusType = STATUS_MODULE_UNKNOWN_BALL; + $statusTitle = __('UNKNOWN'); + $module['statusText'] = "unknown"; break; case AGENT_MODULE_STATUS_NO_DATA: case AGENT_MODULE_STATUS_NOT_INIT: - $module['status'] = "not_init"; + $statusType = STATUS_MODULE_NO_DATA_BALL; + $statusTitle = __('NO DATA'); + $module['statusText'] = "not_init"; break; - case AGENT_MODULE_STATUS_NORMAL: case AGENT_MODULE_STATUS_NORMAL_ALERT: + $module['alert'] = 1; + case AGENT_MODULE_STATUS_NORMAL: default: - $module['status'] = "ok"; + $statusType = STATUS_MODULE_OK_BALL; + $statusTitle = __('NORMAL'); + $module['statusText'] = "ok"; break; } + if ($statusType !== STATUS_MODULE_UNKNOWN_BALL + && $statusType !== STATUS_MODULE_NO_DATA_BALL) { + if (is_numeric($module["value"])) { + $statusTitle .= " : " . format_for_graph($module["value"]); + } + else { + $statusTitle .= " : " . substr(io_safe_output($module["value"]),0,42); + } + } + + $module['statusImageHTML'] = ui_print_status_image($statusType, $statusTitle, true); + // HTML of the server type image $module['serverTypeHTML'] = servers_show_type($module['server_type']); @@ -111,12 +140,29 @@ class Tree { } protected function processModules ($modules_aux, &$modules) { + $counters = false; + if (!empty($modules_aux)) { + $counters = array( + 'critical' => 0, + 'warning' => 0, + 'ok' => 0, + 'not_init' => 0, + 'unknown' => 0, + 'alerts' => 0 + ); + foreach ($modules_aux as $module) { $this->processModule($module); $modules[] = $module; + + if (isset($counters[$module['statusText']])) + $counters[$module['statusText']]++; + if ($module['alert']) + $counters['alerts']++; } } + return $counters; } protected function getModules ($parent = 0, $filter = array()) { @@ -261,8 +307,8 @@ class Tree { $filter['id_grupo'] = $parent; if (isset($this->filter['status']) && $this->filter['status'] != -1) $filter['status'] = $this->filter['status']; - if (!empty($this->filter['search'])) - $filter['nombre'] = "%" . $this->filter['search'] . "%"; + if (!empty($this->filter['searchAgent'])) + $filter['nombre'] = "%" . $this->filter['searchAgent'] . "%"; $agents = agents_get_agents($filter, array('id_agente', 'nombre')); if (empty($agents)) { @@ -468,11 +514,14 @@ class Tree { tam.id_tipo_modulo, tam.id_modulo, ta.id_agente, ta.nombre AS agent_name, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, - ta.unknown_count, ta.notinit_count, ta.total_count + ta.unknown_count, ta.notinit_count, ta.total_count, + tae.estado, tae.datos FROM tagente_modulo AS tam INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + INNER JOIN tagente_estado AS tae + ON tae.id_agente_modulo = tam.id_agente_modulo WHERE tam.disabled = 0 $agent_search $module_search @@ -502,6 +551,8 @@ class Tree { $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['data']; $this->processModule($module); @@ -576,11 +627,14 @@ class Tree { ta.id_agente, ta.nombre AS agent_name, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, - tmg.id_mg, tmg.name AS module_group_name + tmg.id_mg, tmg.name AS module_group_name, + tae.estado, tae.datos FROM tagente_modulo AS tam INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + INNER JOIN tagente_estado AS tae + ON tae.id_agente_modulo = tam.id_agente_modulo LEFT JOIN tmodule_group AS tmg ON tmg.id_mg = tam.id_module_group WHERE tam.disabled = 0 @@ -611,6 +665,8 @@ class Tree { $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['id_module_group'] = (int) $value['id_mg']; $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['data']; $this->processModule($module); @@ -731,11 +787,14 @@ class Tree { ta.id_agente, ta.nombre AS agent_name, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, - tos.id_os, tos.name AS os_name, tos.icon_name AS os_icon + tos.id_os, tos.name AS os_name, tos.icon_name AS os_icon, + tae.estado, tae.datos FROM tagente_modulo AS tam INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + INNER JOIN tagente_estado AS tae + ON tae.id_agente_modulo = tam.id_agente_modulo LEFT JOIN tconfig_os AS tos ON tos.id_os = ta.id_os WHERE tam.disabled = 0 @@ -766,6 +825,8 @@ class Tree { $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['datos']; $this->processModule($module); @@ -889,11 +950,14 @@ class Tree { ta.id_agente, ta.nombre AS agent_name, ta.fired_count, ta.normal_count, ta.warning_count, ta.critical_count, ta.unknown_count, ta.notinit_count, ta.total_count, - tt.id_tag, tt.name AS tag_name + tt.id_tag, tt.name AS tag_name, + tae.estado, tae.estado FROM tagente_modulo AS tam INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + INNER JOIN tagente_estado AS tae + ON tae.id_agente_modulo = tam.id_agente_modulo INNER JOIN ttag_module AS ttm ON ttm.id_agente_modulo = tam.id_agente_modulo INNER JOIN ttag AS tt @@ -925,6 +989,8 @@ class Tree { $module['nombre'] = $value['module_name']; $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['datos']; $this->processModule($module); From b05a14bf5ec5178bb14cb4d6b7aac2c8f1601ea3 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 14 Jan 2015 17:48:51 +0100 Subject: [PATCH 87/92] Now the image is small as the other module status images --- .../default/module_unknown_ball.png | Bin 336 -> 1022 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/pandora_console/images/status_sets/default/module_unknown_ball.png b/pandora_console/images/status_sets/default/module_unknown_ball.png index 7d0e20ea742f23941f4940fd18e1f510996f07f0..4d0ff8b35a91af1391e113278a2901bde647abd4 100755 GIT binary patch literal 1022 zcmaJ=J#W)M7`~sLbs332QYVqEn${l)jZ{}j8i|Z`>}zAS_8I$1+zybk z!GQ7;_yt{<5Calh{{k!s!2}Xr5G&_2Nf`*1PIvF?=Xu_bd+$YU>)~AHb_M`2SKTlg zbWbNMeHDPIH|bY*sd0;xTVxyWlCBjZpgOpXVAZqsPy<=c(c?3;3c&O|x7i{sb5pjl z$65)7jlF=f0a#s&1Iyk=1h&zh>nqI9ckdbKItufsVDe_5qmH|A9HQ;xt)_jvZ%Yod z_5iNNG8OO;v0&^S_>mkd%s^MB=fur1Z~!6u3UiTE%d9~ihX@u}K4b2YR3PgivIq{F7$1zfSnFVdqYe(B zzFlAiXj-=GC!PVrH07!v5zDtx)le9!!Md&^3k6b&1JH@@H%ycoUHeNUYuS` uJ0F&3Q{UB0_H+HbH~UrW*E<>Y$9n$`ApFw#!lzJpThvyEYvF literal 336 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4AL_4K$=2#p8^o zpZ#yYd$aMWsM8Zx>Deam{|I8}4UuCDw7#<1Zow*VR+R&S5g%olmpF*AO{`_>_{o#w z-ZNjsL56MO)uIU&GX!&)7U*3+#QaY9y4+!gY~Sk!;l__{X2#8(cQ`GxVSRn}vWq3m zM$^+W5BM@$-krW9sbTW8n||pmOA-aP)(RW%`uJzMlT8LgWRHY}!Cx8WSwC`Tw(VH= anYp^tY2!r2gRg-eWAJqKb6Mw<&;$Swf_VD? From 3779bd518f0f8f69162db509d875bbe9e9140b74 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 14 Jan 2015 17:52:05 +0100 Subject: [PATCH 88/92] Minor fixes --- pandora_console/include/ajax/tree.ajax.php | 9 ++++----- pandora_console/include/styles/pandora.css | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pandora_console/include/ajax/tree.ajax.php b/pandora_console/include/ajax/tree.ajax.php index 910e0bf87c..6c44b591fb 100644 --- a/pandora_console/include/ajax/tree.ajax.php +++ b/pandora_console/include/ajax/tree.ajax.php @@ -31,9 +31,7 @@ if (is_ajax ()) { if ($getChildren) { $type = get_parameter('type', 'group'); - $filter = get_parameter('filter', - array('search' => '', - 'status' => AGENT_STATUS_ALL)); + $filter = get_parameter('filter', array('searchAgent' => '', 'statusAgent' => AGENT_STATUS_ALL)); $id = (int)get_parameter('id', 0); $childrenMethod = get_parameter('childrenMethod', 'on_demand'); $countModuleStatusMethod = get_parameter('countModuleStatusMethod', 'on_demand'); @@ -57,8 +55,9 @@ if (is_ajax ()) { } $tree->setFilter(array( - 'status' => $filter['status'], - 'search' => $filter['search'])); + 'statusAgent' => $filter['statusAgent'], + 'searchAgent' => $filter['searchAgent']) + ); echo json_encode(array('success' => 1, 'tree' => $tree->getArray())); return; } diff --git a/pandora_console/include/styles/pandora.css b/pandora_console/include/styles/pandora.css index f433683b12..ea715e7df1 100755 --- a/pandora_console/include/styles/pandora.css +++ b/pandora_console/include/styles/pandora.css @@ -2856,7 +2856,7 @@ table#policy_modules td * { min-height: 26px; } -.tree-last { +.tree-node:last-child { background: 0 0; } .node-content { From 0c572530a86dff12900f6d6926e1b30c32393bfe Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 14 Jan 2015 17:53:22 +0100 Subject: [PATCH 89/92] Fixed an error on the function "group_get_data" --- pandora_console/include/functions_groups.php | 78 ++++++++++---------- 1 file changed, 41 insertions(+), 37 deletions(-) diff --git a/pandora_console/include/functions_groups.php b/pandora_console/include/functions_groups.php index dfcfecf236..ab2e190ce6 100644 --- a/pandora_console/include/functions_groups.php +++ b/pandora_console/include/functions_groups.php @@ -1840,9 +1840,10 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu if ($id_user == false) { $id_user = $config['id_user']; } - + $user_groups = array(); $user_tags = array(); + $groups_without_tags = array(); foreach ($acltags as $group => $tags) { if ($user_strict) { //Remove groups with tags if ($tags == '') { @@ -1864,34 +1865,31 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } else { $user_groups_ids = implode(',',array_keys($acltags)); } - - if ($user_groups_ids == '') { - $user_groups_ids == -1; - } - switch ($config["dbtype"]) { - case "mysql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - - break; - case "postgresql": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre ASC"); - break; - case "oracle": - $list_groups = db_get_all_rows_sql(" - SELECT * - FROM tgrupo - WHERE id_grupo IN (" . $user_groups_ids . ") - ORDER BY nombre COLLATE utf8_general_ci ASC"); - break; + if (!empty($user_groups_ids)) { + switch ($config["dbtype"]) { + case "mysql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + break; + case "postgresql": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre ASC"); + break; + case "oracle": + $list_groups = db_get_all_rows_sql(" + SELECT * + FROM tgrupo + WHERE id_grupo IN (" . $user_groups_ids . ") + ORDER BY nombre COLLATE utf8_general_ci ASC"); + break; + } } if ($list_groups == false) { @@ -1919,11 +1917,14 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + if ($mode == 'tree' && !empty($item['parent'])) + $list[$i]['_parent_id_'] = $item['parent']; + $list[$i]['_agents_unknown_'] = $group_stat[0]["unknown"]; $list[$i]['_monitors_alerts_fired_'] = $group_stat[0]["alerts_fired"]; $list[$i]['_total_agents_'] = $group_stat[0]["agents"]; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = $group_stat[0]["normal"]; $list[$i]['_agents_warning_'] = $group_stat[0]["warning"]; $list[$i]['_agents_critical_'] = $group_stat[0]["critical"]; @@ -1949,7 +1950,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_not_init_'] += $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init'] += $list[$i]['_agents_not_init']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $group_stat[0]["normal"]; $list[0]['_agents_warning_'] += $group_stat[0]["warning"]; $list[0]['_agents_critical_'] += $group_stat[0]["critical"]; @@ -1957,7 +1958,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]); @@ -1974,6 +1975,9 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_name_'] = $item['nombre']; $list[$i]['_iconImg_'] = html_print_image ("images/groups_small/" . groups_get_icon($item['id_grupo']).".png", true, array ("style" => 'vertical-align: middle;')); + if ($mode == 'tree' && !empty($item['parent'])) + $list[$i]['_parent_id_'] = $item['parent']; + $list[$i]['_monitors_ok_'] = groups_monitor_ok($id, $user_strict, $id); $list[$i]['_monitors_critical_'] = groups_monitor_critical($id, $user_strict, $id); $list[$i]['_monitors_warning_'] = groups_monitor_warning($id, $user_strict, $id); @@ -1984,7 +1988,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_not_init_'] = groups_monitor_not_init($id, $user_strict, $id); $list[$i]['_agents_not_init_'] = groups_agent_not_init ($id, $user_strict, $id); - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = groups_agent_ok ($id, $user_strict, $id); $list[$i]['_agents_warning_'] = groups_agent_warning ($id, $user_strict, $id); $list[$i]['_agents_critical_'] = groups_agent_critical ($id, $user_strict, $id); @@ -2002,7 +2006,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; $list[0]['_agents_not_init_'] += $list[$i]['_agents_not_init']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; @@ -2010,7 +2014,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]); @@ -2041,7 +2045,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[$i]['_monitors_warning_'] = tags_monitors_warning ($id, $acltags); $list[$i]['_monitors_alerts_fired_'] = tags_monitors_fired_alerts($id, $acltags); - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[$i]['_agents_ok_'] = tags_agent_ok ($id, $acltags); $list[$i]['_agents_warning_'] = tags_agent_warning ($id, $acltags); $list[$i]['_agents_critical_'] = tags_get_critical_agents ($id, $acltags); @@ -2059,7 +2063,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu $list[0]['_monitors_unknown_'] += $list[$i]['_monitors_unknown_']; $list[0]['_monitors_not_init_'] = $list[$i]['_monitors_not_init_']; - if ($mode == 'tactical') { + if ($mode == 'tactical' || $mode == 'tree') { $list[0]['_agents_ok_'] += $list[$i]['_agents_ok_']; $list[0]['_agents_warning_'] += $list[$i]['_agents_warning_']; $list[0]['_agents_critical_'] += $list[$i]['_agents_critical_']; @@ -2067,7 +2071,7 @@ function group_get_data ($id_user = false, $user_strict = false, $acltags, $retu } } - if ($mode == 'group') { + if ($mode == 'group' || $mode == 'tree') { if (! defined ('METACONSOLE')) { if (($list[$i]['_agents_unknown_'] == 0) && ($list[$i]['_monitors_alerts_fired_'] == 0) && ($list[$i]['_total_agents_'] == 0) && ($list[$i]['_monitors_ok_'] == 0) && ($list[$i]['_monitors_critical_'] == 0) && ($list[$i]['_monitors_warning_'] == 0) && ($list[$i]['_monitors_unknown_'] == 0) && ($list[$i]['_monitors_not_init_'] == 0) && ($list[$i]['_agents_not_init_'] == 0)) { unset($list[$i]); From c64c09f86b991fce86394976edf40d1456f50660 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Wed, 14 Jan 2015 17:56:42 +0100 Subject: [PATCH 90/92] Working in the trees --- pandora_console/include/class/Tree.class.php | 727 +++++++++++++----- .../include/javascript/tree/TreeController.js | 99 +-- 2 files changed, 587 insertions(+), 239 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 538a33e716..5897fdd3f4 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -24,6 +24,9 @@ class Tree { protected $userGroups; + protected $strictACL = false; + protected $acltags = false; + public function __construct($type, $root = null, $childrenMethod = "on_demand", $countModuleStatusMethod = "on_demand", @@ -64,8 +67,6 @@ class Tree { $module['server_type'] = (int) $module['id_modulo']; // $module['icon'] = modules_get_type_icon($module['id_tipo_modulo']); - if (!isset($module['status'])) - $module['status'] = modules_get_status($module['id']); if (!isset($module['value'])) $module['value'] = modules_get_last_value($module['id']); @@ -186,42 +187,44 @@ class Tree { $agent['name'] = $agent['nombre']; // Counters - $agent['counters'] = array(); + if (empty($agent['counters'])) { + $agent['counters'] = array(); - if (isset($agent['unknown_count'])) - $agent['counters']['unknown'] = $agent['unknown_count']; - else - $agent['counters']['unknown'] = agents_monitor_unknown($agent['id']); + if (isset($agent['unknown_count'])) + $agent['counters']['unknown'] = $agent['unknown_count']; + else + $agent['counters']['unknown'] = agents_monitor_unknown($agent['id']); - if (isset($agent['critical_count'])) - $agent['counters']['critical'] = $agent['critical_count']; - else - $agent['counters']['critical'] = agents_monitor_critical($agent['id']); + if (isset($agent['critical_count'])) + $agent['counters']['critical'] = $agent['critical_count']; + else + $agent['counters']['critical'] = agents_monitor_critical($agent['id']); - if (isset($agent['warning_count'])) - $agent['counters']['warning'] = $agent['warning_count']; - else - $agent['counters']['warning'] = agents_monitor_warning($agent['id']); + if (isset($agent['warning_count'])) + $agent['counters']['warning'] = $agent['warning_count']; + else + $agent['counters']['warning'] = agents_monitor_warning($agent['id']); - if (isset($agent['notinit_count'])) - $agent['counters']['not_init'] = $agent['notinit_count']; - else - $agent['counters']['not_init'] = agents_monitor_notinit($agent['id']); + if (isset($agent['notinit_count'])) + $agent['counters']['not_init'] = $agent['notinit_count']; + else + $agent['counters']['not_init'] = agents_monitor_notinit($agent['id']); - if (isset($agent['normal_count'])) - $agent['counters']['ok'] = $agent['normal_count']; - else - $agent['counters']['ok'] = agents_monitor_ok($agent['id']); + if (isset($agent['normal_count'])) + $agent['counters']['ok'] = $agent['normal_count']; + else + $agent['counters']['ok'] = agents_monitor_ok($agent['id']); - if (isset($agent['total_count'])) - $agent['counters']['total'] = $agent['total_count']; - else - $agent['counters']['total'] = agents_monitor_total($agent['id']); + if (isset($agent['total_count'])) + $agent['counters']['total'] = $agent['total_count']; + else + $agent['counters']['total'] = agents_monitor_total($agent['id']); - if (isset($agent['fired_count'])) - $agent['counters']['alerts'] = $agent['fired_count']; - else - $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); + if (isset($agent['fired_count'])) + $agent['counters']['alerts'] = $agent['fired_count']; + else + $agent['counters']['alerts'] = agents_get_alerts_fired($agent['id']); + } // Status image $agent['statusImageHTML'] = agents_tree_view_status_img_ball( @@ -258,28 +261,30 @@ class Tree { } // Children - $agent['children'] = array(); - if ($agent['counters']['total'] > 0) { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 1; - break; - case 'live': - $agent['searchChildren'] = 0; + if (empty($agent['children'])) { + $agent['children'] = array(); + if ($agent['counters']['total'] > 0) { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 1; + break; + case 'live': + $agent['searchChildren'] = 0; - if ($searchChildren) - $agent['children'] = $this->getModules($agent['id'], $modulesFilter); - break; + if ($searchChildren) + $agent['children'] = $this->getModules($agent['id'], $modulesFilter); + break; + } } - } - else { - switch ($this->childrenMethod) { - case 'on_demand': - $agent['searchChildren'] = 0; - break; - case 'live': - $agent['searchChildren'] = 0; - break; + else { + switch ($this->childrenMethod) { + case 'on_demand': + $agent['searchChildren'] = 0; + break; + case 'live': + $agent['searchChildren'] = 0; + break; + } } } } @@ -293,6 +298,18 @@ class Tree { } protected function getAgents ($parent = 0, $parentType = '') { + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; + } + + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + switch ($parentType) { case 'group': // ACL Groups @@ -303,24 +320,139 @@ class Tree { if (!isset($this->userGroups[$parent])) return array(); } - $filter = array(); - $filter['id_grupo'] = $parent; - if (isset($this->filter['status']) && $this->filter['status'] != -1) - $filter['status'] = $this->filter['status']; - if (!empty($this->filter['searchAgent'])) - $filter['nombre'] = "%" . $this->filter['searchAgent'] . "%"; + // TODO: Check ACL - $agents = agents_get_agents($filter, array('id_agente', 'nombre')); - if (empty($agents)) { - $agents = array(); + // Get the agents. The modules are optional (LEFT JOIN), like their status + $sql = "SELECT ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos + FROM tagente AS ta + LEFT JOIN tagente_modulo AS tam + LEFT JOIN tagente_estado AS tae + ON tam.id_agente_modulo IS NOT NULL + AND tam.id_agente_modulo = tae.id_agente_modulo + ON tam.disabled = 0 + AND ta.id_agente = tam.id_agente + $module_search + WHERE ta.id_grupo = $parent + AND ta.disabled = 0 + $agent_search + ORDER BY ta.nombre ASC, ta.id_agente ASC, tam.nombre ASC, tam.id_agente_modulo ASC"; + $data = db_process_sql($sql); + break; + case 'tag': + $groups_clause = ""; + if (!empty($this->acltags)) { + $i = 0; + $groups = array(); + foreach ($this->acltags as $group_id => $tags) { + if (!empty($tags)) { + $tags_arr = explode(',', $tags); + + if (in_array($id_tag, $tags_arr)) + $groups[] = $group_id; + } + } + if (!empty($groups)) { + $groups_str = implode(",", $groups); + $groups_clause = " AND ta.id_grupo IN ($groups_str)"; + } } + + // Get the agents. The modules are required (INNER JOIN), although their status + $sql = "SELECT ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, tae.estado, tae.datos + FROM tagente AS ta + INNER JOIN tagente_modulo AS tam + ON tam.disabled = 0 + AND ta.id_agente = tam.id_agente + $module_search + INNER JOIN ttag_module AS ttm + ON ttm.id_tag = $parent + AND tam.id_agente_modulo = ttm.id_agente_modulo + LEFT JOIN tagente_estado AS tae + ON tam.id_agente_modulo = tae.id_agente_modulo + WHERE ta.disabled = 0 + $groups_clause + $agent_search + ORDER BY ta.nombre ASC, ta.id_agente ASC, tam.nombre ASC, tam.id_agente_modulo ASC"; + $data = db_process_sql($sql); break; default: return array(); break; } + + if (empty($data)) + return array(); - $this->processAgents($agents); + $agents = array(); + $actual_agent = array(); + foreach ($data as $key => $value) { + + if (empty($actual_agent) || $actual_agent['id_agente'] != (int)$value['id_agente']) { + if (!empty($actual_agent)) { + $this->processAgent(&$actual_agent, array(), false); + $agents[] = $actual_agent; + } + + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + + $actual_agent['children'] = array(); + + // Initialize counters + $actual_agent['counters'] = array(); + $actual_agent['counters']['total'] = 0; + $actual_agent['counters']['alerts'] = 0; + $actual_agent['counters']['critical'] = 0; + $actual_agent['counters']['warning'] = 0; + $actual_agent['counters']['unknown'] = 0; + $actual_agent['counters']['not_init'] = 0; + $actual_agent['counters']['ok'] = 0; + + // $actual_agent['counters'] = array(); + // $actual_agent['counters']['total'] = (int) $value['total_count']; + // $actual_agent['counters']['alerts'] = (int) $value['fired_count_count']; + // $actual_agent['counters']['critical'] = (int) $value['critical_count']; + // $actual_agent['counters']['warning'] = (int) $value['warning_count']; + // $actual_agent['counters']['unknown'] = (int) $value['unknown_count']; + // $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; + // $actual_agent['counters']['ok'] = (int) $value['normal_count']; + } + + if (empty($value['id_agente_modulo'])) + continue; + + $module = array(); + $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; + $module['nombre'] = $value['module_name']; + $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['data']; + + $this->processModule($module); + + $actual_agent['children'][] = $module; + $actual_agent['counters']['total']++; + + if (isset($actual_agent['counters'][$module['statusText']])) + $actual_agent['counters'][$module['statusText']]++; + + if ($module['alert']) + $actual_agent['counters']['alerts']++; + } + if (!empty($actual_agent)) { + $this->processAgent(&$actual_agent, array(), false); + $agents[] = $actual_agent; + } return $agents; } @@ -473,18 +605,167 @@ class Tree { } private function getDataGroup() { + global $config; + // Get the parent if (empty($this->root)) $parent = 0; else $parent = $this->root; - $groups = $this->getGroupsRecursive($parent); + // Get all groups + if (empty($parent)) { + require_once($config['homedir']."/include/functions_groups.php"); - if (empty($groups)) - $groups = array(); + // Return all the children groups + function __searchChildren(&$groups, $id) { + $children = array(); + foreach ($groups as $key => $group) { + if (isset($group['_parent_id_']) && $group['_parent_id_'] == $id) { + $processed_group = array(); + $processed_group['id'] = $group['_id_']; + $processed_group['parentID'] = $group['_parent_id_']; + $processed_group['name'] = $group['_name_']; + $processed_group['iconHTML'] = $group['_iconImg_']; + $processed_group['type'] = 'group'; + $processed_group['searchChildren'] = 1; - $this->tree = $groups; + $counters = array(); + if (isset($group['_agents_unknown_'])) + $counters['unknown'] = $group['_agents_unknown_']; + + if (isset($group['_agents_critical_'])) + $counters['critical'] = $group['_agents_critical_']; + + if (isset($group['_agents_warning_'])) + $counters['warning'] = $group['_agents_warning_']; + + if (isset($group['_agents_not_init_'])) + $counters['not_init'] = $group['_agents_not_init_']; + + if (isset($group['_agents_ok_'])) + $counters['ok'] = $group['_agents_ok_']; + + if (isset($group['_total_agents_'])) + $counters['total'] = $group['_total_agents_']; + + if (isset($group['_monitors_alerts_fired_'])) + $counters['alerts'] = $group['_monitors_alerts_fired_']; + + $children = __searchChildren($groups, $group['_id_']);html_debug_print($children, true); + if (!empty($children)) { + $processed_group['children'] = $children; + + foreach ($children as $key => $child) { + if (isset($child['counters'])) { + foreach ($child['counters'] as $type => $value) { + if (isset($counters[$type])) + $counters[$type] += $value; + } + } + } + } + + if (!empty($counters)) + $processed_group['counters'] = $counters; + + $children[] = $processed_group; + unset($groups[$key]); + } + } + return $children; + } + + if (! defined ('METACONSOLE')) { + $groups = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); + } else { + + } + //$groups = group_get_groups_list($config['id_user'], true, 'AR', true, false, 'tree'); + + // Build the group hierarchy + foreach ($groups as $key => $group) { + if (empty($group['_is_tag_'])) + $children = __searchChildren($groups, $group['_id_']); + + if (!empty($children)) + $groups[$key]['children'] = $children; + } + + // Process the groups for the tree + $processed_groups = array(); + foreach ($groups as $key => $group) { + $processed_group = array(); + $processed_group['id'] = $group['_id_']; + $processed_group['name'] = $group['_name_']; + $processed_group['searchChildren'] = 1; + + if (!empty($group['_iconImg_'])) + $processed_group['iconHTML'] = $group['_iconImg_']; + + if (!empty($group['_parent_id_'])) + $processed_group['parentID'] = $group['_parent_id_']; + + if (empty($group['_is_tag_'])) + $processed_group['type'] = 'group'; + else + $processed_group['type'] = 'tag'; + + $counters = array(); + if (isset($group['_agents_unknown_'])) + $counters['unknown'] = $group['_agents_unknown_']; + + if (isset($group['_agents_critical_'])) + $counters['critical'] = $group['_agents_critical_']; + + if (isset($group['_agents_warning_'])) + $counters['warning'] = $group['_agents_warning_']; + + if (isset($group['_agents_not_init_'])) + $counters['not_init'] = $group['_agents_not_init_']; + + if (isset($group['_agents_ok_'])) + $counters['ok'] = $group['_agents_ok_']; + + if (isset($group['_total_agents_'])) + $counters['total'] = $group['_total_agents_']; + + if (isset($group['_monitors_alerts_fired_'])) + $counters['alerts'] = $group['_monitors_alerts_fired_']; + + if (!empty($group['children'])) { + $processed_group['children'] = $group['children']; + + if ($processed_group['type'] == 'group') { + foreach ($processed_group['children'] as $key => $child) { + if (isset($child['counters'])) { + foreach ($child['counters'] as $type => $value) { + if (isset($counters[$type])) + $counters[$type] += $value; + } + } + } + } + } + + if (!empty($counters)) + $processed_group['counters'] = $counters; + + $processed_groups[] = $processed_group; + } + $groups = $processed_groups; + + // $groups = $this->getGroupsRecursive($parent); + + if (empty($groups)) + $groups = array(); + + $this->tree = $groups; + } + // Get the group agents + else { + $this->tree = $this->getAgents($parent, $this->type); + } } private function getDataModules() { @@ -520,12 +801,12 @@ class Tree { INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + $agent_search + $group_acl INNER JOIN tagente_estado AS tae ON tae.id_agente_modulo = tam.id_agente_modulo WHERE tam.disabled = 0 - $agent_search $module_search - $group_acl ORDER BY tam.nombre ASC, ta.nombre ASC"; $data = db_process_sql($sql); @@ -544,6 +825,15 @@ class Tree { $agent['id_agente'] = (int) $value['id_agente']; $agent['nombre'] = $value['agent_name']; + $agent['counters'] = array(); + $agent['counters']['total'] = (int) $value['total_count']; + $agent['counters']['alerts'] = (int) $value['fired_count_count']; + $agent['counters']['critical'] = (int) $value['critical_count']; + $agent['counters']['warning'] = (int) $value['warning_count']; + $agent['counters']['unknown'] = (int) $value['unknown_count']; + $agent['counters']['not_init'] = (int) $value['notinit_count']; + $agent['counters']['ok'] = (int) $value['normal_count']; + $this->processAgent(&$agent, array(), false); $module = array(); @@ -633,14 +923,14 @@ class Tree { INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + $agent_search + $group_acl INNER JOIN tagente_estado AS tae ON tae.id_agente_modulo = tam.id_agente_modulo LEFT JOIN tmodule_group AS tmg ON tmg.id_mg = tam.id_module_group WHERE tam.disabled = 0 - $agent_search $module_search - $group_acl ORDER BY tmg.name ASC, tmg.id_mg ASC, ta.nombre ASC, tam.nombre ASC"; $data = db_process_sql($sql); @@ -684,6 +974,15 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); + $actual_agent['counters'] = array(); + $actual_agent['counters']['total'] = (int) $value['total_count']; + $actual_agent['counters']['alerts'] = (int) $value['fired_count_count']; + $actual_agent['counters']['critical'] = (int) $value['critical_count']; + $actual_agent['counters']['warning'] = (int) $value['warning_count']; + $actual_agent['counters']['unknown'] = (int) $value['unknown_count']; + $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; + $actual_agent['counters']['ok'] = (int) $value['normal_count']; + $this->processAgent(&$actual_agent, array(), false); // Add the module to the agent @@ -714,6 +1013,15 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); + $actual_agent['counters'] = array(); + $actual_agent['counters']['total'] = (int) $value['total_count']; + $actual_agent['counters']['alerts'] = (int) $value['fired_count_count']; + $actual_agent['counters']['critical'] = (int) $value['critical_count']; + $actual_agent['counters']['warning'] = (int) $value['warning_count']; + $actual_agent['counters']['unknown'] = (int) $value['unknown_count']; + $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; + $actual_agent['counters']['ok'] = (int) $value['normal_count']; + $this->processAgent(&$actual_agent, array(), false); // Add the module to the agent @@ -793,14 +1101,14 @@ class Tree { INNER JOIN tagente AS ta ON ta.id_agente = tam.id_agente AND ta.disabled = 0 + $agent_search + $group_acl INNER JOIN tagente_estado AS tae ON tae.id_agente_modulo = tam.id_agente_modulo LEFT JOIN tconfig_os AS tos ON tos.id_os = ta.id_os WHERE tam.disabled = 0 - $agent_search $module_search - $group_acl ORDER BY tos.icon_name ASC, tos.id_os ASC, ta.nombre ASC, tam.nombre"; $data = db_process_sql($sql); @@ -844,6 +1152,15 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); + $actual_agent['counters'] = array(); + $actual_agent['counters']['total'] = (int) $value['total_count']; + $actual_agent['counters']['alerts'] = (int) $value['fired_count_count']; + $actual_agent['counters']['critical'] = (int) $value['critical_count']; + $actual_agent['counters']['warning'] = (int) $value['warning_count']; + $actual_agent['counters']['unknown'] = (int) $value['unknown_count']; + $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; + $actual_agent['counters']['ok'] = (int) $value['normal_count']; + $this->processAgent(&$actual_agent, array(), false); // Add the module to the agent @@ -889,6 +1206,15 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); + $actual_agent['counters'] = array(); + $actual_agent['counters']['total'] = (int) $value['total_count']; + $actual_agent['counters']['alerts'] = (int) $value['fired_count_count']; + $actual_agent['counters']['critical'] = (int) $value['critical_count']; + $actual_agent['counters']['warning'] = (int) $value['warning_count']; + $actual_agent['counters']['unknown'] = (int) $value['unknown_count']; + $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; + $actual_agent['counters']['ok'] = (int) $value['normal_count']; + $this->processAgent(&$actual_agent, array(), false); // Add the module to the agent @@ -923,84 +1249,123 @@ class Tree { } private function getDataTag() { - // ACL Group - if (isset($this->userGroups) && $this->userGroups === false) - return array(); - $group_acl = ""; - if (!empty($this->userGroups)) { - $user_groups_str = implode(",", array_keys($this->userGroups)); - $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; - } + // Get the parent + if (empty($this->root)) + $parent = 0; + else + $parent = $this->root; - // Agent name filter - $agent_search = ""; - if (!empty($this->filter['searchAgent'])) { - $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; - } - - // Module name filter - $module_search = ""; - if (!empty($this->filter['searchModule'])) { - $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; - } - - $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, - tam.id_tipo_modulo, tam.id_modulo, - ta.id_agente, ta.nombre AS agent_name, ta.fired_count, - ta.normal_count, ta.warning_count, ta.critical_count, - ta.unknown_count, ta.notinit_count, ta.total_count, - tt.id_tag, tt.name AS tag_name, - tae.estado, tae.estado - FROM tagente_modulo AS tam - INNER JOIN tagente AS ta - ON ta.id_agente = tam.id_agente - AND ta.disabled = 0 - INNER JOIN tagente_estado AS tae - ON tae.id_agente_modulo = tam.id_agente_modulo - INNER JOIN ttag_module AS ttm - ON ttm.id_agente_modulo = tam.id_agente_modulo - INNER JOIN ttag AS tt - ON tt.id_tag = ttm.id_tag - WHERE tam.disabled = 0 - $agent_search - $module_search - $group_acl - ORDER BY tt.name ASC, tt.id_tag ASC, ta.nombre ASC, tam.nombre ASC"; - $data = db_process_sql($sql); + // Get all groups + if (empty($parent)) { + // ACL Group + if (isset($this->userGroups) && $this->userGroups === false) + return array(); - if (empty($data)) { - $data = array(); - } + $group_acl = ""; + if (!empty($this->userGroups)) { + $user_groups_str = implode(",", array_keys($this->userGroups)); + $group_acl = " AND ta.id_grupo IN ($user_groups_str) "; + } - $nodes = array(); - $actual_tag_root = array( - 'id' => null, - 'name' => '', - 'children' => array(), - 'counters' => array() - ); - $actual_agent = array(); - foreach ($data as $key => $value) { + // Agent name filter + $agent_search = ""; + if (!empty($this->filter['searchAgent'])) { + $agent_search = " AND ta.nombre LIKE '%".$this->filter['searchAgent']."%' "; + } + + // Module name filter + $module_search = ""; + if (!empty($this->filter['searchModule'])) { + $module_search = " AND tam.nombre LIKE '%".$this->filter['searchModule']."%' "; + } + + $sql = "SELECT tam.id_agente_modulo, tam.nombre AS module_name, + tam.id_tipo_modulo, tam.id_modulo, + ta.id_agente, ta.nombre AS agent_name, ta.fired_count, + ta.normal_count, ta.warning_count, ta.critical_count, + ta.unknown_count, ta.notinit_count, ta.total_count, + tt.id_tag, tt.name AS tag_name, + tae.estado, tae.estado + FROM tagente_modulo AS tam + INNER JOIN tagente AS ta + ON ta.id_agente = tam.id_agente + AND ta.disabled = 0 + INNER JOIN tagente_estado AS tae + ON tae.id_agente_modulo = tam.id_agente_modulo + INNER JOIN ttag_module AS ttm + ON ttm.id_agente_modulo = tam.id_agente_modulo + INNER JOIN ttag AS tt + ON tt.id_tag = ttm.id_tag + WHERE tam.disabled = 0 + $agent_search + $module_search + $group_acl + ORDER BY tt.name ASC, tt.id_tag ASC, ta.nombre ASC, tam.nombre ASC"; + $data = db_process_sql($sql); - // Module - $module = array(); - $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; - $module['nombre'] = $value['module_name']; - $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; - $module['server_type'] = (int) $value['id_modulo']; - $module['status'] = (int) $value['estado']; - $module['value'] = $value['datos']; + if (empty($data)) { + $data = array(); + } - $this->processModule($module); + $nodes = array(); + $actual_tag_root = array( + 'id' => null, + 'name' => '', + 'children' => array(), + 'counters' => array() + ); + $actual_agent = array(); + foreach ($data as $key => $value) { - // Tag - if ($actual_tag_root['id'] === (int)$value['id_tag']) { - // Agent - if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) { - // Add the last agent to the tag - if (!empty($actual_agent)) + // Module + $module = array(); + $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; + $module['nombre'] = $value['module_name']; + $module['id_tipo_modulo'] = (int) $value['id_tipo_modulo']; + $module['server_type'] = (int) $value['id_modulo']; + $module['status'] = (int) $value['estado']; + $module['value'] = $value['datos']; + + $this->processModule($module); + + // Tag + if ($actual_tag_root['id'] === (int)$value['id_tag']) { + // Agent + if (empty($actual_agent) || $actual_agent['id'] !== (int)$value['id_agente']) { + // Add the last agent to the tag + if (!empty($actual_agent)) + $actual_tag_root['children'][] = $actual_agent; + + // Create the new agent + $actual_agent = array(); + $actual_agent['id_agente'] = (int) $value['id_agente']; + $actual_agent['nombre'] = $value['agent_name']; + $actual_agent['children'] = array(); + + $this->processAgent(&$actual_agent, array(), false); + + // Add the module to the agent + $actual_agent['children'][] = $module; + + // Increase counters + $actual_tag_root['counters']['total']++; + + if (isset($actual_tag_root['counters'][$actual_agent['status']])) + $actual_tag_root['counters'][$actual_agent['status']]++; + } + else { + $actual_agent['children'][] = $module; + } + } + else { + // The first iteration doesn't enter here + if ($actual_tag_root['id'] !== null) { + // Add the agent to the tag $actual_tag_root['children'][] = $actual_agent; + // Add the tag to the branch + $nodes[] = $actual_tag_root; + } // Create the new agent $actual_agent = array(); @@ -1013,68 +1378,42 @@ class Tree { // Add the module to the agent $actual_agent['children'][] = $module; + // Create new tag + $actual_tag_root = array(); + $actual_tag_root['id'] = (int) $value['id_tag']; + $actual_tag_root['name'] = $value['tag_name']; + $actual_tag_root['type'] = $this->type; + + // Initialize counters + $actual_tag_root['counters'] = array(); + $actual_tag_root['counters']['total'] = 0; + $actual_tag_root['counters']['alerts'] = 0; + $actual_tag_root['counters']['critical'] = 0; + $actual_tag_root['counters']['warning'] = 0; + $actual_tag_root['counters']['unknown'] = 0; + $actual_tag_root['counters']['not_init'] = 0; + $actual_tag_root['counters']['ok'] = 0; + // Increase counters $actual_tag_root['counters']['total']++; if (isset($actual_tag_root['counters'][$actual_agent['status']])) $actual_tag_root['counters'][$actual_agent['status']]++; } - else { - $actual_agent['children'][] = $module; - } } - else { - // The first iteration doesn't enter here - if ($actual_tag_root['id'] !== null) { - // Add the agent to the tag - $actual_tag_root['children'][] = $actual_agent; - // Add the tag to the branch - $nodes[] = $actual_tag_root; - } - - // Create the new agent - $actual_agent = array(); - $actual_agent['id_agente'] = (int) $value['id_agente']; - $actual_agent['nombre'] = $value['agent_name']; - $actual_agent['children'] = array(); - - $this->processAgent(&$actual_agent, array(), false); - - // Add the module to the agent - $actual_agent['children'][] = $module; - - // Create new tag - $actual_tag_root = array(); - $actual_tag_root['id'] = (int) $value['id_tag']; - $actual_tag_root['name'] = $value['tag_name']; - $actual_tag_root['type'] = $this->type; - - // Initialize counters - $actual_tag_root['counters'] = array(); - $actual_tag_root['counters']['total'] = 0; - $actual_tag_root['counters']['alerts'] = 0; - $actual_tag_root['counters']['critical'] = 0; - $actual_tag_root['counters']['warning'] = 0; - $actual_tag_root['counters']['unknown'] = 0; - $actual_tag_root['counters']['not_init'] = 0; - $actual_tag_root['counters']['ok'] = 0; - - // Increase counters - $actual_tag_root['counters']['total']++; - - if (isset($actual_tag_root['counters'][$actual_agent['status']])) - $actual_tag_root['counters'][$actual_agent['status']]++; + // If there is an agent and a tag opened and not saved + if ($actual_tag_root['id'] !== null) { + // Add the last agent to the tag + $actual_tag_root['children'][] = $actual_agent; + // Add the last tag to the branch + $nodes[] = $actual_tag_root; } - } - // If there is an agent and a tag opened and not saved - if ($actual_tag_root['id'] !== null) { - // Add the last agent to the tag - $actual_tag_root['children'][] = $actual_agent; - // Add the last tag to the branch - $nodes[] = $actual_tag_root; - } - $this->tree = $nodes; + $this->tree = $nodes; + } + else { + $this->tree = $this->getAgents($parent, $this->type); + } } public function getJSON() { diff --git a/pandora_console/include/javascript/tree/TreeController.js b/pandora_console/include/javascript/tree/TreeController.js index 0c2391bd81..f32a3c5bd0 100644 --- a/pandora_console/include/javascript/tree/TreeController.js +++ b/pandora_console/include/javascript/tree/TreeController.js @@ -49,7 +49,6 @@ TreeController = { } // Normal group else { - rootGroup = false; $group .addClass("tree-group") .hide(); @@ -57,12 +56,8 @@ TreeController = { container.append($group); - var lastNode; - var firstNode; elements.forEach(function(element, index) { - lastNode = index == elements.length - 1 ? true : false; - firstNode = rootGroup && index == 0 ? true : false; - element.jqObject = _processNode($group, element, lastNode, firstNode); + element.jqObject = _processNode($group, element); }, $group); return $group; @@ -287,7 +282,7 @@ TreeController = { } // Load leaf - function _processNode (container, element, lastNode, firstNode) { + function _processNode (container, element) { var $node = $("
          • "); var $leafIcon = $("
            "); var $content = $("
            "); @@ -303,6 +298,9 @@ TreeController = { $content.append(' '); } + else if (typeof element.iconHTML != 'undefined' && element.iconHTML.length > 0) { + $content.append(element.iconHTML); + } $content.append(element.name); break; case 'agent': @@ -426,48 +424,49 @@ TreeController = { .append($leafIcon) .append($content); - if (typeof lastNode != 'undefinded' && lastNode == true) { - $node.addClass("tree-last"); - } - if (typeof firstNode != 'undefinded' && firstNode == true) { - $node.addClass("tree-first"); - } - container.append($node); + $node.addClass("leaf-empty"); + if (typeof element.children != 'undefined' && element.children.length > 0) { - $node.addClass("leaf-closed"); + $node + .removeClass("leaf-empty") + .addClass("leaf-closed"); // Add children var $children = _processGroup($node, element.children); $node.data('children', $children); - $leafIcon.click(function (e) { - e.preventDefault(); + if (typeof element.searchChildren == 'undefined' || !element.searchChildren) { + $leafIcon.click(function (e) { + e.preventDefault(); - if ($node.hasClass("leaf-open")) { - $node - .removeClass("leaf-open") - .addClass("leaf-closed") - .data('children') - .slideUp(); - } - else { - $node - .removeClass("leaf-closed") - .addClass("leaf-open") - .data('children') - .slideDown(); - } - }); + if ($node.hasClass("leaf-open")) { + $node + .removeClass("leaf-open") + .addClass("leaf-closed") + .data('children') + .slideUp(); + } + else { + $node + .removeClass("leaf-closed") + .addClass("leaf-open") + .data('children') + .slideDown(); + } + }); + } } - else if (typeof element.searchChildren != 'undefined' && element.searchChildren) { - $node.addClass("leaf-closed"); + if (typeof element.searchChildren != 'undefined' && element.searchChildren) { + $node + .removeClass("leaf-empty") + .addClass("leaf-closed"); $leafIcon.click(function (e) { e.preventDefault(); - if (! $node.hasClass("children-loaded") && ! $node.hasClass("leaf-empty")) { + if (!$node.hasClass("children-loaded") && !$node.hasClass("leaf-empty")) { $node .removeClass("leaf-closed") .removeClass("leaf-error") @@ -492,17 +491,30 @@ TreeController = { $node.addClass("children-loaded"); }, success: function(data, textStatus, xhr) { - data = $.parseJSON(data); - if (data.success) { - if (typeof data.tree != 'undefined' && data.tree.length > 0) { $node.addClass("leaf-open"); - - var $children = _processGroup($node, data.tree); - $children.slideDown(); - $node.data('children', $children); + var $group = $node.find("ul.tree-group"); + + if ($group.length <= 0) { + $group = $("
              "); + $group + .addClass("tree-group") + .hide(); + $node.append($group); + } + + data.tree.forEach(function(element, index) { + element.jqObject = _processNode($group, element); + }, $group); + + $group.slideDown(); + + $node.data('children', $group); + + // Add again the hover event to the 'force_callback' elements + forced_title_callback(); } else { $node.addClass("leaf-empty"); @@ -535,9 +547,6 @@ TreeController = { } }); } - else { - $node.addClass("leaf-empty"); - } return $node; } From e87cba03b3b271bfa4bb9ef80c7ace9d42c12c31 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Thu, 15 Jan 2015 13:23:08 +0100 Subject: [PATCH 91/92] Fixed some function calls --- pandora_console/include/class/Tree.class.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index 5897fdd3f4..bb75d09ee5 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -397,7 +397,7 @@ class Tree { if (empty($actual_agent) || $actual_agent['id_agente'] != (int)$value['id_agente']) { if (!empty($actual_agent)) { - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); $agents[] = $actual_agent; } @@ -450,7 +450,7 @@ class Tree { $actual_agent['counters']['alerts']++; } if (!empty($actual_agent)) { - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); $agents[] = $actual_agent; } @@ -834,7 +834,7 @@ class Tree { $agent['counters']['not_init'] = (int) $value['notinit_count']; $agent['counters']['ok'] = (int) $value['normal_count']; - $this->processAgent(&$agent, array(), false); + $this->processAgent($agent, array(), false); $module = array(); $module['id_agente_modulo'] = (int) $value['id_agente_modulo']; @@ -983,7 +983,7 @@ class Tree { $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; $actual_agent['counters']['ok'] = (int) $value['normal_count']; - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; @@ -1022,7 +1022,7 @@ class Tree { $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; $actual_agent['counters']['ok'] = (int) $value['normal_count']; - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; @@ -1161,7 +1161,7 @@ class Tree { $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; $actual_agent['counters']['ok'] = (int) $value['normal_count']; - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; @@ -1215,7 +1215,7 @@ class Tree { $actual_agent['counters']['not_init'] = (int) $value['notinit_count']; $actual_agent['counters']['ok'] = (int) $value['normal_count']; - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; @@ -1343,7 +1343,7 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; @@ -1373,7 +1373,7 @@ class Tree { $actual_agent['nombre'] = $value['agent_name']; $actual_agent['children'] = array(); - $this->processAgent(&$actual_agent, array(), false); + $this->processAgent($actual_agent, array(), false); // Add the module to the agent $actual_agent['children'][] = $module; From 127699044e9359fcfd4b9af082628a1d6a5d0463 Mon Sep 17 00:00:00 2001 From: Alejandro Gallardo Escobar Date: Fri, 16 Jan 2015 17:16:24 +0100 Subject: [PATCH 92/92] Now the tree view has compatibility with the metaconsole --- pandora_console/include/class/Tree.class.php | 329 ++++++++++++------- 1 file changed, 210 insertions(+), 119 deletions(-) diff --git a/pandora_console/include/class/Tree.class.php b/pandora_console/include/class/Tree.class.php index bb75d09ee5..d28910ba58 100644 --- a/pandora_console/include/class/Tree.class.php +++ b/pandora_console/include/class/Tree.class.php @@ -622,149 +622,215 @@ class Tree { $children = array(); foreach ($groups as $key => $group) { if (isset($group['_parent_id_']) && $group['_parent_id_'] == $id) { - $processed_group = array(); - $processed_group['id'] = $group['_id_']; - $processed_group['parentID'] = $group['_parent_id_']; - $processed_group['name'] = $group['_name_']; - $processed_group['iconHTML'] = $group['_iconImg_']; - $processed_group['type'] = 'group'; - $processed_group['searchChildren'] = 1; - - $counters = array(); - if (isset($group['_agents_unknown_'])) - $counters['unknown'] = $group['_agents_unknown_']; - - if (isset($group['_agents_critical_'])) - $counters['critical'] = $group['_agents_critical_']; - - if (isset($group['_agents_warning_'])) - $counters['warning'] = $group['_agents_warning_']; - - if (isset($group['_agents_not_init_'])) - $counters['not_init'] = $group['_agents_not_init_']; - - if (isset($group['_agents_ok_'])) - $counters['ok'] = $group['_agents_ok_']; - - if (isset($group['_total_agents_'])) - $counters['total'] = $group['_total_agents_']; - - if (isset($group['_monitors_alerts_fired_'])) - $counters['alerts'] = $group['_monitors_alerts_fired_']; - - $children = __searchChildren($groups, $group['_id_']);html_debug_print($children, true); - if (!empty($children)) { - $processed_group['children'] = $children; - - foreach ($children as $key => $child) { - if (isset($child['counters'])) { - foreach ($child['counters'] as $type => $value) { - if (isset($counters[$type])) - $counters[$type] += $value; - } - } - } - } - - if (!empty($counters)) - $processed_group['counters'] = $counters; - - $children[] = $processed_group; - unset($groups[$key]); + $children[] = __getProcessedItem($key, $groups); } } return $children; } - if (! defined ('METACONSOLE')) { - $groups = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); - } else { + function __getProcessedItem($itemKey, &$items) { + if (!isset($items[$itemKey])) { + return false; + } + else { + $item = $items[$itemKey]; + unset($items[$itemKey]); + } - } - //$groups = group_get_groups_list($config['id_user'], true, 'AR', true, false, 'tree'); + $processed_item = array(); + $processed_item['id'] = $item['_id_']; + $processed_item['name'] = $item['_name_']; + $processed_item['searchChildren'] = 1; - // Build the group hierarchy - foreach ($groups as $key => $group) { - if (empty($group['_is_tag_'])) - $children = __searchChildren($groups, $group['_id_']); - - if (!empty($children)) - $groups[$key]['children'] = $children; - } - - // Process the groups for the tree - $processed_groups = array(); - foreach ($groups as $key => $group) { - $processed_group = array(); - $processed_group['id'] = $group['_id_']; - $processed_group['name'] = $group['_name_']; - $processed_group['searchChildren'] = 1; - - if (!empty($group['_iconImg_'])) - $processed_group['iconHTML'] = $group['_iconImg_']; - - if (!empty($group['_parent_id_'])) - $processed_group['parentID'] = $group['_parent_id_']; - - if (empty($group['_is_tag_'])) - $processed_group['type'] = 'group'; - else - $processed_group['type'] = 'tag'; + if (isset($item['_is_tag_']) && $item['_is_tag_']) { + $processed_item['type'] = 'tag'; + } + else { + $processed_item['type'] = 'group'; + $processed_item['parentID'] = $item['_parent_id_']; + $processed_item['iconHTML'] = $item['_iconImg_']; + } $counters = array(); - if (isset($group['_agents_unknown_'])) - $counters['unknown'] = $group['_agents_unknown_']; + if (isset($item['_agents_unknown_'])) + $counters['unknown'] = $item['_agents_unknown_']; + if (isset($item['_agents_critical_'])) + $counters['critical'] = $item['_agents_critical_']; + if (isset($item['_agents_warning_'])) + $counters['warning'] = $item['_agents_warning_']; + if (isset($item['_agents_not_init_'])) + $counters['not_init'] = $item['_agents_not_init_']; + if (isset($item['_agents_ok_'])) + $counters['ok'] = $item['_agents_ok_']; + if (isset($item['_total_agents_'])) + $counters['total'] = $item['_total_agents_']; + if (isset($item['_monitors_alerts_fired_'])) + $counters['alerts'] = $item['_monitors_alerts_fired_']; - if (isset($group['_agents_critical_'])) - $counters['critical'] = $group['_agents_critical_']; + $children = __searchChildren($items, $item['_id_']); + if (!empty($children)) { + $processed_item['children'] = $children; - if (isset($group['_agents_warning_'])) - $counters['warning'] = $group['_agents_warning_']; - - if (isset($group['_agents_not_init_'])) - $counters['not_init'] = $group['_agents_not_init_']; - - if (isset($group['_agents_ok_'])) - $counters['ok'] = $group['_agents_ok_']; - - if (isset($group['_total_agents_'])) - $counters['total'] = $group['_total_agents_']; - - if (isset($group['_monitors_alerts_fired_'])) - $counters['alerts'] = $group['_monitors_alerts_fired_']; - - if (!empty($group['children'])) { - $processed_group['children'] = $group['children']; - - if ($processed_group['type'] == 'group') { - foreach ($processed_group['children'] as $key => $child) { - if (isset($child['counters'])) { - foreach ($child['counters'] as $type => $value) { - if (isset($counters[$type])) - $counters[$type] += $value; - } + foreach ($children as $key => $child) { + if (isset($child['counters'])) { + foreach ($child['counters'] as $type => $value) { + if (isset($counters[$type])) + $counters[$type] += $value; } } } } if (!empty($counters)) - $processed_group['counters'] = $counters; + $processed_item['counters'] = $counters; - $processed_groups[] = $processed_group; + return $processed_item; } - $groups = $processed_groups; - // $groups = $this->getGroupsRecursive($parent); + if (! defined ('METACONSOLE')) { + $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); - if (empty($groups)) - $groups = array(); + // Build the group hierarchy + $processed_items = array(); + foreach ($items as $key => $item) { + if (empty($item['_parent_id_'])) + $processed_items[] = __getProcessedItem($key, $items); + } + $items = $processed_items; + } + else { + //enterprise_include_once("include/functions_metaconsole.php"); + $servers = metaconsole_get_servers(); - $this->tree = $groups; + $item_list = array(); + foreach ($servers as $server) { + if (metaconsole_connect($server) != NOERR) + continue; + + $items = group_get_data($config['id_user'], $this->strictACL, $this->acltags, false, 'tree'); + + // Build the group hierarchy + $processed_items = array(); + foreach ($items as $key => $item) { + if (empty($item['_parent_id_'])) + $processed_items[] = __getProcessedItem($key, $items); + } + $item_list[$server['id']] = $processed_items; + + metaconsole_restore_db(); + } + + function __getMergedItems($items) { + // This variable holds the result + $mergedItems = array(); + + foreach ($items as $key => $child) { + + $childrenAux = array(); + + // Store the item in a temporary element + $resultItem = $child; + // Remove the item + unset($items[$key]); + + // The 'id' parameter will be stored as 'server_id' => 'id' + $resultItem['id'] = array(); + $resultItem['id'][$child['server_id']] = $child['id']; + + // Initialize counters if any of it don't exist + if (!isset($resultItem['counters'])) + $resultItem['counters'] = array(); + if (!isset($resultItem['counters']['unknown'])) + $resultItem['counters']['unknown'] = 0; + if (!isset($resultItem['counters']['critical'])) + $resultItem['counters']['critical'] = 0; + if (!isset($resultItem['counters']['warning'])) + $resultItem['counters']['warning'] = 0; + if (!isset($resultItem['counters']['not_init'])) + $resultItem['counters']['not_init'] = 0; + if (!isset($resultItem['counters']['ok'])) + $resultItem['counters']['ok'] = 0; + if (!isset($resultItem['counters']['total'])) + $resultItem['counters']['total'] = 0; + if (!isset($resultItem['counters']['alerts'])) + $resultItem['counters']['alerts'] = 0; + + // Iterate over the list to search items that match the actual item + foreach ($items as $key2 => $child2) { + // Skip the actual or empty items + if (!isset($key) || !isset($key2) || $key == $key2) + continue; + + // Match with the name + if ($child['name'] == $child2['name'] && $child['type'] == $child2['type']) { + // Add the matched ids + $resultItem['id'][$child2['server_id']] = $child2['id']; + + // Add the matched counters + if (isset($child2['counters']) && !child2($item['counters'])) { + foreach ($child2['counters'] as $type => $value) { + if (isset($resultItem['counters'][$type])) + $resultItem['counters'][$type] += $value; + } + } + + // Add the matched children + if (isset($child2['children'])) + $childrenAux += $child2['children']; + + // Remove the item + unset($items[$key2]); + } + } + // Get the merged children (recursion) + if (!empty($childrenAux)) + $resultItem['children'] = __getMergedItems($childrenAux); + + // Add the resulting item + $mergedItems[] = $resultItem; + } + + return $mergedItems; + } + + $items = __getMergedItems($item_list); + + html_debug_print($items, true); + } + + if (empty($items)) + $items = array(); + + $this->tree = $items; } // Get the group agents else { - $this->tree = $this->getAgents($parent, $this->type); + if (! defined ('METACONSOLE')) { + $this->tree = $this->getAgents($parent, $this->type); + } + else { + function cmpSortAgentNames($a, $b) { + return strcmp($a["name"], $b["name"]); + } + + $agents = array(); + foreach ($parent as $server_id => $group_id) { + $server = metaconsole_get_servers($server_id); + + if (!empty($server)) { + if (metaconsole_connect($server) != NOERR) + continue; + + $agents += $this->tree = $this->getAgents($group_id, $this->type); + + metaconsole_restore_db(); + } + } + if (!empty($agents)) + usort($agents, "cmpSortAgentNames"); + + $this->tree = $agents; + } } } @@ -1412,7 +1478,32 @@ class Tree { $this->tree = $nodes; } else { - $this->tree = $this->getAgents($parent, $this->type); + if (! defined ('METACONSOLE')) { + $this->tree = $this->getAgents($parent, $this->type); + } + else { + function cmpSortAgentNames($a, $b) { + return strcmp($a["name"], $b["name"]); + } + + $agents = array(); + foreach ($parent as $server_id => $tag_id) { + $server = metaconsole_get_servers($server_id); + + if (!empty($server)) { + if (metaconsole_connect($server) != NOERR) + continue; + + $agents += $this->tree = $this->getAgents($tag_id, $this->type); + + metaconsole_restore_db(); + } + } + if (!empty($agents)) + usort($agents, "cmpSortAgentNames"); + + $this->tree = $agents; + } } }