glpi / src / plugins / vigilo / inc / monitoredcomputer.class.php @ 2fd8023e
History | View | Annotate | Download (5.41 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
class PluginVigiloMonitoredComputer extends PluginVigiloAbstractMonitoredItem |
4 |
{ |
5 |
protected static $softwares = null; |
6 |
|
7 |
public function __construct(CommonDBTM $item) |
8 |
{ |
9 |
if (null === static::$softwares) { |
10 |
// Chargement et validation de la liste des logiciels
|
11 |
// supervisés automatiquement.
|
12 |
$mapping = plugin_vigilo_getSoftwareMapping();
|
13 |
$softwares = array(); |
14 |
foreach ($mapping as $name => $test) { |
15 |
// Cas d'un test sans paramètres explicites.
|
16 |
if (1 === count($test)) { |
17 |
$test[] = array(); |
18 |
} |
19 |
|
20 |
if (2 !== count($test) || !is_array($test[1])) { |
21 |
Toolbox::logDebug("Invalid test definition for '$name'"); |
22 |
} else {
|
23 |
$softwares[$name] = $test; |
24 |
} |
25 |
} |
26 |
static::$softwares = $softwares; |
27 |
} |
28 |
|
29 |
parent::__construct($item); |
30 |
$this->monitorMemory();
|
31 |
$this->monitorPartitions();
|
32 |
$this->monitorSoftwares();
|
33 |
} |
34 |
|
35 |
protected function monitorMemory() |
36 |
{ |
37 |
global $DB; |
38 |
|
39 |
$total = 0; |
40 |
$query = Item_DeviceMemory::getSQLRequestToSearchForItem( |
41 |
$this->item->getType(), |
42 |
$this->item->getID()
|
43 |
); |
44 |
|
45 |
foreach ($DB->query($query) as $mem) { |
46 |
$memory = new Item_DeviceMemory(); |
47 |
$memory->getFromDB($mem['id']); |
48 |
$total += $memory->fields['size'] * 1024 * 1024; |
49 |
} |
50 |
|
51 |
if ($total > 0) { |
52 |
$this->children[] = new VigiloTest('RAM'); |
53 |
} |
54 |
} |
55 |
|
56 |
protected function monitorPartitions() |
57 |
{ |
58 |
global $DB; |
59 |
|
60 |
$query = ComputerDisk::getSQLRequestToSearchForItem( |
61 |
$this->item->getType(), |
62 |
$this->item->getID()
|
63 |
); |
64 |
|
65 |
foreach ($DB->query($query) as $cd) { |
66 |
$disk = new ComputerDisk(); |
67 |
$disk->getFromDB($cd['id']); |
68 |
$total = $disk->fields['totalsize']; |
69 |
|
70 |
$this->children[] =
|
71 |
$test = new VigiloTest('Partition'); |
72 |
|
73 |
// On supprime les éventuels / ou \ finaux (p.ex. "C:\").
|
74 |
$mountpoint = rtrim($disk->fields['mountpoint'], '/\\'); |
75 |
$mountpoint = self::escapeRegex($mountpoint); |
76 |
|
77 |
// Si présence d'un ":", il s'agit probablement d'un volume Windows.
|
78 |
// On ajoute "\\.*" pour matcher le label éventuellement associé.
|
79 |
if (false !== strpos($mountpoint, ':')) { |
80 |
$mountpoint .= '\\\\.*'; |
81 |
} |
82 |
|
83 |
$test['partname'] = $mountpoint; |
84 |
$test['label'] = $disk->getName(); |
85 |
if (!empty($total)) { |
86 |
$test[] = new VigiloArg('max', $total * 1024 * 1024); |
87 |
} |
88 |
} |
89 |
} |
90 |
|
91 |
protected function monitorSoftwares() |
92 |
{ |
93 |
$installations = new Computer_SoftwareVersion(); |
94 |
$installations = $installations->find('computers_id=' . $this->item->getID()); |
95 |
foreach ($installations as $installation) { |
96 |
if (!$installation['softwareversions_id']) { |
97 |
continue;
|
98 |
} |
99 |
|
100 |
$versions = new SoftwareVersion(); |
101 |
$versions = $versions->find('id=' . $installation['softwareversions_id']); |
102 |
foreach ($versions as $version) { |
103 |
if (!$version['softwares_id']) { |
104 |
continue;
|
105 |
} |
106 |
|
107 |
$software = new Software(); |
108 |
$software->getFromDB($version['softwares_id']); |
109 |
$lcname = strtolower($software->getName()); |
110 |
if (isset(static::$softwares[$lcname])) { |
111 |
// Gestion des logiciels supervisés automatiquement.
|
112 |
list($testName, $testArgs) = static::$softwares[$lcname]; |
113 |
$this->children[] = new VigiloTest($testName, $testArgs); |
114 |
} elseif (!strncmp($lcname, 'vigilo-test-', 12)) { |
115 |
// Gestion des "faux logiciels".
|
116 |
$parts = explode('-', $software->getName(), 4); |
117 |
if (count($parts) < 3) { |
118 |
continue;
|
119 |
} |
120 |
|
121 |
$type = ucfirst(strtolower($parts[2])); |
122 |
$args = isset($parts[3]) ? $parts[3] : null; |
123 |
$method = 'monitorCustom' . $type; |
124 |
if (method_exists($this, $method)) { |
125 |
$this->$method($software, $args); |
126 |
} |
127 |
} |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
protected function monitorCustomService($software, $service) |
133 |
{ |
134 |
if (!$service) { |
135 |
return;
|
136 |
} |
137 |
|
138 |
$this->children[] = new VigiloTest('Service', array('svcname' => $service)); |
139 |
} |
140 |
|
141 |
protected function monitorCustomTcp($software, $port) |
142 |
{ |
143 |
if (!$port) { |
144 |
return;
|
145 |
} |
146 |
|
147 |
$port = (int) $port; |
148 |
if ($port > 0 && $port <= 65535) { |
149 |
$this->children[] = new Vigilotest('TCP', array('port' => $port)); |
150 |
} |
151 |
} |
152 |
|
153 |
protected function monitorCustomProcess($software, $process) |
154 |
{ |
155 |
if (!$process) { |
156 |
return;
|
157 |
} |
158 |
|
159 |
$this->children[] = new VigiloTest('Process', array('processname' => $process)); |
160 |
} |
161 |
|
162 |
protected function monitorCustomSwap($software, $dummy) |
163 |
{ |
164 |
$this->children[] = new VigiloTest('Swap'); |
165 |
} |
166 |
|
167 |
protected function monitorCustomPing($software, $dummy) |
168 |
{ |
169 |
$this->children[] = new VigiloTest('Ping'); |
170 |
} |
171 |
} |