glpi / src / plugins / vigilo / inc / monitoredcomputer.class.php @ e1c378c0
History | View | Annotate | Download (4.96 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 | $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 | c60a37ae | Francois POIROTTE | $installations = new Computer_SoftwareVersion(); |
83 | $installations = $installations->find('computers_id=' . $this->item->getID()); |
||
84 | foreach ($installations as $installation) { |
||
85 | if (!$installation['softwareversions_id']) { |
||
86 | 166be9d2 | Francois POIROTTE | continue;
|
87 | } |
||
88 | |||
89 | c60a37ae | Francois POIROTTE | $versions = new SoftwareVersion(); |
90 | $versions = $versions->find('id=' . $installation['softwareversions_id']); |
||
91 | foreach ($versions as $version) { |
||
92 | if (!$version['softwares_id']) { |
||
93 | 166be9d2 | Francois POIROTTE | continue;
|
94 | } |
||
95 | |||
96 | $software = new Software(); |
||
97 | c60a37ae | Francois POIROTTE | $software->getFromDB($version['softwares_id']); |
98 | 166be9d2 | Francois POIROTTE | $lcname = strtolower($software->getName()); |
99 | if (isset(static::$softwares[$lcname])) { |
||
100 | // Gestion des logiciels supervisés automatiquement.
|
||
101 | cdde5484 | Francois POIROTTE | list($testName, $testArgs) = static::$softwares[$lcname]; |
102 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest($testName, $testArgs); |
103 | } elseif (!strncmp($lcname, 'vigilo-test-', 12)) { |
||
104 | // Gestion des "faux logiciels".
|
||
105 | $parts = explode('-', $software->getName(), 4); |
||
106 | if (count($parts) < 3) { |
||
107 | continue;
|
||
108 | } |
||
109 | |||
110 | c60a37ae | Francois POIROTTE | $type = ucfirst(strtolower($parts[2])); |
111 | $args = isset($parts[3]) ? $parts[3] : null; |
||
112 | 166be9d2 | Francois POIROTTE | $method = 'monitorCustom' . $type; |
113 | if (method_exists($this, $method)) { |
||
114 | $this->$method($software, $args); |
||
115 | } |
||
116 | } |
||
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
121 | protected function monitorCustomService($software, $service) |
||
122 | { |
||
123 | c60a37ae | Francois POIROTTE | if (!$service) { |
124 | return;
|
||
125 | } |
||
126 | |||
127 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest('Service', array('svcname' => $service)); |
128 | } |
||
129 | |||
130 | protected function monitorCustomTcp($software, $port) |
||
131 | { |
||
132 | c60a37ae | Francois POIROTTE | if (!$port) { |
133 | return;
|
||
134 | } |
||
135 | |||
136 | 166be9d2 | Francois POIROTTE | $port = (int) $port; |
137 | if ($port > 0 && $port <= 65535) { |
||
138 | cdde5484 | Francois POIROTTE | $this->children[] = new Vigilotest('TCP', array('port' => $port)); |
139 | 166be9d2 | Francois POIROTTE | } |
140 | } |
||
141 | |||
142 | protected function monitorCustomProcess($software, $process) |
||
143 | { |
||
144 | c60a37ae | Francois POIROTTE | if (!$process) { |
145 | return;
|
||
146 | } |
||
147 | |||
148 | 166be9d2 | Francois POIROTTE | $this->children[] = new VigiloTest('Process', array('processname' => $process)); |
149 | } |
||
150 | |||
151 | protected function monitorCustomSwap($software, $dummy) |
||
152 | { |
||
153 | $this->children[] = new VigiloTest('Swap'); |
||
154 | } |
||
155 | |||
156 | protected function monitorCustomPing($software, $dummy) |
||
157 | { |
||
158 | $this->children[] = new VigiloTest('Ping'); |
||
159 | } |
||
160 | } |