PageRenderTime 25ms CodeModel.GetById 4ms RepoModel.GetById 1ms app.codeStats 0ms

/www/include/monitoring/status/Services/xml/makeXMLForOneService.php

https://gitlab.com/florianocomercial/centreon
PHP | 287 lines | 180 code | 31 blank | 76 comment | 26 complexity | 17fe8a4c2940cb6b8a0e50932e0801f9 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. /**
  36. * Require Centreon Config file
  37. */
  38. require_once realpath(dirname(__FILE__) . "/../../../../../../config/centreon.config.php");
  39. include_once $centreon_path . "www/class/centreonUtils.class.php";
  40. /**
  41. * Include Monitoring Classes
  42. */
  43. include_once _CENTREON_PATH_ . "www/class/centreonXMLBGRequest.class.php";
  44. include_once _CENTREON_PATH_ . "www/class/centreonLang.class.php";
  45. /*
  46. * Create XML Request Objects
  47. */
  48. CentreonSession::start();
  49. $obj = new CentreonXMLBGRequest(session_id(), 1, 1, 0, 1);
  50. /**
  51. * Manage Session
  52. */
  53. $centreon = $_SESSION['centreon'];
  54. /**
  55. * Check Security
  56. */
  57. if (isset($obj->session_id) && CentreonSession::checkSession($obj->session_id, $obj->DB)) {
  58. ;
  59. } else {
  60. print "Bad Session ID";
  61. exit();
  62. }
  63. /** **************************************************
  64. * Enable Lang Object
  65. */
  66. $centreonlang = new CentreonLang(_CENTREON_PATH_, $centreon);
  67. $centreonlang->bindLang();
  68. /** **************************************************
  69. * Check Arguments From GET tab
  70. */
  71. $svc_id = $obj->checkArgument("svc_id", $_GET, 0);
  72. $enable = $obj->checkArgument("enable", $_GET, "");
  73. $disable = $obj->checkArgument("disable", $_GET, "disable");
  74. $dateFormat = $obj->checkArgument("date_time_format_status", $_GET, "d/m/Y H:i:s");
  75. $tab = preg_split('/\_/', $svc_id);
  76. $host_id = $tab[0];
  77. $service_id = $tab[1];
  78. /** **************************************************
  79. * Get Service status
  80. */
  81. $rq1 = "SELECT s.state," .
  82. " h.name, " .
  83. " s.description," .
  84. " s.last_check," .
  85. " s.next_check," .
  86. " s.last_state_change," .
  87. " s.last_notification," .
  88. " s.next_notification," .
  89. " s.last_hard_state_change," .
  90. " s.last_hard_state," .
  91. " s.latency," .
  92. " s.last_time_ok," .
  93. " s.last_time_critical," .
  94. " s.last_time_unknown," .
  95. " s.last_time_warning," .
  96. " s.notification_number," .
  97. " s.scheduled_downtime_depth," .
  98. " s.output," .
  99. " s.notes," .
  100. " ROUND(s.percent_state_change) as percent_state_change," .
  101. " s.notify," .
  102. " s.perfdata," .
  103. " s.state_type," .
  104. " s.execution_time," .
  105. " s.event_handler_enabled, " .
  106. " s.icon_image, " .
  107. " s.display_name " .
  108. " FROM hosts h, services s " .
  109. " WHERE s.host_id = h.host_id " .
  110. " AND s.host_id = $host_id AND service_id = $service_id LIMIT 1";
  111. /*
  112. * Init Buffer
  113. */
  114. $obj->XML->startElement("reponse");
  115. /*
  116. * Request
  117. */
  118. $DBRESULT = $obj->DBC->query($rq1);
  119. if ($data = $DBRESULT->fetchRow()) {
  120. /* Split the plugin_output */
  121. $outputLines = explode('\n', $data['output']);
  122. if (strlen($outputLines[0]) > 100) {
  123. $pluginShortOuput = sprintf("%.100s", $outputLines[0])."...";
  124. } else {
  125. $pluginShortOuput = $outputLines[0];
  126. }
  127. $obj->XML->writeElement("svc_name", CentreonUtils::escapeSecure($data["description"]), false);
  128. if ($data["icon_image"] == "") {
  129. $data["icon_image"] = "./img/icons/service.png";
  130. } else {
  131. $data["icon_image"] = "./img/media/" . $data["icon_image"];
  132. }
  133. $duration = "";
  134. if ($data["last_state_change"] > 0) {
  135. $duration = CentreonDuration::toString(time() - $data["last_state_change"]);
  136. }
  137. $last_notification = "N/A";
  138. if ($data["last_notification"] > 0) {
  139. $last_notification = $data["last_notification"];
  140. }
  141. $next_notification = "N/A";
  142. if ($data["next_notification"] > 0) {
  143. $next_notification = $data["next_notification"];
  144. }
  145. if ($data["last_check"] == 0) {
  146. $data["last_check"] = _("N/A");
  147. }
  148. if ($data['name'] == '_Module_Meta') {
  149. $hostname = _('Meta service');
  150. $service_desc = $data['display_name'];
  151. } else {
  152. $hostname = $data['name'];
  153. $service_desc = $data['description'];
  154. }
  155. $obj->XML->writeElement("service_description", CentreonUtils::escapeSecure($service_desc), false);
  156. $obj->XML->writeElement("hostname", CentreonUtils::escapeSecure($hostname), false);
  157. $obj->XML->writeElement("color", $obj->backgroundService[$data["state"]]);
  158. $obj->XML->startElement("current_state");
  159. $obj->XML->writeAttribute("color", $obj->colorService[$data["state"]]);
  160. $obj->XML->text(_($obj->statusService[$data["state"]]), false);
  161. $obj->XML->endElement();
  162. $obj->XML->writeElement("current_state_name", _("Host Status"), 0);
  163. $obj->XML->startElement("plugin_output");
  164. $obj->XML->writeAttribute("name", _("Status Information"));
  165. $obj->XML->text(CentreonUtils::escapeSecure($pluginShortOuput), 0);
  166. $obj->XML->endElement();
  167. $tab_perf = preg_split("/\ /", $data["perfdata"]);
  168. foreach ($tab_perf as $val) {
  169. $obj->XML->startElement("performance_data");
  170. $obj->XML->writeElement("perf_data", CentreonUtils::escapeSecure($val));
  171. $obj->XML->endElement();
  172. }
  173. $obj->XML->writeElement("performance_data_name", _("Performance Data"), 0);
  174. $obj->XML->writeElement("state_type", $obj->stateTypeFull[$data["state_type"]]);
  175. $obj->XML->writeElement("state_type_name", _("State Type"), 0);
  176. $obj->XML->writeElement("last_check", $obj->GMT->getDate($dateFormat, $data["last_check"]));
  177. $obj->XML->writeElement("last_check_name", _("Last Check"), 0);
  178. $obj->XML->writeElement("next_check", $obj->GMT->getDate($dateFormat, $data["next_check"]));
  179. $obj->XML->writeElement("next_check_name", _("Next Check"), 0);
  180. $obj->XML->writeElement("check_latency", $data["latency"]);
  181. $obj->XML->writeElement("check_latency_name", _("Latency"), 0);
  182. $obj->XML->writeElement("check_execution_time", $data["execution_time"]);
  183. $obj->XML->writeElement("check_execution_time_name", _("Execution Time"), 0);
  184. $obj->XML->writeElement("last_state_change", $obj->GMT->getDate($dateFormat, $data["last_state_change"]));
  185. $obj->XML->writeElement("last_state_change_name", _("Last State Change"), 0);
  186. $obj->XML->writeElement("duration", $duration);
  187. $obj->XML->writeElement("duration_name", _("Current State Duration"), 0);
  188. $obj->XML->writeElement("last_notification", $obj->GMT->getDate($dateFormat, $last_notification));
  189. $obj->XML->writeElement("last_notification_name", _("Last Notification"), 0);
  190. $obj->XML->writeElement("next_notification", $obj->GMT->getDate($dateFormat, $next_notification));
  191. $obj->XML->writeElement("next_notification_name", _("Next Notification"), 0);
  192. $obj->XML->writeElement("current_notification_number", $data["notification_number"]);
  193. $obj->XML->writeElement("current_notification_number_name", _("Current Notification Number"), 0);
  194. $obj->XML->writeElement("percent_state_change", $data["percent_state_change"]);
  195. $obj->XML->writeElement("percent_state_change_name", _("Percent State Change"), 0);
  196. $obj->XML->writeElement("is_downtime", ($data["scheduled_downtime_depth"] ? $obj->en["1"] : $obj->en["0"]));
  197. $obj->XML->writeElement("is_downtime_name", _("In Scheduled Downtime?"), 0);
  198. $obj->XML->writeElement("last_update", $obj->GMT->getDate($dateFormat, time()));
  199. $obj->XML->writeElement("last_update_name", _("Last Update"), 0);
  200. $obj->XML->writeElement("ico", $data["icon_image"]);
  201. $obj->XML->startElement("last_time_ok");
  202. $obj->XML->writeAttribute("name", _("Last ok time"));
  203. if ($data["last_time_ok"] == 0) {
  204. $data["last_time_ok"] = _("N/A");
  205. }
  206. $obj->XML->text($obj->GMT->getDate($dateFormat, $data["last_time_ok"]));
  207. $obj->XML->endElement();
  208. $obj->XML->startElement("last_time_warning");
  209. $obj->XML->writeAttribute("name", _("Last warning time"));
  210. if ($data["last_time_warning"] == 0) {
  211. $data["last_time_warning"] = _("N/A");
  212. }
  213. $obj->XML->text($obj->GMT->getDate($dateFormat, $data["last_time_warning"]));
  214. $obj->XML->endElement();
  215. $obj->XML->startElement("last_time_unknown");
  216. $obj->XML->writeAttribute("name", _("Last unknown time"));
  217. if ($data["last_time_unknown"] == 0) {
  218. $data["last_time_unknown"] = _("N/A");
  219. }
  220. $obj->XML->text($obj->GMT->getDate($dateFormat, $data["last_time_unknown"]));
  221. $obj->XML->endElement();
  222. $obj->XML->startElement("last_time_critical");
  223. $obj->XML->writeAttribute("name", _("Last critical time"));
  224. if ($data["last_time_critical"] == 0) {
  225. $data["last_time_critical"] = _("N/A");
  226. }
  227. $obj->XML->text($obj->GMT->getDate($dateFormat, $data["last_time_critical"]));
  228. $obj->XML->endElement();
  229. $obj->XML->startElement("notes");
  230. $obj->XML->writeAttribute("name", _("Notes"));
  231. $obj->XML->text(CentreonUtils::escapeSecure($data['notes']));
  232. $obj->XML->endElement();
  233. } else {
  234. $obj->XML->writeElement("infos", "none");
  235. }
  236. unset($data);
  237. /*
  238. * Translations
  239. */
  240. $obj->XML->writeElement("tr1", _("Check information"), 0);
  241. $obj->XML->writeElement("tr2", _("Notification Information"), 0);
  242. $obj->XML->writeElement("tr3", _("Last Status Change"), 0);
  243. $obj->XML->writeElement("tr4", _("Extended information"), 0);
  244. $obj->XML->writeElement("tr5", _("Status Information"), 0);
  245. /*
  246. * End Buffer
  247. */
  248. $obj->XML->endElement();
  249. /*
  250. * Send Header
  251. */
  252. $obj->header();
  253. /*
  254. * Send XML
  255. */
  256. $obj->XML->output();