event.class.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. // Copyright (C) 2010 Combodo SARL
  3. //
  4. // This program is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation; version 3 of the License.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. /**
  17. * Persistent class Event and derived
  18. * Application internal events
  19. * There is also a file log
  20. *
  21. * @author Erwan Taloc <erwan.taloc@combodo.com>
  22. * @author Romain Quetiez <romain.quetiez@combodo.com>
  23. * @author Denis Flaven <denis.flaven@combodo.com>
  24. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  25. */
  26. class Event extends cmdbAbstractObject
  27. {
  28. public static function Init()
  29. {
  30. $aParams = array
  31. (
  32. "category" => "core/cmdb,view_in_gui",
  33. "key_type" => "autoincrement",
  34. "name_attcode" => "",
  35. "state_attcode" => "",
  36. "reconc_keys" => array(),
  37. "db_table" => "priv_event",
  38. "db_key_field" => "id",
  39. "db_finalclass_field" => "realclass",
  40. "display_template" => "",
  41. );
  42. MetaModel::Init_Params($aParams);
  43. //MetaModel::Init_InheritAttributes();
  44. MetaModel::Init_AddAttribute(new AttributeText("message", array("allowed_values"=>null, "sql"=>"message", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  45. MetaModel::Init_AddAttribute(new AttributeDateTime("date", array("allowed_values"=>null, "sql"=>"date", "default_value"=>"", "is_null_allowed"=>false, "depends_on"=>array())));
  46. MetaModel::Init_AddAttribute(new AttributeString("userinfo", array("allowed_values"=>null, "sql"=>"userinfo", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  47. // Display lists
  48. MetaModel::Init_SetZListItems('details', array('message', 'date', 'userinfo')); // Attributes to be displayed for the complete details
  49. MetaModel::Init_SetZListItems('list', array('date', 'finalclass', 'message')); // Attributes to be displayed for a list
  50. // Search criteria
  51. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  52. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  53. }
  54. }
  55. class EventNotification extends Event
  56. {
  57. public static function Init()
  58. {
  59. $aParams = array
  60. (
  61. "category" => "core/cmdb,view_in_gui",
  62. "key_type" => "autoincrement",
  63. "name_attcode" => "",
  64. "state_attcode" => "",
  65. "reconc_keys" => array(),
  66. "db_table" => "priv_event_notification",
  67. "db_key_field" => "id",
  68. "db_finalclass_field" => "",
  69. "display_template" => "",
  70. );
  71. MetaModel::Init_Params($aParams);
  72. MetaModel::Init_InheritAttributes();
  73. MetaModel::Init_AddAttribute(new AttributeExternalKey("trigger_id", array("targetclass"=>"Trigger", "jointype"=> "", "allowed_values"=>null, "sql"=>"trigger_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  74. MetaModel::Init_AddAttribute(new AttributeExternalKey("action_id", array("targetclass"=>"Action", "jointype"=> "", "allowed_values"=>null, "sql"=>"action_id", "is_null_allowed"=>false, "on_target_delete"=>DEL_AUTO, "depends_on"=>array())));
  75. MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  76. // Display lists
  77. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'trigger_id', 'action_id', 'object_id')); // Attributes to be displayed for the complete details
  78. MetaModel::Init_SetZListItems('list', array('date', 'userinfo')); // Attributes to be displayed for a list
  79. // Search criteria
  80. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  81. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  82. }
  83. }
  84. class EventNotificationEmail extends EventNotification
  85. {
  86. public static function Init()
  87. {
  88. $aParams = array
  89. (
  90. "category" => "core/cmdb,view_in_gui",
  91. "key_type" => "autoincrement",
  92. "name_attcode" => "",
  93. "state_attcode" => "",
  94. "reconc_keys" => array(),
  95. "db_table" => "priv_event_email",
  96. "db_key_field" => "id",
  97. "db_finalclass_field" => "",
  98. "display_template" => "",
  99. );
  100. MetaModel::Init_Params($aParams);
  101. MetaModel::Init_InheritAttributes();
  102. MetaModel::Init_AddAttribute(new AttributeText("to", array("allowed_values"=>null, "sql"=>"to", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  103. MetaModel::Init_AddAttribute(new AttributeText("cc", array("allowed_values"=>null, "sql"=>"cc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  104. MetaModel::Init_AddAttribute(new AttributeText("bcc", array("allowed_values"=>null, "sql"=>"bcc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  105. MetaModel::Init_AddAttribute(new AttributeText("from", array("allowed_values"=>null, "sql"=>"from", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  106. MetaModel::Init_AddAttribute(new AttributeText("subject", array("allowed_values"=>null, "sql"=>"subject", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  107. MetaModel::Init_AddAttribute(new AttributeText("body", array("allowed_values"=>null, "sql"=>"body", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  108. // Display lists
  109. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'message', 'trigger_id', 'action_id', 'object_id', 'to', 'cc', 'bcc', 'from', 'subject', 'body')); // Attributes to be displayed for the complete details
  110. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'message', 'to', 'subject')); // Attributes to be displayed for a list
  111. // Search criteria
  112. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  113. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  114. }
  115. }
  116. class EventIssue extends Event
  117. {
  118. public static function Init()
  119. {
  120. $aParams = array
  121. (
  122. "category" => "core/cmdb,view_in_gui",
  123. "key_type" => "autoincrement",
  124. "name_attcode" => "",
  125. "state_attcode" => "",
  126. "reconc_keys" => array(),
  127. "db_table" => "priv_event_issue",
  128. "db_key_field" => "id",
  129. "db_finalclass_field" => "",
  130. "display_template" => "",
  131. );
  132. MetaModel::Init_Params($aParams);
  133. MetaModel::Init_InheritAttributes();
  134. MetaModel::Init_AddAttribute(new AttributeString("issue", array("allowed_values"=>null, "sql"=>"issue", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  135. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  136. MetaModel::Init_AddAttribute(new AttributeString("page", array("allowed_values"=>null, "sql"=>"page", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  137. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_post", array("allowed_values"=>null, "sql"=>"arguments_post", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  138. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_get", array("allowed_values"=>null, "sql"=>"arguments_get", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  139. MetaModel::Init_AddAttribute(new AttributeTable("callstack", array("allowed_values"=>null, "sql"=>"callstack", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  140. MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  141. // Display lists
  142. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
  143. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
  144. // Search criteria
  145. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  146. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  147. }
  148. protected function OnInsert()
  149. {
  150. // Init page information: name, arguments
  151. //
  152. $this->Set('page', @$GLOBALS['_SERVER']['SCRIPT_NAME']);
  153. if (array_key_exists('_GET', $GLOBALS) && is_array($GLOBALS['_GET']))
  154. {
  155. $this->Set('arguments_get', $GLOBALS['_GET']);
  156. }
  157. else
  158. {
  159. $this->Set('arguments_get', array());
  160. }
  161. if (array_key_exists('_POST', $GLOBALS) && is_array($GLOBALS['_POST']))
  162. {
  163. $aPost = array();
  164. foreach($GLOBALS['_POST'] as $sKey => $sValue)
  165. {
  166. if (is_string($sValue))
  167. {
  168. if (strlen($sValue) < 256)
  169. {
  170. $aPost[$sKey] = $sValue;
  171. }
  172. else
  173. {
  174. $aPost[$sKey] = "!long string: ".strlen($sValue). " chars";
  175. }
  176. }
  177. else
  178. {
  179. // Not a string
  180. $aPost[$sKey] = (string) $sValue;
  181. }
  182. }
  183. $this->Set('arguments_post', $aPost);
  184. }
  185. else
  186. {
  187. $this->Set('arguments_post', array());
  188. }
  189. $sLength = strlen($this->Get('issue'));
  190. if ($sLength > 255)
  191. {
  192. $this->Set('issue', substr($this->Get('issue'), 0, 200)." -truncated ($sLength chars)");
  193. }
  194. $sLength = strlen($this->Get('impact'));
  195. if ($sLength > 255)
  196. {
  197. $this->Set('impact', substr($this->Get('impact'), 0, 200)." -truncated ($sLength chars)");
  198. }
  199. $sLength = strlen($this->Get('page'));
  200. if ($sLength > 255)
  201. {
  202. $this->Set('page', substr($this->Get('page'), 0, 200)." -truncated ($sLength chars)");
  203. }
  204. }
  205. }
  206. class EventWebService extends Event
  207. {
  208. public static function Init()
  209. {
  210. $aParams = array
  211. (
  212. "category" => "core/cmdb,view_in_gui",
  213. "key_type" => "autoincrement",
  214. "name_attcode" => "",
  215. "state_attcode" => "",
  216. "reconc_keys" => array(),
  217. "db_table" => "priv_event_webservice",
  218. "db_key_field" => "id",
  219. "db_finalclass_field" => "",
  220. "display_template" => "",
  221. );
  222. MetaModel::Init_Params($aParams);
  223. MetaModel::Init_InheritAttributes();
  224. MetaModel::Init_AddAttribute(new AttributeString("verb", array("allowed_values"=>null, "sql"=>"verb", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  225. //MetaModel::Init_AddAttribute(new AttributeStructure("arguments", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  226. MetaModel::Init_AddAttribute(new AttributeBoolean("result", array("allowed_values"=>null, "sql"=>"result", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  227. MetaModel::Init_AddAttribute(new AttributeText("log_info", array("allowed_values"=>null, "sql"=>"log_info", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  228. MetaModel::Init_AddAttribute(new AttributeText("log_warning", array("allowed_values"=>null, "sql"=>"log_warning", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  229. MetaModel::Init_AddAttribute(new AttributeText("log_error", array("allowed_values"=>null, "sql"=>"log_error", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  230. MetaModel::Init_AddAttribute(new AttributeText("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  231. // Display lists
  232. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'verb', 'result', 'log_info', 'log_warning', 'log_error', 'data')); // Attributes to be displayed for the complete details
  233. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'verb', 'result')); // Attributes to be displayed for a list
  234. // Search criteria
  235. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  236. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  237. }
  238. }
  239. ?>