PageRenderTime 55ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/www/include/options/centStorage/viewData.php

https://gitlab.com/florianocomercial/centreon
PHP | 332 lines | 245 code | 32 blank | 55 comment | 108 complexity | 59f4d0e63a1c94e46501ea52c29e37e5 MD5 | raw file
  1. <?php
  2. /*
  3. * Copyright 2005-2015 Centreon
  4. * Centreon is developped by : Julien Mathis and Romain Le Merlus under
  5. * GPL Licence 2.0.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it under
  8. * the terms of the GNU General Public License as published by the Free Software
  9. * Foundation ; either version 2 of the License.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT ANY
  12. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
  13. * PARTICULAR PURPOSE. See the GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along with
  16. * this program; if not, see <http://www.gnu.org/licenses>.
  17. *
  18. * Linking this program statically or dynamically with other modules is making a
  19. * combined work based on this program. Thus, the terms and conditions of the GNU
  20. * General Public License cover the whole combination.
  21. *
  22. * As a special exception, the copyright holders of this program give Centreon
  23. * permission to link this program with independent modules to produce an executable,
  24. * regardless of the license terms of these independent modules, and to copy and
  25. * distribute the resulting executable under terms of Centreon choice, provided that
  26. * Centreon also meet, for each linked independent module, the terms and conditions
  27. * of the license of that module. An independent module is a module which is not
  28. * derived from this program. If you modify this program, you may extend this
  29. * exception to your version of the program, but you are not obliged to do so. If you
  30. * do not wish to do so, delete this exception statement from your version.
  31. *
  32. * For more information : contact@centreon.com
  33. *
  34. */
  35. if (!isset($centreon)) {
  36. exit();
  37. }
  38. require_once './class/centreonDuration.class.php';
  39. require_once './class/centreonBroker.class.php';
  40. include_once("./include/monitoring/common-Func.php");
  41. /*
  42. * Pear library
  43. */
  44. require_once "HTML/QuickForm.php";
  45. require_once 'HTML/QuickForm/Renderer/ArraySmarty.php';
  46. /*
  47. * Path to the option dir
  48. */
  49. $path = "./include/options/centStorage/";
  50. /*
  51. * Set URL for search
  52. */
  53. $url = "viewData.php";
  54. /*
  55. * PHP functions
  56. */
  57. require_once("./include/options/oreon/generalOpt/DB-Func.php");
  58. require_once("./include/common/common-Func.php");
  59. require_once("./class/centreonDB.class.php");
  60. include("./include/common/autoNumLimit.php");
  61. /*
  62. * Prepare search engine
  63. */
  64. if (isset($_POST["search"])) {
  65. $searchH = $_POST["searchH"];
  66. $num = $_GET['num'] = 0;
  67. $_POST["search"] = $_POST["searchH"];
  68. $oreon->historySearch[$url] = $search;
  69. } else if (isset($oreon->historySearch[$url])) {
  70. $searchH = $oreon->historySearch[$url];
  71. } else {
  72. $searchH = NULL;
  73. }
  74. if (isset($_POST["searchS"])) {
  75. $searchS = $_POST["searchS"];
  76. $num = $_GET['num'] = 0;
  77. $oreon->historySearchService[$url] = $searchS;
  78. } else if (isset($oreon->historySearchService[$url])) {
  79. $searchS = $oreon->historySearchService[$url];
  80. } else {
  81. $searchS = NULL;
  82. }
  83. /* Search for poller */
  84. if (isset($_POST['searchP']) && is_numeric($_POST['searchP'])) {
  85. $searchP = $_POST['searchP'];
  86. $num = $_GET['num'] = 0;
  87. } else {
  88. $searchP = NULL;
  89. }
  90. /* Get broker type */
  91. $brk = new CentreonBroker($pearDB);
  92. if ((isset($_POST["o1"]) && $_POST["o1"]) || (isset($_POST["o2"]) && $_POST["o2"])){
  93. if ($_POST["o"] == "rg" && isset($_POST["select"])){
  94. $selected = $_POST["select"];
  95. foreach ($selected as $key => $value){
  96. $DBRESULT = $pearDBO->query("UPDATE index_data SET `must_be_rebuild` = '1' WHERE id = '".$key."'");
  97. }
  98. $brk->reload();
  99. } else if ($_POST["o"] == "nrg" && isset($_POST["select"])){
  100. $selected = $_POST["select"];
  101. foreach ($selected as $key => $value){
  102. $DBRESULT = $pearDBO->query("UPDATE index_data SET `must_be_rebuild` = '0' WHERE id = '".$key."' AND `must_be_rebuild` = '1'");
  103. }
  104. } else if ($_POST["o"] == "ed" && isset($_POST["select"])){
  105. $selected = $_POST["select"];
  106. $listMetricsToDelete = array();
  107. foreach ($selected as $key => $value){
  108. $DBRESULT = $pearDBO->query("SELECT metric_id FROM metrics WHERE `index_id` = '".$key."'");
  109. while ($metrics = $DBRESULT->fetchRow()){
  110. $listMetricsToDelete[] = $metrics['metric_id'];
  111. }
  112. }
  113. $listMetricsToDelete = array_unique($listMetricsToDelete);
  114. if (count($listMetricsToDelete) > 0) {
  115. $pearDBO->query("UPDATE metrics SET to_delete = 1 WHERE metric_id IN (" . join(', ', $listMetricsToDelete) . ")");
  116. $pearDBO->query("UPDATE index_data SET to_delete = 1 WHERE id IN (" . join(', ', array_keys($selected)) . ")");
  117. $pearDB->query("DELETE FROM ods_view_details WHERE metric_id IN (" . join(', ', $listMetricsToDelete) . ")");
  118. $brk = new CentreonBroker($pearDB);
  119. if ($brk->getBroker() == 'broker') {
  120. $brk->reload();
  121. }
  122. }
  123. } else if ($_POST["o"] == "hg" && isset($_POST["select"])){
  124. $selected = $_POST["select"];
  125. foreach ($selected as $key => $value){
  126. $DBRESULT = $pearDBO->query("UPDATE index_data SET `hidden` = '1' WHERE id = '".$key."'");
  127. }
  128. } else if ($_POST["o"] == "nhg" && isset($_POST["select"])){
  129. $selected = $_POST["select"];
  130. foreach ($selected as $key => $value){
  131. $DBRESULT = $pearDBO->query("UPDATE index_data SET `hidden` = '0' WHERE id = '".$key."'");
  132. }
  133. } else if ($_POST["o"] == "lk" && isset($_POST["select"])){
  134. $selected = $_POST["select"];
  135. foreach ($selected as $key => $value){
  136. $DBRESULT = $pearDBO->query("UPDATE index_data SET `locked` = '1' WHERE id = '".$key."'");
  137. }
  138. } else if ($_POST["o"] == "nlk" && isset($_POST["select"])){
  139. $selected = $_POST["select"];
  140. foreach ($selected as $key => $value){
  141. $DBRESULT = $pearDBO->query("UPDATE index_data SET `locked` = '0' WHERE id = '".$key."'");
  142. }
  143. }
  144. }
  145. if (isset($_POST["o"]) && $_POST["o"] == "d" && isset($_POST["id"])){
  146. $DBRESULT = $pearDBO->query("UPDATE index_data SET `trashed` = '1' WHERE id = '".htmlentities($_POST["id"], ENT_QUOTES, 'UTF-8')."'");
  147. }
  148. if (isset($_POST["o"]) && $_POST["o"] == "rb" && isset($_POST["id"])){
  149. $DBRESULT = $pearDBO->query("UPDATE index_data SET `must_be_rebuild` = '1' WHERE id = '".htmlentities($_POST["id"], ENT_QUOTES, 'UTF-8')."'");
  150. }
  151. $search_string = "";
  152. $extTables = "";
  153. if ($searchH != "" || $searchS != "" || $searchP != "") {
  154. if ($searchH != ""){
  155. $search_string .= " AND i.host_name LIKE '%".htmlentities($searchH, ENT_QUOTES, 'UTF-8')."%' ";
  156. }
  157. if ($searchS != "") {
  158. $search_string .= " AND i.service_description LIKE '%".htmlentities($searchS, ENT_QUOTES, 'UTF-8')."%' ";
  159. }
  160. if ($searchP != "") {
  161. /* Centron Broker */
  162. $extTables = ", hosts h";
  163. $search_string .= " AND i.host_id = h.host_id AND h.instance_id = " . $searchP;
  164. }
  165. }
  166. $tab_class = array("0" => "list_one", "1" => "list_two");
  167. $storage_type = array(0 => "RRDTool", 2 => "RRDTool & MySQL");
  168. $yesOrNo = array(0 => "No", 1 => "Yes", 2 => "Rebuilding");
  169. $data = array();
  170. $DBRESULT = $pearDBO->query("SELECT SQL_CALC_FOUND_ROWS DISTINCT i.* FROM index_data i, metrics m" . $extTables . " WHERE i.id = m.index_id $search_string ORDER BY host_name, service_description LIMIT ".$num * $limit.", $limit");
  171. $rows = $pearDBO->numberRows();
  172. for ($i = 0; $index_data = $DBRESULT->fetchRow(); $i++) {
  173. $DBRESULT2 = $pearDBO->query("SELECT * FROM metrics WHERE index_id = '".$index_data["id"]."' ORDER BY metric_name");
  174. $metric = "";
  175. for ($im = 0;$metrics = $DBRESULT2->fetchRow();$im++){
  176. if ($im) {
  177. $metric .= " - ";
  178. }
  179. $metric .= $metrics["metric_name"]; // "<a href='./main.php?p=50119&o=mmtrc&index_id=".$index_data["id"]."'>".$metrics["metric_name"]."</a>";
  180. if (isset($metrics["unit_name"]) && $metrics["unit_name"]) {
  181. $metric .= "(".$metrics["unit_name"].")";
  182. }
  183. }
  184. $index_data["metrics_name"] = $metric;
  185. $index_data["service_description"] = "<a href='./main.php?p=50119&o=msvc&index_id=".$index_data["id"]."'>".$index_data["service_description"]."</a>";
  186. $index_data["storage_type"] = $storage_type[$index_data["storage_type"]];
  187. $index_data["must_be_rebuild"] = $yesOrNo[$index_data["must_be_rebuild"]];
  188. $index_data["to_delete"] = $yesOrNo[$index_data["to_delete"]];
  189. $index_data["trashed"] = $yesOrNo[$index_data["trashed"]];
  190. $index_data["hidden"] = $yesOrNo[$index_data["hidden"]];
  191. if (isset($index_data["locked"])) {
  192. $index_data["locked"] = $yesOrNo[$index_data["locked"]];
  193. } else {
  194. $index_data["locked"] = $yesOrNo[0];
  195. }
  196. $index_data["class"] = $tab_class[$i % 2];
  197. $data[$i] = $index_data;
  198. }
  199. /* Get the list of running poller */
  200. $queryPollers = "SELECT instance_id, name FROM instances ORDER BY name";
  201. $res = $pearDBO->query($queryPollers);
  202. $instances = array();
  203. if (false === PEAR::isError($res)) {
  204. while ($row = $res->fetchRow()) {
  205. $instances[$row['instance_id']] = $row['name'];
  206. }
  207. }
  208. include("./include/common/checkPagination.php");
  209. /*
  210. * Smarty template Init
  211. */
  212. $tpl = new Smarty();
  213. $tpl = initSmartyTpl($path, $tpl);
  214. $form = new HTML_QuickForm('form', 'POST', "?p=".$p);
  215. ?>
  216. <script type="text/javascript">
  217. function setO(_i) {
  218. document.forms['form'].elements['o'].value = _i;
  219. }
  220. </script>
  221. <?php
  222. $attrs1 = array(
  223. 'onchange'=>"javascript: " .
  224. "if (this.form.elements['o1'].selectedIndex == 1) {" .
  225. " setO(this.form.elements['o1'].value); submit();} " .
  226. "else if (this.form.elements['o1'].selectedIndex == 2) {" .
  227. " setO(this.form.elements['o1'].value); submit();} " .
  228. "else if (this.form.elements['o1'].selectedIndex == 3 && confirm('"._('Do you confirm the deletion ?')."')) {" .
  229. " setO(this.form.elements['o1'].value); submit();} " .
  230. "else if (this.form.elements['o1'].selectedIndex == 4) {" .
  231. " setO(this.form.elements['o1'].value); submit();} " .
  232. "else if (this.form.elements['o1'].selectedIndex == 5) {" .
  233. " setO(this.form.elements['o1'].value); submit();} " .
  234. "else if (this.form.elements['o1'].selectedIndex == 6) {" .
  235. " setO(this.form.elements['o1'].value); submit();} " .
  236. "else if (this.form.elements['o1'].selectedIndex == 7) {" .
  237. " setO(this.form.elements['o1'].value); submit();} " .
  238. "");
  239. $form->addElement('select', 'o1', NULL, array(NULL=>_("More actions..."), "rg"=>_("Rebuild RRD Database"), "nrg"=>_("Stop rebuilding RRD Databases"), "ed"=>_("Delete graphs"), "hg"=>_("Hide graphs of selected Services"), "nhg"=>_("Stop hiding graphs of selected Services"), "lk"=>_("Lock Services"), "nlk"=>_("Unlock Services")), $attrs1);
  240. $form->setDefaults(array('o1' => NULL));
  241. $attrs2 = array(
  242. 'onchange'=>"javascript: " .
  243. "if (this.form.elements['o2'].selectedIndex == 1) {" .
  244. " setO(this.form.elements['o2'].value); submit();} " .
  245. "else if (this.form.elements['o2'].selectedIndex == 2) {" .
  246. " setO(this.form.elements['o2'].value); submit();} " .
  247. "else if (this.form.elements['o2'].selectedIndex == 3 && confirm('"._('Do you confirm the deletion ?')."')) {" .
  248. " setO(this.form.elements['o2'].value); submit();} " .
  249. "else if (this.form.elements['o2'].selectedIndex == 4) {" .
  250. " setO(this.form.elements['o2'].value); submit();} " .
  251. "else if (this.form.elements['o2'].selectedIndex == 5) {" .
  252. " setO(this.form.elements['o2'].value); submit();} " .
  253. "else if (this.form.elements['o2'].selectedIndex == 6) {" .
  254. " setO(this.form.elements['o2'].value); submit();} " .
  255. "else if (this.form.elements['o2'].selectedIndex == 7) {" .
  256. " setO(this.form.elements['o2'].value); submit();} " .
  257. "");
  258. $form->addElement('select', 'o2', NULL, array(NULL=>_("More actions..."), "rg"=>_("Rebuild RRD Database"), "nrg"=>_("Stop rebuilding RRD Databases"), "ed"=>_("Delete graphs"), "hg"=>_("Hide graphs of selected Services"), "nhg"=>_("Stop hiding graphs of selected Services"), "lk"=>_("Lock Services"), "nlk"=>_("Unlock Services")), $attrs2);
  259. $form->setDefaults(array('o2' => NULL));
  260. $o1 = $form->getElement('o1');
  261. $o1->setValue(NULL);
  262. $o1->setSelected(NULL);
  263. $o2 = $form->getElement('o2');
  264. $o2->setValue(NULL);
  265. $o2->setSelected(NULL);
  266. $tpl->assign('limit', $limit);
  267. $tpl->assign("p", $p);
  268. $tpl->assign('o', $o);
  269. $tpl->assign("num", $num);
  270. $tpl->assign("limit", $limit);
  271. $tpl->assign("data", $data);
  272. $tpl->assign("instances", $instances);
  273. $tpl->assign("Host", _("Host"));
  274. $tpl->assign("Service", _("Service"));
  275. $tpl->assign("Metrics", _("Metrics"));
  276. $tpl->assign("RebuildWaiting", _("Rebuild Waiting"));
  277. $tpl->assign("Delete", _("Delete"));
  278. $tpl->assign("Hidden", _("Hidden"));
  279. $tpl->assign("Locked", _("Locked"));
  280. $tpl->assign("StorageType", _("Storage Type"));
  281. $tpl->assign("Actions", _("Actions"));
  282. $tpl->assign('Services', _("Services"));
  283. $tpl->assign('Hosts', _("Hosts"));
  284. $tpl->assign('Pollers', _("Pollers"));
  285. $tpl->assign('Search', _("Search"));
  286. if (isset($searchH)) {
  287. $tpl->assign('searchH', $searchH);
  288. }
  289. if (isset($searchS)) {
  290. $tpl->assign('searchS', $searchS);
  291. }
  292. if (isset($searchP)) {
  293. $tpl->assign('searchP', $searchP);
  294. } else {
  295. $tpl->assign('searchP', '');
  296. }
  297. $renderer = new HTML_QuickForm_Renderer_ArraySmarty($tpl);
  298. $form->accept($renderer);
  299. $tpl->assign('form', $renderer->toArray());
  300. $tpl->display("viewData.ihtml");