webservices.basic.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. * Implementation of iTop SOAP services
  18. *
  19. * @author Erwan Taloc <erwan.taloc@combodo.com>
  20. * @author Romain Quetiez <romain.quetiez@combodo.com>
  21. * @author Denis Flaven <denis.flaven@combodo.com>
  22. * @license http://www.opensource.org/licenses/gpl-3.0.html LGPL
  23. */
  24. require_once(APPROOT.'/webservices/webservices.class.inc.php');
  25. class BasicServices extends WebServicesBase
  26. {
  27. static protected function GetWSDLFilePath()
  28. {
  29. return APPROOT.'/webservices/itop.wsdl.tpl';
  30. }
  31. /**
  32. * Get the server version (TODO: get it dynamically, where ?)
  33. *
  34. * @return WebServiceResult
  35. */
  36. static public function GetVersion()
  37. {
  38. if (ITOP_REVISION == '$WCREV$')
  39. {
  40. $sVersionString = ITOP_VERSION.' [dev]';
  41. }
  42. else
  43. {
  44. // This is a build made from SVN, let display the full information
  45. $sVersionString = ITOP_VERSION."-".ITOP_REVISION." ".ITOP_BUILD_DATE;
  46. }
  47. return $sVersionString;
  48. }
  49. public function CreateIncidentTicket($sLogin, $sPassword, $sTitle, $sDescription, $oCallerDesc, $oCustomerDesc, $oServiceDesc, $oServiceSubcategoryDesc, $sProduct, $oWorkgroupDesc, $aSOAPImpactedCIs, $sImpact, $sUrgency)
  50. {
  51. if (!UserRights::CheckCredentials($sLogin, $sPassword))
  52. {
  53. $oRes = new WebServiceResultFailedLogin($sLogin);
  54. $this->LogUsage(__FUNCTION__, $oRes);
  55. return $oRes->ToSoapStructure();
  56. }
  57. UserRights::Login($sLogin);
  58. $aCallerDesc = self::SoapStructToExternalKeySearch($oCallerDesc);
  59. $aCustomerDesc = self::SoapStructToExternalKeySearch($oCustomerDesc);
  60. $aServiceDesc = self::SoapStructToExternalKeySearch($oServiceDesc);
  61. $aServiceSubcategoryDesc = self::SoapStructToExternalKeySearch($oServiceSubcategoryDesc);
  62. $aWorkgroupDesc = self::SoapStructToExternalKeySearch($oWorkgroupDesc);
  63. $aImpactedCIs = array();
  64. if (is_null($aSOAPImpactedCIs)) $aSOAPImpactedCIs = array();
  65. foreach($aSOAPImpactedCIs as $oImpactedCIs)
  66. {
  67. $aImpactedCIs[] = self::SoapStructToLinkCreationSpec($oImpactedCIs);
  68. }
  69. $oRes = $this->_CreateIncidentTicket
  70. (
  71. $sTitle,
  72. $sDescription,
  73. $aCallerDesc,
  74. $aCustomerDesc,
  75. $aServiceDesc,
  76. $aServiceSubcategoryDesc,
  77. $sProduct,
  78. $aWorkgroupDesc,
  79. $aImpactedCIs,
  80. $sImpact,
  81. $sUrgency
  82. );
  83. return $oRes->ToSoapStructure();
  84. }
  85. /**
  86. * Create an incident ticket from a monitoring system
  87. * Some CIs might be specified (by their name/IP)
  88. *
  89. * @param string sTitle
  90. * @param string sDescription
  91. * @param array aCallerDesc
  92. * @param array aCustomerDesc
  93. * @param array aServiceDesc
  94. * @param array aServiceSubcategoryDesc
  95. * @param string sProduct
  96. * @param array aWorkgroupDesc
  97. * @param array aImpactedCIs
  98. * @param string sImpact
  99. * @param string sUrgency
  100. *
  101. * @return WebServiceResult
  102. */
  103. protected function _CreateIncidentTicket($sTitle, $sDescription, $aCallerDesc, $aCustomerDesc, $aServiceDesc, $aServiceSubcategoryDesc, $sProduct, $aWorkgroupDesc, $aImpactedCIs, $sImpact, $sUrgency)
  104. {
  105. $oRes = new WebServiceResult();
  106. try
  107. {
  108. $oMyChange = MetaModel::NewObject("CMDBChange");
  109. $oMyChange->Set("date", time());
  110. $oMyChange->Set("userinfo", "Administrator");
  111. $iChangeId = $oMyChange->DBInsertNoReload();
  112. $oNewTicket = MetaModel::NewObject('Incident');
  113. $this->MyObjectSetScalar('title', 'title', $sTitle, $oNewTicket, $oRes);
  114. $this->MyObjectSetScalar('description', 'description', $sDescription, $oNewTicket, $oRes);
  115. $this->MyObjectSetExternalKey('org_id', 'customer', $aCustomerDesc, $oNewTicket, $oRes);
  116. $this->MyObjectSetExternalKey('caller_id', 'caller', $aCallerDesc, $oNewTicket, $oRes);
  117. $this->MyObjectSetExternalKey('service_id', 'service', $aServiceDesc, $oNewTicket, $oRes);
  118. if (!array_key_exists('service_id', $aServiceSubcategoryDesc))
  119. {
  120. $aServiceSubcategoryDesc['service_id'] = $oNewTicket->Get('service_id');
  121. }
  122. $this->MyObjectSetExternalKey('servicesubcategory_id', 'servicesubcategory', $aServiceSubcategoryDesc, $oNewTicket, $oRes);
  123. $this->MyObjectSetScalar('product', 'product', $sProduct, $oNewTicket, $oRes);
  124. $this->MyObjectSetExternalKey('workgroup_id', 'workgroup', $aWorkgroupDesc, $oNewTicket, $oRes);
  125. $aDevicesNotFound = $this->AddLinkedObjects('ci_list', 'impacted_cis', 'FunctionalCI', $aImpactedCIs, $oNewTicket, $oRes);
  126. if (count($aDevicesNotFound) > 0)
  127. {
  128. $this->MyObjectSetScalar('description', 'n/a', $sDescription.' - Related CIs: '.implode(', ', $aDevicesNotFound), $oNewTicket, $oRes);
  129. }
  130. else
  131. {
  132. $this->MyObjectSetScalar('description', 'n/a', $sDescription, $oNewTicket, $oRes);
  133. }
  134. $this->MyObjectSetScalar('impact', 'impact', $sImpact, $oNewTicket, $oRes);
  135. $this->MyObjectSetScalar('urgency', 'urgency', $sUrgency, $oNewTicket, $oRes);
  136. $this->MyObjectInsert($oNewTicket, 'created', $oMyChange, $oRes);
  137. }
  138. catch (CoreException $e)
  139. {
  140. $oRes->LogError($e->getMessage());
  141. }
  142. catch (Exception $e)
  143. {
  144. $oRes->LogError($e->getMessage());
  145. }
  146. $this->LogUsage(__FUNCTION__, $oRes);
  147. return $oRes;
  148. }
  149. /**
  150. * Given an OQL, returns a set of objects (several objects could be on the same row)
  151. *
  152. * @param string sOQL
  153. */
  154. public function SearchObjects($sLogin, $sPassword, $sOQL)
  155. {
  156. if (!UserRights::CheckCredentials($sLogin, $sPassword))
  157. {
  158. $oRes = new WebServiceResultFailedLogin($sLogin);
  159. $this->LogUsage(__FUNCTION__, $oRes);
  160. return $oRes->ToSoapStructure();
  161. }
  162. UserRights::Login($sLogin);
  163. $oRes = $this->_SearchObjects($sOQL);
  164. return $oRes->ToSoapStructure();
  165. }
  166. protected function _SearchObjects($sOQL)
  167. {
  168. $oRes = new WebServiceResult();
  169. try
  170. {
  171. $oSearch = DBObjectSearch::FromOQL($sOQL);
  172. $oSet = new DBObjectSet($oSearch);
  173. $aData = $oSet->ToArrayOfValues();
  174. foreach($aData as $iRow => $aRow)
  175. {
  176. $oRes->AddResultRow("row_$iRow", $aRow);
  177. }
  178. }
  179. catch (CoreException $e)
  180. {
  181. $oRes->LogError($e->getMessage());
  182. }
  183. catch (Exception $e)
  184. {
  185. $oRes->LogError($e->getMessage());
  186. }
  187. $this->LogUsage(__FUNCTION__, $oRes);
  188. return $oRes;
  189. }
  190. }
  191. ?>