ConfigurationInstance.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Service_WindowsAzure
  17. * @subpackage Diagnostics
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. /**
  23. * @see Zend_Service_WindowsAzure_Diagnostics_Exception
  24. */
  25. require_once 'Zend/Service/WindowsAzure/Diagnostics/Exception.php';
  26. /**
  27. * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
  28. */
  29. require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationObjectBaseAbstract.php';
  30. /**
  31. * @see Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources
  32. */
  33. require_once 'Zend/Service/WindowsAzure/Diagnostics/ConfigurationDataSources.php';
  34. /**
  35. * @category Zend
  36. * @package Zend_Service_WindowsAzure
  37. * @subpackage Diagnostics
  38. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  39. * @license http://framework.zend.com/license/new-bsd New BSD License
  40. *
  41. * @property Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources DataSources Data sources
  42. */
  43. class Zend_Service_WindowsAzure_Diagnostics_ConfigurationInstance
  44. extends Zend_Service_WindowsAzure_Diagnostics_ConfigurationObjectBaseAbstract
  45. {
  46. /**
  47. * Constructor
  48. */
  49. public function __construct()
  50. {
  51. $this->_data = array(
  52. 'datasources' => new Zend_Service_WindowsAzure_Diagnostics_ConfigurationDataSources()
  53. );
  54. }
  55. /**
  56. * Load configuration XML
  57. *
  58. * @param string $configurationXml Configuration XML
  59. */
  60. public function loadXml($configurationXml)
  61. {
  62. // Convert to SimpleXMLElement
  63. $configurationXml = simplexml_load_string($configurationXml);
  64. // Assign general settings
  65. $this->DataSources->OverallQuotaInMB = (int)$configurationXml->DataSources->OverallQuotaInMB;
  66. // Assign Logs settings
  67. $this->DataSources->Logs->BufferQuotaInMB = (int)$configurationXml->DataSources->Logs->BufferQuotaInMB;
  68. $this->DataSources->Logs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Logs->ScheduledTransferPeriodInMinutes;
  69. $this->DataSources->Logs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->Logs->ScheduledTransferLogLevelFilter;
  70. // Assign DiagnosticInfrastructureLogs settings
  71. $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB;
  72. $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes;
  73. $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter;
  74. // Assign PerformanceCounters settings
  75. $this->DataSources->PerformanceCounters->BufferQuotaInMB = (int)$configurationXml->DataSources->PerformanceCounters->BufferQuotaInMB;
  76. $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes;
  77. if ($configurationXml->DataSources->PerformanceCounters->Subscriptions
  78. && $configurationXml->DataSources->PerformanceCounters->Subscriptions->PerformanceCounterConfiguration) {
  79. $subscriptions = $configurationXml->DataSources->PerformanceCounters->Subscriptions;
  80. if (count($subscriptions->PerformanceCounterConfiguration) > 1) {
  81. $subscriptions = $subscriptions->PerformanceCounterConfiguration;
  82. } else {
  83. $subscriptions = array($subscriptions->PerformanceCounterConfiguration);
  84. }
  85. foreach ($subscriptions as $subscription) {
  86. $this->DataSources->PerformanceCounters->addSubscription((string)$subscription->CounterSpecifier, (int)$subscription->SampleRateInSeconds);
  87. }
  88. }
  89. // Assign WindowsEventLog settings
  90. $this->DataSources->WindowsEventLog->BufferQuotaInMB = (int)$configurationXml->DataSources->WindowsEventLog->BufferQuotaInMB;
  91. $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes;
  92. $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter = (string)$configurationXml->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter;
  93. if ($configurationXml->DataSources->WindowsEventLog->Subscriptions
  94. && $configurationXml->DataSources->WindowsEventLog->Subscriptions->string) {
  95. $subscriptions = $configurationXml->DataSources->WindowsEventLog->Subscriptions;
  96. if (count($subscriptions->string) > 1) {
  97. $subscriptions = $subscriptions->string;
  98. } else {
  99. $subscriptions = array($subscriptions->string);
  100. }
  101. foreach ($subscriptions as $subscription) {
  102. $this->DataSources->WindowsEventLog->addSubscription((string)$subscription);
  103. }
  104. }
  105. // Assign Directories settings
  106. $this->DataSources->Directories->BufferQuotaInMB = (int)$configurationXml->DataSources->Directories->BufferQuotaInMB;
  107. $this->DataSources->Directories->ScheduledTransferPeriodInMinutes = (int)$configurationXml->DataSources->Directories->ScheduledTransferPeriodInMinutes;
  108. if ($configurationXml->DataSources->Directories->Subscriptions
  109. && $configurationXml->DataSources->Directories->Subscriptions->DirectoryConfiguration) {
  110. $subscriptions = $configurationXml->DataSources->WindowsEventLog->Subscriptions;
  111. if (count($subscriptions->DirectoryConfiguration) > 1) {
  112. $subscriptions = $subscriptions->DirectoryConfiguration;
  113. } else {
  114. $subscriptions = array($subscriptions->DirectoryConfiguration);
  115. }
  116. foreach ($subscriptions as $subscription) {
  117. $this->DataSources->Directories->addSubscription((string)$subscription->Path, (string)$subscription->Container, (int)$subscription->DirectoryQuotaInMB);
  118. }
  119. }
  120. }
  121. /**
  122. * Create configuration XML
  123. *
  124. * @return string
  125. */
  126. public function toXml()
  127. {
  128. // Return value
  129. $returnValue = array();
  130. // Build XML
  131. $returnValue[] = '<?xml version="1.0"?>';
  132. $returnValue[] = '<ConfigRequest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">';
  133. // Add data sources
  134. $returnValue[] = ' <DataSources>';
  135. $returnValue[] = ' <OverallQuotaInMB>' . $this->DataSources->OverallQuotaInMB . '</OverallQuotaInMB>';
  136. $returnValue[] = ' <Logs>';
  137. $returnValue[] = ' <BufferQuotaInMB>' . $this->DataSources->Logs->BufferQuotaInMB . '</BufferQuotaInMB>';
  138. $returnValue[] = ' <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Logs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
  139. $returnValue[] = ' <ScheduledTransferLogLevelFilter>' . $this->DataSources->Logs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
  140. $returnValue[] = ' </Logs>';
  141. $returnValue[] = ' <DiagnosticInfrastructureLogs>';
  142. $returnValue[] = ' <BufferQuotaInMB>' . $this->DataSources->DiagnosticInfrastructureLogs->BufferQuotaInMB . '</BufferQuotaInMB>';
  143. $returnValue[] = ' <ScheduledTransferPeriodInMinutes>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
  144. $returnValue[] = ' <ScheduledTransferLogLevelFilter>' . $this->DataSources->DiagnosticInfrastructureLogs->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
  145. $returnValue[] = ' </DiagnosticInfrastructureLogs>';
  146. $returnValue[] = ' <PerformanceCounters>';
  147. $returnValue[] = ' <BufferQuotaInMB>' . $this->DataSources->PerformanceCounters->BufferQuotaInMB . '</BufferQuotaInMB>';
  148. $returnValue[] = ' <ScheduledTransferPeriodInMinutes>' . $this->DataSources->PerformanceCounters->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
  149. if (count($this->DataSources->PerformanceCounters->Subscriptions) == 0) {
  150. $returnValue[] = ' <Subscriptions />';
  151. } else {
  152. $returnValue[] = ' <Subscriptions>';
  153. foreach ($this->DataSources->PerformanceCounters->Subscriptions as $subscription) {
  154. $returnValue[] = ' <PerformanceCounterConfiguration>';
  155. $returnValue[] = ' <CounterSpecifier>' . $subscription->CounterSpecifier . '</CounterSpecifier>';
  156. $returnValue[] = ' <SampleRateInSeconds>' . $subscription->SampleRateInSeconds . '</SampleRateInSeconds>';
  157. $returnValue[] = ' </PerformanceCounterConfiguration>';
  158. }
  159. $returnValue[] = ' </Subscriptions>';
  160. }
  161. $returnValue[] = ' </PerformanceCounters>';
  162. $returnValue[] = ' <WindowsEventLog>';
  163. $returnValue[] = ' <BufferQuotaInMB>' . $this->DataSources->WindowsEventLog->BufferQuotaInMB . '</BufferQuotaInMB>';
  164. $returnValue[] = ' <ScheduledTransferPeriodInMinutes>' . $this->DataSources->WindowsEventLog->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
  165. if (count($this->DataSources->WindowsEventLog->Subscriptions) == 0) {
  166. $returnValue[] = ' <Subscriptions />';
  167. } else {
  168. $returnValue[] = ' <Subscriptions>';
  169. foreach ($this->DataSources->WindowsEventLog->Subscriptions as $subscription) {
  170. $returnValue[] = ' <string>' . $subscription . '</string>';
  171. }
  172. $returnValue[] = ' </Subscriptions>';
  173. }
  174. $returnValue[] = ' <ScheduledTransferLogLevelFilter>' . $this->DataSources->WindowsEventLog->ScheduledTransferLogLevelFilter . '</ScheduledTransferLogLevelFilter>';
  175. $returnValue[] = ' </WindowsEventLog>';
  176. $returnValue[] = ' <Directories>';
  177. $returnValue[] = ' <BufferQuotaInMB>' . $this->DataSources->Directories->BufferQuotaInMB . '</BufferQuotaInMB>';
  178. $returnValue[] = ' <ScheduledTransferPeriodInMinutes>' . $this->DataSources->Directories->ScheduledTransferPeriodInMinutes . '</ScheduledTransferPeriodInMinutes>';
  179. if (count($this->DataSources->Directories->Subscriptions) == 0) {
  180. $returnValue[] = ' <Subscriptions />';
  181. } else {
  182. $returnValue[] = ' <Subscriptions>';
  183. foreach ($this->DataSources->Directories->Subscriptions as $subscription) {
  184. $returnValue[] = ' <DirectoryConfiguration>';
  185. $returnValue[] = ' <Path>' . $subscription->Path . '</Path>';
  186. $returnValue[] = ' <Container>' . $subscription->Container . '</Container>';
  187. $returnValue[] = ' <DirectoryQuotaInMB>' . $subscription->DirectoryQuotaInMB . '</DirectoryQuotaInMB>';
  188. $returnValue[] = ' </DirectoryConfiguration>';
  189. }
  190. $returnValue[] = ' </Subscriptions>';
  191. }
  192. $returnValue[] = ' </Directories>';
  193. $returnValue[] = ' </DataSources>';
  194. $returnValue[] = '</ConfigRequest>';
  195. // Return
  196. return implode("\r\n", $returnValue);
  197. }
  198. }