glpi / src / plugins / vigilo / inc / monitoredcomputer.class.php @ 945f4815
History | View | Annotate | Download (5.59 KB)
1 | 166be9d2 | Francois POIROTTE | <?php
|
---|---|---|---|
2 | |||
3 | class PluginVigiloMonitoredComputer extends PluginVigiloAbstractMonitoredItem |
||
4 | { |
||
5 | protected static $softwares = null; |
||
6 | |||
7 | public function __construct(CommonDBTM $item) |
||
8 | { |
||
9 | cdde5484 | Francois POIROTTE | if (null === static::$softwares) { |
10 | 166be9d2 | Francois POIROTTE | // 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 | cdde5484 | Francois POIROTTE | static::$softwares = $softwares; |
27 | 166be9d2 | Francois POIROTTE | } |
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 | 3bebddc7 | Francois POIROTTE | if ('' === $disk->fields['mountpoint']) { |
71 | continue;
|
||
72 | } |
||
73 | |||
74 | 166be9d2 | Francois POIROTTE | $this->children[] =
|
75 | $test = new VigiloTest('Partition'); |
||
76 | c24d7938 | Francois POIROTTE | |
77 | // On supprime les éventuels / ou \ finaux (p.ex. "C:\").
|
||
78 | $mountpoint = rtrim($disk->fields['mountpoint'], '/\\'); |
||
79 | 3bebddc7 | Francois POIROTTE | if ('' === $mountpoint) { |
80 | $mountpoint = '/'; |
||
81 | } |
||
82 | c24d7938 | Francois POIROTTE | $mountpoint = self::escapeRegex($mountpoint); |
83 | |||
84 | // Si présence d'un ":", il s'agit probablement d'un volume Windows.
|
||
85 | // On ajoute "\\.*" pour matcher le label éventuellement associé.
|
||
86 | if (false !== strpos($mountpoint, ':')) { |
||
87 | $mountpoint .= '\\\\.*'; |
||
88 | } |
||
89 | |||
90 | $test['partname'] = $mountpoint; |
||
91 | 166be9d2 | Francois POIROTTE | $test['label'] = $disk->getName(); |
92 | if (!empty($total)) { |
||
93 | $test[] = new VigiloArg('max', $total * 1024 * 1024); |
||
94 | } |
||
95 | } |
||
96 | } |
||
97 | |||
98 | protected function monitorSoftwares() |
||
99 | { |
||
100 | c60a37ae | Francois POIROTTE | $installations = new Computer_SoftwareVersion(); |
101 | $installations = $installations->find('computers_id=' . $this->item->getID()); |
||
102 | foreach ($installations as $installation) { |
||
103 | if (!$installation['softwareversions_id']) { |
||
104 | 166be9d2 | Francois POIROTTE | continue;
|
105 | } |
||
106 | |||
107 | c60a37ae | Francois POIROTTE | $versions = new SoftwareVersion(); |
108 | $versions = $versions->find('id=' . $installation['softwareversions_id']); |
||
109 | foreach ($versions as $version) { |
||
110 | if (!$version['softwares_id']) { |
||
111 | 166be9d2 | Francois POIROTTE | continue;
|
112 | } |
||
113 | |||
114 | $software = new Software(); |
||
115 | c60a37ae | Francois POIROTTE | $software->getFromDB($version['softwares_id']); |
116 | 166be9d2 | Francois POIROTTE | $lcname = strtolower($software->getName()); |
117 | if (isset(static::$softwares[$lcname])) { |
||
118 | // Gestion des logiciels supervisés automatiquement.
|
||
119 | cdde5484 | Francois POIROTTE | list($testName, $testArgs) = static::$softwares[$lcname]; |
120 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest($testName, $testArgs); |
121 | } elseif (!strncmp($lcname, 'vigilo-test-', 12)) { |
||
122 | // Gestion des "faux logiciels".
|
||
123 | $parts = explode('-', $software->getName(), 4); |
||
124 | if (count($parts) < 3) { |
||
125 | continue;
|
||
126 | } |
||
127 | |||
128 | c60a37ae | Francois POIROTTE | $type = ucfirst(strtolower($parts[2])); |
129 | $args = isset($parts[3]) ? $parts[3] : null; |
||
130 | 166be9d2 | Francois POIROTTE | $method = 'monitorCustom' . $type; |
131 | if (method_exists($this, $method)) { |
||
132 | $this->$method($software, $args); |
||
133 | } |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | protected function monitorCustomService($software, $service) |
||
140 | { |
||
141 | c60a37ae | Francois POIROTTE | if (!$service) { |
142 | return;
|
||
143 | } |
||
144 | |||
145 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest('Service', array('svcname' => $service)); |
146 | } |
||
147 | |||
148 | protected function monitorCustomTcp($software, $port) |
||
149 | { |
||
150 | c60a37ae | Francois POIROTTE | if (!$port) { |
151 | return;
|
||
152 | } |
||
153 | |||
154 | 166be9d2 | Francois POIROTTE | $port = (int) $port; |
155 | if ($port > 0 && $port <= 65535) { |
||
156 | cdde5484 | Francois POIROTTE | $this->children[] = new Vigilotest('TCP', array('port' => $port)); |
157 | 166be9d2 | Francois POIROTTE | } |
158 | } |
||
159 | |||
160 | protected function monitorCustomProcess($software, $process) |
||
161 | { |
||
162 | c60a37ae | Francois POIROTTE | if (!$process) { |
163 | return;
|
||
164 | } |
||
165 | |||
166 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest('Process', array('processname' => $process)); |
167 | } |
||
168 | |||
169 | protected function monitorCustomSwap($software, $dummy) |
||
170 | { |
||
171 | $this->children[] = new VigiloTest('Swap'); |
||
172 | } |
||
173 | |||
174 | protected function monitorCustomPing($software, $dummy) |
||
175 | { |
||
176 | $this->children[] = new VigiloTest('Ping'); |
||
177 | } |
||
178 | } |