glpi / Vigilo / VigiloHost.php @ 0d761a49
History | View | Annotate | Download (8.95 KB)
1 | bef4271a | Thibault Louet | <?php
|
---|---|---|---|
2 | |||
3 | class VigiloHost extends VigiloXml |
||
4 | { |
||
5 | protected $computer; |
||
6 | protected $addresses; |
||
7 | protected $ventilation; |
||
8 | protected $children; |
||
9 | protected $agent; |
||
10 | |||
11 | public function __construct($computer) |
||
12 | { |
||
13 | $this->agent = null; |
||
14 | $this->ventilation = "Servers"; |
||
15 | $this->computer = $computer; |
||
16 | $this->addresses = array(); |
||
17 | $this->children = array(); |
||
18 | |||
19 | if (class_exists('PluginFusioninventoryAgent')) { |
||
20 | $agent = new PluginFusioninventoryAgent(); |
||
21 | a5c9df40 | Thibault Louet | if ($agent->getAgentWithComputerid($this->computer->getID()) !== false) { |
22 | bef4271a | Thibault Louet | $this->agent = $agent; |
23 | a5c9df40 | Thibault Louet | } |
24 | bef4271a | Thibault Louet | } |
25 | |||
26 | $this->selectTemplates();
|
||
27 | $this->selectGroups();
|
||
28 | $this->monitorMemory();
|
||
29 | $this->monitorNetworkInterfaces();
|
||
30 | $this->monitorSoftwares();
|
||
31 | $this->monitorPartitions();
|
||
32 | } |
||
33 | |||
34 | public function getName() |
||
35 | { |
||
36 | return $this->computer->getName(); |
||
37 | } |
||
38 | |||
39 | protected function selectTemplates() |
||
40 | { |
||
41 | 0e0753c8 | Romain CHOLLET | $template_name = $this->computer->getField("template_name"); |
42 | |||
43 | if ($template_name && $template_name !== "N/A") { |
||
44 | a5c9df40 | Thibault Louet | $this->children[] = new VigiloHostTemplate($this->computer->getField("template_name")); |
45 | } |
||
46 | 2ef80588 | Romain CHOLLET | /*$refs = array(
|
47 | bef4271a | Thibault Louet | "glpi_operatingsystems" => "operatingsystems_id",
|
48 | "glpi_operatingsystemversions" => "operatingsystemversions_id",
|
||
49 | "glpi_operatingsystemservicepacks" => "operatingsystemservicepacks_id",
|
||
50 | );
|
||
51 | |||
52 | $model = array();
|
||
53 | foreach ($refs as $table => $field) {
|
||
54 | $id = $this->computer->fields[$field];
|
||
55 | $value = Dropdown::getDropdownName($table, $id);
|
||
56 | a5c9df40 | Thibault Louet | if ($value !== "" && $value !== null && $value !== " "
|
57 | 0e0753c8 | Romain CHOLLET | && $value !== false && $value !== "-----" && $value !== 'N/A'
|
58 | a5c9df40 | Thibault Louet | ) {
|
59 | bef4271a | Thibault Louet | $model[] = $value;
|
60 | }
|
||
61 | }
|
||
62 | |||
63 | a5c9df40 | Thibault Louet | if (!count($model)) {
|
64 | bef4271a | Thibault Louet | $model = "default";
|
65 | a5c9df40 | Thibault Louet | } else {
|
66 | bef4271a | Thibault Louet | $model = implode(" - ", $model);
|
67 | a5c9df40 | Thibault Louet | }
|
68 | bef4271a | Thibault Louet | |
69 | 2ef80588 | Romain CHOLLET | $this->children[] = new VigiloHostTemplate($model);*/
|
70 | 0d761a49 | Romain CHOLLET | |
71 | 2ef80588 | Romain CHOLLET | |
72 | $template_number = $this->computer->getField("vigilo_template"); |
||
73 | 0d761a49 | Romain CHOLLET | if ($template_number !== '0' && $template_number !== 'N/A') { |
74 | 2ef80588 | Romain CHOLLET | $common_dbtm = new CommonDBTM(); |
75 | 0d761a49 | Romain CHOLLET | $template_name = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($template_number); |
76 | $this->children[] = new VigiloHostTemplate($template_name); |
||
77 | 2ef80588 | Romain CHOLLET | } |
78 | else {
|
||
79 | 0d761a49 | Romain CHOLLET | if (empty($this->children)) { |
80 | $template_name = "default"; |
||
81 | $this->children[] = new VigiloHostTemplate($template_name); |
||
82 | } |
||
83 | 2ef80588 | Romain CHOLLET | } |
84 | bef4271a | Thibault Louet | } |
85 | |||
86 | protected function selectGroups() |
||
87 | { |
||
88 | $location = new Location(); |
||
89 | $location->getFromDB($this->computer->fields["locations_id"]); |
||
90 | a5c9df40 | Thibault Louet | if (!($location->getName()=='N/A')) { |
91 | $locationCompleteName=explode(" > ", $location->getField("completename")); |
||
92 | 0e0753c8 | Romain CHOLLET | $locationRealName=implode("/", $locationCompleteName); |
93 | a5c9df40 | Thibault Louet | $this->children[] = new VigiloGroup($locationRealName); |
94 | } |
||
95 | bef4271a | Thibault Louet | |
96 | a5c9df40 | Thibault Louet | $entity = new Entity(); |
97 | $entity->getFromDB($this->computer->fields["entities_id"]); |
||
98 | if (!($entity->getName()=='N/A')) { |
||
99 | $entityCompleteName=explode(" > ", $entity->getField("completename")); |
||
100 | 0e0753c8 | Romain CHOLLET | $entityRealName=implode("/", $entityCompleteName); |
101 | a5c9df40 | Thibault Louet | $this->children[] = new VigiloGroup($entityRealName); |
102 | } |
||
103 | bef4271a | Thibault Louet | |
104 | a5c9df40 | Thibault Louet | $manufacturer = new Manufacturer(); |
105 | $manufacturer->getFromDB($this->computer->fields["manufacturers_id"]); |
||
106 | if (!($manufacturer->getName()=='N/A')) { |
||
107 | $this->children[] = new VigiloGroup($manufacturer->getName()); |
||
108 | } |
||
109 | bef4271a | Thibault Louet | } |
110 | |||
111 | protected function selectAddress() |
||
112 | { |
||
113 | static $address = null; |
||
114 | |||
115 | if ($address === null && $this->agent) { |
||
116 | $addresses = $this->agent->getIPs(); |
||
117 | a5c9df40 | Thibault Louet | if (count($addresses)) { |
118 | bef4271a | Thibault Louet | $address = current($addresses); |
119 | a5c9df40 | Thibault Louet | } |
120 | bef4271a | Thibault Louet | } |
121 | |||
122 | if ($address === null) { |
||
123 | $address = $this->computer->getName(); |
||
124 | foreach ($this->addresses as $addr) { |
||
125 | a5c9df40 | Thibault Louet | if (!$addr->is_ipv4()) { |
126 | bef4271a | Thibault Louet | continue;
|
127 | a5c9df40 | Thibault Louet | } |
128 | bef4271a | Thibault Louet | |
129 | $textual = $addr->getTextual(); |
||
130 | if (is_string($textual)) { |
||
131 | $address = $textual; |
||
132 | break;
|
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | |||
137 | return $address; |
||
138 | } |
||
139 | |||
140 | protected function monitorMemory() |
||
141 | { |
||
142 | global $DB; |
||
143 | |||
144 | $total = 0; |
||
145 | $query = Item_DeviceMemory::getSQLRequestToSearchForItem( |
||
146 | $this->computer->getType(), |
||
147 | $this->computer->getID()
|
||
148 | ); |
||
149 | |||
150 | foreach ($DB->query($query) as $mem) { |
||
151 | $memory = new Item_DeviceMemory(); |
||
152 | $memory->getFromDB($mem['id']); |
||
153 | $total += $memory->fields['size'] * 1024 * 1024; |
||
154 | } |
||
155 | |||
156 | a5c9df40 | Thibault Louet | if ($total > 0) { |
157 | bef4271a | Thibault Louet | $this->children[] = new VigiloTest('RAM'); |
158 | a5c9df40 | Thibault Louet | } |
159 | bef4271a | Thibault Louet | } |
160 | |||
161 | protected function monitorNetworkInterfaces() |
||
162 | { |
||
163 | global $DB; |
||
164 | $query = NetworkPort::getSQLRequestToSearchForItem( |
||
165 | $this->computer->getType(), |
||
166 | $this->computer->getID()
|
||
167 | ); |
||
168 | |||
169 | foreach ($DB->query($query) as $np) { |
||
170 | $query2 = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']); |
||
171 | $port = new NetworkPort(); |
||
172 | a5c9df40 | Thibault Louet | $ethport = new NetworkPortEthernet(); |
173 | bef4271a | Thibault Louet | $port->getFromDB($np['id']); |
174 | a5c9df40 | Thibault Louet | if ($port->getName() == 'lo') { |
175 | bef4271a | Thibault Louet | continue;
|
176 | a5c9df40 | Thibault Louet | } |
177 | bef4271a | Thibault Louet | |
178 | $args = array(); |
||
179 | $label = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName(); |
||
180 | a5c9df40 | Thibault Louet | $ethport = $ethport->find('networkports_id=' . $np['id']); |
181 | foreach ($ethport as $rowEthPort) { |
||
182 | if ($rowEthPort['speed']) { |
||
183 | $args[] = new VigiloArg('max', $rowEthPort['speed']); |
||
184 | break;
|
||
185 | } |
||
186 | } |
||
187 | bef4271a | Thibault Louet | $args[] = new VigiloArg('label', $label); |
188 | a5c9df40 | Thibault Louet | $args[] = new VigiloArg('ifname', $port->getName()); |
189 | bef4271a | Thibault Louet | $this->children[] = new VigiloTest('Interface', $args); |
190 | |||
191 | // Retrieve all IP addresses associated with this interface.
|
||
192 | // This will be used later in selectAddress() to select
|
||
193 | // the most appropriate IP address to query this computer.
|
||
194 | foreach ($DB->query($query2) as $nn) { |
||
195 | $query3 = IPAddress::getSQLRequestToSearchForItem("NetworkName", $nn['id']); |
||
196 | foreach ($DB->query($query3) as $ip) { |
||
197 | $addr = new IPAddress(); |
||
198 | a5c9df40 | Thibault Louet | if ($addr->getFromDB($ip['id'])) { |
199 | bef4271a | Thibault Louet | $this->addresses[] = $addr; |
200 | a5c9df40 | Thibault Louet | } |
201 | bef4271a | Thibault Louet | } |
202 | } |
||
203 | } |
||
204 | } |
||
205 | |||
206 | protected function monitorSoftwares() |
||
207 | { |
||
208 | a5c9df40 | Thibault Louet | global $DB; |
209 | $listOfTest=new VigiloTestSoftware($this->computer); |
||
210 | $computerSoftwareVersion=new Computer_SoftwareVersion(); |
||
211 | $ids=$computerSoftwareVersion->find('computers_id=' . $this->computer->getID()); |
||
212 | foreach ($ids as $id) { |
||
213 | if ($id['softwareversions_id']) { |
||
214 | $softwareVersion=new SoftwareVersion(); |
||
215 | $ids2=$softwareVersion->find('id=' . $id['softwareversions_id']); |
||
216 | foreach ($ids2 as $id2) { |
||
217 | if ($id2['softwares_id']) { |
||
218 | $software=new Software(); |
||
219 | $software->getFromDB($id2['softwares_id']); |
||
220 | $listOfTest->addRelevantTestWith($software->getName()); |
||
221 | } |
||
222 | } |
||
223 | } |
||
224 | } |
||
225 | foreach ($listOfTest->getTable() as $test) { |
||
226 | $this->children[]=$test; |
||
227 | } |
||
228 | bef4271a | Thibault Louet | } |
229 | |||
230 | protected function monitorPartitions() |
||
231 | { |
||
232 | global $DB; |
||
233 | |||
234 | $query = ComputerDisk::getSQLRequestToSearchForItem( |
||
235 | $this->computer->getType(), |
||
236 | $this->computer->getID()
|
||
237 | ); |
||
238 | |||
239 | foreach ($DB->query($query) as $cd) { |
||
240 | $disk = new ComputerDisk(); |
||
241 | $disk->getFromDB($cd['id']); |
||
242 | |||
243 | $args = array(); |
||
244 | $args[] = new VigiloArg('label', $disk->getName()); |
||
245 | $args[] = new VigiloArg('partname', $disk->fields['mountpoint']); |
||
246 | $total = $disk->fields['totalsize']; |
||
247 | a5c9df40 | Thibault Louet | if (!empty($total)) { |
248 | bef4271a | Thibault Louet | $args[] = new VigiloArg('max', $total * 1024 * 1024); |
249 | a5c9df40 | Thibault Louet | } |
250 | bef4271a | Thibault Louet | $this->children[] = new VigiloTest('Partition', $args); |
251 | } |
||
252 | } |
||
253 | |||
254 | public function __toString() |
||
255 | { |
||
256 | $outXML=new DOMdocument(); |
||
257 | a5c9df40 | Thibault Louet | $outXML->preserveWhiteSpace=false; |
258 | $outXML->formatOutput=true; |
||
259 | $outXML->loadXML(
|
||
260 | self::sprintf( |
||
261 | '<?xml version="1.0"?>' .
|
||
262 | '<host name="%s" address="%s" ventilation="%s">%s</host>',
|
||
263 | $this->computer->getName(),
|
||
264 | $this->selectAddress(),
|
||
265 | "Servers",
|
||
266 | $this->children
|
||
267 | ) |
||
268 | ); |
||
269 | return $outXML->saveXML(); |
||
270 | bef4271a | Thibault Louet | } |
271 | a5c9df40 | Thibault Louet | } |