glpi / src / plugins / vigilo / inc / monitoredcomputer.class.php @ 166be9d2
History | View | Annotate | Download (4.76 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 === self::$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 |
self::$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 |
$test['label'] = $disk->getName(); |
73 |
$test['partname'] = $disk->fields['mountpoint']; |
74 |
if (!empty($total)) { |
75 |
$test[] = new VigiloArg('max', $total * 1024 * 1024); |
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
protected function monitorSoftwares() |
81 |
{ |
82 |
$computerSoftwareVersion = new Computer_SoftwareVersion(); |
83 |
$ids = $computerSoftwareVersion->find('computers_id=' . $this->item->getID()); |
84 |
foreach ($ids as $id) { |
85 |
if (!$id['softwareversions_id']) { |
86 |
continue;
|
87 |
} |
88 |
|
89 |
$softwareVersion = new SoftwareVersion(); |
90 |
$ids2 = $softwareVersion->find('id=' . $id['softwareversions_id']); |
91 |
foreach ($ids2 as $id2) { |
92 |
if (!$id2['softwares_id']) { |
93 |
continue;
|
94 |
} |
95 |
|
96 |
$software = new Software(); |
97 |
$software->getFromDB($id2['softwares_id']); |
98 |
|
99 |
$lcname = strtolower($software->getName()); |
100 |
if (isset(static::$softwares[$lcname])) { |
101 |
// Gestion des logiciels supervisés automatiquement.
|
102 |
list($testName, $testArgs) = static::$softwares[$name]; |
103 |
$this->children[] = new VigiloTest($testName, $testArgs); |
104 |
} elseif (!strncmp($lcname, 'vigilo-test-', 12)) { |
105 |
// Gestion des "faux logiciels".
|
106 |
$parts = explode('-', $software->getName(), 4); |
107 |
if (count($parts) < 3) { |
108 |
continue;
|
109 |
} |
110 |
|
111 |
$type = ucfirst(strtolower($parts[3])); |
112 |
$args = isset($parts[4]) ? $parts[4] : null; |
113 |
$method = 'monitorCustom' . $type; |
114 |
if (method_exists($this, $method)) { |
115 |
$this->$method($software, $args); |
116 |
} |
117 |
} |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
protected function monitorCustomService($software, $service) |
123 |
{ |
124 |
$this->children[] = new VigiloTest('Service', array('svcname' => $service)); |
125 |
} |
126 |
|
127 |
protected function monitorCustomTcp($software, $port) |
128 |
{ |
129 |
$port = (int) $port; |
130 |
if ($port > 0 && $port <= 65535) { |
131 |
$this->children[] = new Vigilotest('TCP', array('port') => $port); |
132 |
} |
133 |
} |
134 |
|
135 |
protected function monitorCustomProcess($software, $process) |
136 |
{ |
137 |
$this->children[] = new VigiloTest('Process', array('processname' => $process)); |
138 |
} |
139 |
|
140 |
protected function monitorCustomSwap($software, $dummy) |
141 |
{ |
142 |
$this->children[] = new VigiloTest('Swap'); |
143 |
} |
144 |
|
145 |
protected function monitorCustomPing($software, $dummy) |
146 |
{ |
147 |
$this->children[] = new VigiloTest('Ping'); |
148 |
} |
149 |
} |