event.class.inc.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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",
  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. static public function IsReadOnly()
  55. {
  56. return true;
  57. }
  58. }
  59. class EventNotification extends Event
  60. {
  61. public static function Init()
  62. {
  63. $aParams = array
  64. (
  65. "category" => "core/cmdb",
  66. "key_type" => "autoincrement",
  67. "name_attcode" => "",
  68. "state_attcode" => "",
  69. "reconc_keys" => array(),
  70. "db_table" => "priv_event_notification",
  71. "db_key_field" => "id",
  72. "db_finalclass_field" => "",
  73. "display_template" => "",
  74. );
  75. MetaModel::Init_Params($aParams);
  76. MetaModel::Init_InheritAttributes();
  77. 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())));
  78. 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())));
  79. MetaModel::Init_AddAttribute(new AttributeInteger("object_id", array("allowed_values"=>null, "sql"=>"object_id", "default_value"=>0, "is_null_allowed"=>false, "depends_on"=>array())));
  80. // Display lists
  81. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'trigger_id', 'action_id', 'object_id')); // Attributes to be displayed for the complete details
  82. MetaModel::Init_SetZListItems('list', array('date', 'userinfo')); // Attributes to be displayed for a list
  83. // Search criteria
  84. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  85. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  86. }
  87. }
  88. class EventNotificationEmail extends EventNotification
  89. {
  90. public static function Init()
  91. {
  92. $aParams = array
  93. (
  94. "category" => "core/cmdb",
  95. "key_type" => "autoincrement",
  96. "name_attcode" => "",
  97. "state_attcode" => "",
  98. "reconc_keys" => array(),
  99. "db_table" => "priv_event_email",
  100. "db_key_field" => "id",
  101. "db_finalclass_field" => "",
  102. "display_template" => "",
  103. );
  104. MetaModel::Init_Params($aParams);
  105. MetaModel::Init_InheritAttributes();
  106. MetaModel::Init_AddAttribute(new AttributeText("to", array("allowed_values"=>null, "sql"=>"to", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  107. MetaModel::Init_AddAttribute(new AttributeText("cc", array("allowed_values"=>null, "sql"=>"cc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  108. MetaModel::Init_AddAttribute(new AttributeText("bcc", array("allowed_values"=>null, "sql"=>"bcc", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  109. MetaModel::Init_AddAttribute(new AttributeText("from", array("allowed_values"=>null, "sql"=>"from", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  110. MetaModel::Init_AddAttribute(new AttributeText("subject", array("allowed_values"=>null, "sql"=>"subject", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  111. MetaModel::Init_AddAttribute(new AttributeText("body", array("allowed_values"=>null, "sql"=>"body", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  112. // Display lists
  113. 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
  114. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'message', 'subject')); // Attributes to be displayed for a list
  115. // Search criteria
  116. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  117. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  118. }
  119. }
  120. class EventIssue extends Event
  121. {
  122. public static function Init()
  123. {
  124. $aParams = array
  125. (
  126. "category" => "core/cmdb",
  127. "key_type" => "autoincrement",
  128. "name_attcode" => "",
  129. "state_attcode" => "",
  130. "reconc_keys" => array(),
  131. "db_table" => "priv_event_issue",
  132. "db_key_field" => "id",
  133. "db_finalclass_field" => "",
  134. "display_template" => "",
  135. );
  136. MetaModel::Init_Params($aParams);
  137. MetaModel::Init_InheritAttributes();
  138. MetaModel::Init_AddAttribute(new AttributeString("issue", array("allowed_values"=>null, "sql"=>"issue", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  139. MetaModel::Init_AddAttribute(new AttributeString("impact", array("allowed_values"=>null, "sql"=>"impact", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  140. MetaModel::Init_AddAttribute(new AttributeString("page", array("allowed_values"=>null, "sql"=>"page", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  141. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_post", array("allowed_values"=>null, "sql"=>"arguments_post", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  142. MetaModel::Init_AddAttribute(new AttributePropertySet("arguments_get", array("allowed_values"=>null, "sql"=>"arguments_get", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  143. MetaModel::Init_AddAttribute(new AttributeTable("callstack", array("allowed_values"=>null, "sql"=>"callstack", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  144. MetaModel::Init_AddAttribute(new AttributePropertySet("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
  145. // Display lists
  146. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'issue', 'impact', 'page', 'arguments_post', 'arguments_get', 'callstack', 'data')); // Attributes to be displayed for the complete details
  147. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'issue', 'impact')); // Attributes to be displayed for a list
  148. // Search criteria
  149. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  150. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  151. }
  152. protected function OnInsert()
  153. {
  154. // Init page information: name, arguments
  155. //
  156. $this->Set('page', @$GLOBALS['_SERVER']['SCRIPT_NAME']);
  157. if (array_key_exists('_GET', $GLOBALS) && is_array($GLOBALS['_GET']))
  158. {
  159. $this->Set('arguments_get', $GLOBALS['_GET']);
  160. }
  161. else
  162. {
  163. $this->Set('arguments_get', array());
  164. }
  165. if (array_key_exists('_POST', $GLOBALS) && is_array($GLOBALS['_POST']))
  166. {
  167. $aPost = array();
  168. foreach($GLOBALS['_POST'] as $sKey => $sValue)
  169. {
  170. if (is_string($sValue))
  171. {
  172. if (strlen($sValue) < 256)
  173. {
  174. $aPost[$sKey] = $sValue;
  175. }
  176. else
  177. {
  178. $aPost[$sKey] = "!long string: ".strlen($sValue). " chars";
  179. }
  180. }
  181. else
  182. {
  183. // Not a string
  184. $aPost[$sKey] = (string) $sValue;
  185. }
  186. }
  187. $this->Set('arguments_post', $aPost);
  188. }
  189. else
  190. {
  191. $this->Set('arguments_post', array());
  192. }
  193. $sLength = strlen($this->Get('issue'));
  194. if ($sLength > 255)
  195. {
  196. $this->Set('issue', substr($this->Get('issue'), 0, 200)." -truncated ($sLength chars)");
  197. }
  198. $sLength = strlen($this->Get('impact'));
  199. if ($sLength > 255)
  200. {
  201. $this->Set('impact', substr($this->Get('impact'), 0, 200)." -truncated ($sLength chars)");
  202. }
  203. $sLength = strlen($this->Get('page'));
  204. if ($sLength > 255)
  205. {
  206. $this->Set('page', substr($this->Get('page'), 0, 200)." -truncated ($sLength chars)");
  207. }
  208. }
  209. }
  210. class EventWebService extends Event
  211. {
  212. public static function Init()
  213. {
  214. $aParams = array
  215. (
  216. "category" => "core/cmdb",
  217. "key_type" => "autoincrement",
  218. "name_attcode" => "",
  219. "state_attcode" => "",
  220. "reconc_keys" => array(),
  221. "db_table" => "priv_event_webservice",
  222. "db_key_field" => "id",
  223. "db_finalclass_field" => "",
  224. "display_template" => "",
  225. );
  226. MetaModel::Init_Params($aParams);
  227. MetaModel::Init_InheritAttributes();
  228. MetaModel::Init_AddAttribute(new AttributeString("verb", array("allowed_values"=>null, "sql"=>"verb", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  229. //MetaModel::Init_AddAttribute(new AttributeStructure("arguments", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  230. MetaModel::Init_AddAttribute(new AttributeBoolean("result", array("allowed_values"=>null, "sql"=>"result", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  231. MetaModel::Init_AddAttribute(new AttributeText("log_info", array("allowed_values"=>null, "sql"=>"log_info", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  232. MetaModel::Init_AddAttribute(new AttributeText("log_warning", array("allowed_values"=>null, "sql"=>"log_warning", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  233. MetaModel::Init_AddAttribute(new AttributeText("log_error", array("allowed_values"=>null, "sql"=>"log_error", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  234. MetaModel::Init_AddAttribute(new AttributeText("data", array("allowed_values"=>null, "sql"=>"data", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
  235. // Display lists
  236. MetaModel::Init_SetZListItems('details', array('date', 'userinfo', 'verb', 'result', 'log_info', 'log_warning', 'log_error', 'data')); // Attributes to be displayed for the complete details
  237. MetaModel::Init_SetZListItems('list', array('date', 'userinfo', 'verb', 'result')); // Attributes to be displayed for a list
  238. // Search criteria
  239. // MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
  240. // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
  241. }
  242. }
  243. ?>