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