Revision a5c9df40
Génération auto de l'XML de l'équipement supervisé.
Rend l'ensemble du code comforme au standard PSR2.
Ajoute la création du fichier XML des groupes.
Ajoute les balises groupes correctement dans le fichier XML des hôtes.
Rempli correctement la balise template dans le fichier XML des hôtes.
Change-Id: Ie8ae52e4912e7f34deb5e8a85dfef0a698cae6c9
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2153
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Tested-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Vigilo/VigiloArg.php | ||
---|---|---|
10 | 10 |
if (is_array($values)) { |
11 | 11 |
$new_values = array(); |
12 | 12 |
foreach ($values as $value) { |
13 |
if (is_string($value)) |
|
13 |
if (is_string($value)) {
|
|
14 | 14 |
$new_values[] = new VigiloItem($value); |
15 |
else if (!is_a($value, 'VigiloItem'))
|
|
15 |
} elseif (!is_a($value, 'VigiloItem')) {
|
|
16 | 16 |
throw new \RuntimeException(); |
17 |
else
|
|
17 |
} else {
|
|
18 | 18 |
$new_values[] = $value; |
19 |
} |
|
19 | 20 |
} |
20 | 21 |
$values = $new_values; |
21 |
} else if (!is_string($values) && !is_int($values) && |
|
22 |
!is_bool($values) && !is_float($values)) |
|
22 |
} elseif (!is_string($values) && !is_int($values) |
|
23 |
&& !is_bool($values) && !is_float($values) |
|
24 |
) { |
|
23 | 25 |
throw new \RuntimeException(); |
24 |
else { |
|
26 |
} else {
|
|
25 | 27 |
$values = (string) $values; |
26 | 28 |
} |
27 | 29 |
|
... | ... | |
36 | 38 |
|
37 | 39 |
public function getValue() |
38 | 40 |
{ |
39 |
if (is_string($this->values)) |
|
41 |
if (is_string($this->values)) {
|
|
40 | 42 |
return $this->values; |
43 |
} |
|
41 | 44 |
return array_map('getValue', $this->values); |
42 | 45 |
} |
43 | 46 |
|
... | ... | |
49 | 52 |
$this->values |
50 | 53 |
); |
51 | 54 |
} |
52 |
} |
|
55 |
} |
Vigilo/VigiloAttribute.php | ||
---|---|---|
19 | 19 |
$this->value |
20 | 20 |
); |
21 | 21 |
} |
22 |
} |
|
22 |
} |
Vigilo/VigiloGroup.php | ||
---|---|---|
13 | 13 |
{ |
14 | 14 |
return self::sprintf('<group>%s</group>', $this->name); |
15 | 15 |
} |
16 |
} |
|
16 |
} |
Vigilo/VigiloGroups.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class VigiloGroups extends VigiloXml |
|
4 |
{ |
|
5 |
protected $name; |
|
6 |
protected $grps; |
|
7 |
|
|
8 |
public function __construct($name) |
|
9 |
{ |
|
10 |
$this->name = $name; |
|
11 |
$this->grps=array(); |
|
12 |
} |
|
13 |
|
|
14 |
public function getName() |
|
15 |
{ |
|
16 |
return $this->name; |
|
17 |
} |
|
18 |
|
|
19 |
public function addSubGroup(VigiloGroups $subGroup) |
|
20 |
{ |
|
21 |
$this->grps[$subGroup->getName()] = $subGroup; |
|
22 |
} |
|
23 |
|
|
24 |
public function __toString() |
|
25 |
{ |
|
26 |
return self::sprintf( |
|
27 |
'<group name="%s">%s</group>', |
|
28 |
$this->name, |
|
29 |
$this->grps |
|
30 |
); |
|
31 |
} |
|
32 |
} |
Vigilo/VigiloHost.php | ||
---|---|---|
18 | 18 |
|
19 | 19 |
if (class_exists('PluginFusioninventoryAgent')) { |
20 | 20 |
$agent = new PluginFusioninventoryAgent(); |
21 |
if ($agent->getAgentWithComputerid($this->computer->getID()) !== false) |
|
21 |
if ($agent->getAgentWithComputerid($this->computer->getID()) !== false) {
|
|
22 | 22 |
$this->agent = $agent; |
23 |
} |
|
23 | 24 |
} |
24 | 25 |
|
25 | 26 |
$this->selectTemplates(); |
... | ... | |
38 | 39 |
|
39 | 40 |
protected function selectTemplates() |
40 | 41 |
{ |
42 |
if ($this->computer->getField("template_name")) { |
|
43 |
$this->children[] = new VigiloHostTemplate($this->computer->getField("template_name")); |
|
44 |
} |
|
41 | 45 |
$refs = array( |
42 | 46 |
"glpi_operatingsystems" => "operatingsystems_id", |
43 | 47 |
"glpi_operatingsystemversions" => "operatingsystemversions_id", |
... | ... | |
48 | 52 |
foreach ($refs as $table => $field) { |
49 | 53 |
$id = $this->computer->fields[$field]; |
50 | 54 |
$value = Dropdown::getDropdownName($table, $id); |
51 |
if ($value !== "" && $value !== null && $value !== " " && |
|
52 |
$value !== false && $value !== "-----") { |
|
55 |
if ($value !== "" && $value !== null && $value !== " " |
|
56 |
&& $value !== false && $value !== "-----" |
|
57 |
) { |
|
53 | 58 |
$model[] = $value; |
54 | 59 |
} |
55 | 60 |
} |
56 | 61 |
|
57 |
if (!count($model)) |
|
62 |
if (!count($model)) {
|
|
58 | 63 |
$model = "default"; |
59 |
else
|
|
64 |
} else {
|
|
60 | 65 |
$model = implode(" - ", $model); |
66 |
} |
|
61 | 67 |
|
62 | 68 |
$this->children[] = new VigiloHostTemplate($model); |
63 | 69 |
} |
... | ... | |
66 | 72 |
{ |
67 | 73 |
$location = new Location(); |
68 | 74 |
$location->getFromDB($this->computer->fields["locations_id"]); |
69 |
$location = $location->getName(); |
|
75 |
if (!($location->getName()=='N/A')) { |
|
76 |
$locationCompleteName=explode(" > ", $location->getField("completename")); |
|
77 |
$locationRealName="/" . implode("/", $locationCompleteName); |
|
78 |
$this->children[] = new VigiloGroup($locationRealName); |
|
79 |
} |
|
70 | 80 |
|
71 |
if (!$location) |
|
72 |
$location = "Servers"; |
|
81 |
$entity = new Entity(); |
|
82 |
$entity->getFromDB($this->computer->fields["entities_id"]); |
|
83 |
if (!($entity->getName()=='N/A')) { |
|
84 |
$entityCompleteName=explode(" > ", $entity->getField("completename")); |
|
85 |
$entityRealName="/" . implode("/", $entityCompleteName); |
|
86 |
$this->children[] = new VigiloGroup($entityRealName); |
|
87 |
} |
|
73 | 88 |
|
74 |
$this->children[] = new VigiloGroup($location); |
|
89 |
$manufacturer = new Manufacturer(); |
|
90 |
$manufacturer->getFromDB($this->computer->fields["manufacturers_id"]); |
|
91 |
if (!($manufacturer->getName()=='N/A')) { |
|
92 |
$this->children[] = new VigiloGroup($manufacturer->getName()); |
|
93 |
} |
|
75 | 94 |
} |
76 | 95 |
|
77 | 96 |
protected function selectAddress() |
... | ... | |
80 | 99 |
|
81 | 100 |
if ($address === null && $this->agent) { |
82 | 101 |
$addresses = $this->agent->getIPs(); |
83 |
if (count($addresses)) |
|
102 |
if (count($addresses)) {
|
|
84 | 103 |
$address = current($addresses); |
104 |
} |
|
85 | 105 |
} |
86 | 106 |
|
87 | 107 |
if ($address === null) { |
88 | 108 |
$address = $this->computer->getName(); |
89 | 109 |
foreach ($this->addresses as $addr) { |
90 |
if (!$addr->is_ipv4()) |
|
110 |
if (!$addr->is_ipv4()) {
|
|
91 | 111 |
continue; |
112 |
} |
|
92 | 113 |
|
93 | 114 |
$textual = $addr->getTextual(); |
94 | 115 |
if (is_string($textual)) { |
... | ... | |
122 | 143 |
$total += $memory->fields['size'] * 1024 * 1024; |
123 | 144 |
} |
124 | 145 |
|
125 |
if ($total > 0) |
|
146 |
if ($total > 0) {
|
|
126 | 147 |
$this->children[] = new VigiloTest('RAM'); |
148 |
} |
|
127 | 149 |
} |
128 | 150 |
|
129 | 151 |
protected function monitorNetworkInterfaces() |
130 | 152 |
{ |
131 | 153 |
global $DB; |
132 |
|
|
133 | 154 |
$query = NetworkPort::getSQLRequestToSearchForItem( |
134 | 155 |
$this->computer->getType(), |
135 | 156 |
$this->computer->getID() |
... | ... | |
137 | 158 |
|
138 | 159 |
foreach ($DB->query($query) as $np) { |
139 | 160 |
$query2 = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']); |
140 |
|
|
141 | 161 |
$port = new NetworkPort(); |
162 |
$ethport = new NetworkPortEthernet(); |
|
142 | 163 |
$port->getFromDB($np['id']); |
143 |
if ($port->getName() == 'lo') |
|
164 |
if ($port->getName() == 'lo') {
|
|
144 | 165 |
continue; |
166 |
} |
|
145 | 167 |
|
146 | 168 |
$args = array(); |
147 | 169 |
$label = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName(); |
170 |
$ethport = $ethport->find('networkports_id=' . $np['id']); |
|
171 |
foreach ($ethport as $rowEthPort) { |
|
172 |
if ($rowEthPort['speed']) { |
|
173 |
$args[] = new VigiloArg('max', $rowEthPort['speed']); |
|
174 |
break; |
|
175 |
} |
|
176 |
} |
|
148 | 177 |
$args[] = new VigiloArg('label', $label); |
149 |
$args[] = new VigiloArg('name', $port->getName()); |
|
150 |
// TODO: retrieve interface speed (from glpi_networkportethernets)
|
|
178 |
$args[] = new VigiloArg('ifname', $port->getName());
|
|
179 |
;
|
|
151 | 180 |
$this->children[] = new VigiloTest('Interface', $args); |
152 | 181 |
|
153 | 182 |
// Retrieve all IP addresses associated with this interface. |
... | ... | |
157 | 186 |
$query3 = IPAddress::getSQLRequestToSearchForItem("NetworkName", $nn['id']); |
158 | 187 |
foreach ($DB->query($query3) as $ip) { |
159 | 188 |
$addr = new IPAddress(); |
160 |
if ($addr->getFromDB($ip['id'])) |
|
189 |
if ($addr->getFromDB($ip['id'])) {
|
|
161 | 190 |
$this->addresses[] = $addr; |
191 |
} |
|
162 | 192 |
} |
163 | 193 |
} |
164 | 194 |
} |
... | ... | |
166 | 196 |
|
167 | 197 |
protected function monitorSoftwares() |
168 | 198 |
{ |
169 |
|
|
199 |
global $DB; |
|
200 |
$listOfTest=new VigiloTestSoftware($this->computer); |
|
201 |
$computerSoftwareVersion=new Computer_SoftwareVersion(); |
|
202 |
$ids=$computerSoftwareVersion->find('computers_id=' . $this->computer->getID()); |
|
203 |
foreach ($ids as $id) { |
|
204 |
if ($id['softwareversions_id']) { |
|
205 |
$softwareVersion=new SoftwareVersion(); |
|
206 |
$ids2=$softwareVersion->find('id=' . $id['softwareversions_id']); |
|
207 |
foreach ($ids2 as $id2) { |
|
208 |
if ($id2['softwares_id']) { |
|
209 |
$software=new Software(); |
|
210 |
$software->getFromDB($id2['softwares_id']); |
|
211 |
$listOfTest->addRelevantTestWith($software->getName()); |
|
212 |
} |
|
213 |
} |
|
214 |
} |
|
215 |
} |
|
216 |
foreach ($listOfTest->getTable() as $test) { |
|
217 |
$this->children[]=$test; |
|
218 |
} |
|
170 | 219 |
} |
171 | 220 |
|
172 | 221 |
protected function monitorPartitions() |
... | ... | |
186 | 235 |
$args[] = new VigiloArg('label', $disk->getName()); |
187 | 236 |
$args[] = new VigiloArg('partname', $disk->fields['mountpoint']); |
188 | 237 |
$total = $disk->fields['totalsize']; |
189 |
if (!empty($total)) |
|
238 |
if (!empty($total)) {
|
|
190 | 239 |
$args[] = new VigiloArg('max', $total * 1024 * 1024); |
240 |
} |
|
191 | 241 |
$this->children[] = new VigiloTest('Partition', $args); |
192 | 242 |
} |
193 | 243 |
} |
... | ... | |
195 | 245 |
public function __toString() |
196 | 246 |
{ |
197 | 247 |
$outXML=new DOMdocument(); |
198 |
$outXML->preserveWhiteSpace=false; |
|
199 |
$outXML->formatOutput=true; |
|
200 |
$outXML->loadXML(self::sprintf( |
|
201 |
'<?xml version="1.0"?>' . |
|
202 |
'<host name="%s" address="%s" ventilation="%s">%s</host>', |
|
203 |
$this->computer->getName(), |
|
204 |
$this->selectAddress(), |
|
205 |
"Servers", |
|
206 |
$this->children |
|
207 |
)); |
|
208 |
return $outXML->saveXML(); |
|
209 |
|
|
248 |
$outXML->preserveWhiteSpace=false; |
|
249 |
$outXML->formatOutput=true; |
|
250 |
$outXML->loadXML( |
|
251 |
self::sprintf( |
|
252 |
'<?xml version="1.0"?>' . |
|
253 |
'<host name="%s" address="%s" ventilation="%s">%s</host>', |
|
254 |
$this->computer->getName(), |
|
255 |
$this->selectAddress(), |
|
256 |
"Servers", |
|
257 |
$this->children |
|
258 |
) |
|
259 |
); |
|
260 |
return $outXML->saveXML(); |
|
210 | 261 |
} |
211 |
} |
|
262 |
} |
Vigilo/VigiloHostTemplate.php | ||
---|---|---|
13 | 13 |
{ |
14 | 14 |
return self::sprintf('<template>%s</template>', $this->name); |
15 | 15 |
} |
16 |
} |
|
16 |
} |
Vigilo/VigiloItem.php | ||
---|---|---|
18 | 18 |
{ |
19 | 19 |
return self::sprintf('<item>%s</item>', $this->value); |
20 | 20 |
} |
21 |
} |
|
21 |
} |
Vigilo/VigiloLocation.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class VigiloLocation extends VigiloXml |
|
4 |
{ |
|
5 |
protected $childrenLocation; |
|
6 |
protected $childrenEntity; |
|
7 |
protected $childrenManufacturer; |
|
8 |
|
|
9 |
public function __construct() |
|
10 |
{ |
|
11 |
$this->childrenLocation=array(); |
|
12 |
$this->childrenEntity=array(); |
|
13 |
$this->childrenManufacturer=array(); |
|
14 |
$this->selectLocations(); |
|
15 |
$this->selectEntities(); |
|
16 |
$this->selectManufacturers(); |
|
17 |
} |
|
18 |
|
|
19 |
protected function selectManufacturers() |
|
20 |
{ |
|
21 |
global $DB; |
|
22 |
$manufacturers=new Manufacturer(); |
|
23 |
$manufacturers=$manufacturers->find(); |
|
24 |
foreach ($manufacturers as $manufacturer) { |
|
25 |
$this->childrenManufacturer[] = new VigiloGroups($manufacturer["name"]); |
|
26 |
} |
|
27 |
} |
|
28 |
|
|
29 |
protected function selectEntities() |
|
30 |
{ |
|
31 |
global $DB; |
|
32 |
$entities=new Entity(); |
|
33 |
$entities=$entities->find("", "completename"); |
|
34 |
$ancestors=array(); |
|
35 |
foreach ($entities as $entity) { |
|
36 |
$currentLevel=$entity["level"]; |
|
37 |
if ($currentLevel==1 && isset($ancestors[1])) { |
|
38 |
$this->childrenEntity[]=$ancestors[1]; |
|
39 |
} |
|
40 |
$tempEntity = new VigiloGroups($entity["name"]); |
|
41 |
$ancestors[$currentLevel]=$tempEntity; |
|
42 |
if ($currentLevel != 1) { |
|
43 |
$ancestors[$currentLevel-1]->addSubGroup($tempEntity); |
|
44 |
} |
|
45 |
} |
|
46 |
$this->childrenEntity[]=$ancestors[1]; |
|
47 |
} |
|
48 |
|
|
49 |
protected function selectLocations() |
|
50 |
{ |
|
51 |
global $DB; |
|
52 |
$locations=new Location(); |
|
53 |
$locations=$locations->find("", "completename"); |
|
54 |
$ancestors=array(); |
|
55 |
foreach ($locations as $location) { |
|
56 |
$currentLevel=$location["level"]; |
|
57 |
if ($currentLevel==1 && isset($ancestors[1])) { |
|
58 |
$this->childrenLocation[]=$ancestors[1]; |
|
59 |
} |
|
60 |
$tempLocation = new VigiloGroups($location["name"]); |
|
61 |
$ancestors[$currentLevel]=$tempLocation; |
|
62 |
if ($currentLevel != 1) { |
|
63 |
$ancestors[$currentLevel-1]->addSubGroup($tempLocation); |
|
64 |
} |
|
65 |
} |
|
66 |
$this->childrenLocation[]=$ancestors[1]; |
|
67 |
} |
|
68 |
|
|
69 |
public function __toString() |
|
70 |
{ |
|
71 |
$outXML=new DOMdocument(); |
|
72 |
$outXML->preserveWhiteSpace=false; |
|
73 |
$outXML->formatOutput=true; |
|
74 |
$outXML->loadXML( |
|
75 |
self::sprintf( |
|
76 |
'<groups> |
|
77 |
<group name="Locations"> %s </group> |
|
78 |
<group name="Entities"> %s </group> |
|
79 |
<group name="Manufacturers"> %s </group> |
|
80 |
</groups>', |
|
81 |
$this->childrenLocation, |
|
82 |
$this->childrenEntity, |
|
83 |
$this->childrenManufacturer |
|
84 |
) |
|
85 |
); |
|
86 |
return $outXML->saveXML(); |
|
87 |
} |
|
88 |
} |
Vigilo/VigiloSoftwareList.php | ||
---|---|---|
1 |
<?php |
|
2 |
function getSoftwareList($computer) |
|
3 |
{ |
|
4 |
return array('httpd' =>array("addHTTPTest",array()), //http Apache server of CentOS |
|
5 |
'apache2' =>array("addHTTPTest",array()), //http Apache server |
|
6 |
'aolserver-4' =>array("addHTTPTest",array()), //AOL web server |
|
7 |
'gunicorn' =>array("addHTTPTest",array()), //Event-based HTTP/WSGI server |
|
8 |
'ebhttpd' =>array("addHTTPTest",array()), //Specialized HTTP server to access CD-ROM books |
|
9 |
'lighttpd' =>array("addHTTPTest",array()), //Fast webserver with minimal memory footprint |
|
10 |
'micro-httpd' =>array("addHTTPTest",array()), //Really small HTTP server |
|
11 |
'nghttp2' =>array("addHTTPTest",array()), //nghttp HTTP 2.0 servers |
|
12 |
'nginx' =>array("addHTTPTest",array()), //Small, powerful, scalable web/proxy server |
|
13 |
'webfs' =>array("addHTTPTest",array()), //Lightweight HTTP server for static content |
|
14 |
'yaws' =>array("addHTTPTest",array()), //High performance HTTP 1.1 webserver written by Erlang |
|
15 |
'elserv' =>array("addHTTPTest",array()), //HTTP server that runs on Emacsen |
|
16 |
'thin' =>array("addHTTPTest",array()), //Fast and very simple Ruby web server |
|
17 |
'webdis' =>array("addHTTPTest",array()), //Web server providing an HTTP interface to Redis |
|
18 |
|
|
19 |
//'ntp'=>array("addNTPTest",array()), //Network Time Protocol deamon and utility programs |
|
20 |
|
|
21 |
'vigilo-connector-metro' =>array("addVigiloConnectorTest",array("metro")), //Vigilo module receiving and stocking metrology data |
|
22 |
'vigilo-connector-nagios' =>array("addVigiloConnectorTest",array("nagios")), //Vigilo module sharing data with Nagios |
|
23 |
'vigilo-connector-syncevent' =>array("addVigiloConnectorTest",array("syncevent")), |
|
24 |
'vigilo-connector-vigiconf' =>array("addVigiloConnectorTest",array("vigiconf")), |
|
25 |
|
|
26 |
'nagios' =>array("addNagiosTest",array()), //Host/service/network monitoring and management system for CentOS |
|
27 |
'nagios3' =>array("addNagiosTest",array()), //Host/service/network monitoring and management system for Debian |
|
28 |
|
|
29 |
'memcached' =>array("addMemcachedTest",array($computer)), //High-performance memory object caching system |
|
30 |
'yrmcds' =>array("addMemcachedTest",array($computer)), //Memory object caching system with master/slave replication and server-side locking. |
|
31 |
|
|
32 |
'openssh-server' =>array("addSSHTest",array()), //Secure shell (SSH) server, for secure access from remote machines |
|
33 |
'ssh' =>array("addSSHTest",array()), //Secure shell client and server (metapackage) |
|
34 |
|
|
35 |
'mariadb-server' =>array("addPGSQLTest",array($computer)), //MariaDB database server |
|
36 |
'mysql-server' =>array("addPGSQLTest",array($computer)), //MySQL database server |
|
37 |
|
|
38 |
'micro-proxy' =>array("addProxyTest",array($computer)), //Really small HTTP/HTTPS proxy |
|
39 |
'ntlmaps' =>array("addProxyTest",array($computer)), //NTLM Authorization Proxy Server |
|
40 |
'privoxy' =>array("addProxyTest",array($computer)), //Privacy enhancing HTTP Proxy |
|
41 |
'squid3' =>array("addProxyTest",array($computer)), //Full featured Web Proxy cache (HTTP proxy) |
|
42 |
'tinyproxy' =>array("addProxyTest",array($computer)), //A lightweight, non-caching, optionally anonymizing HTTP proxy |
|
43 |
|
|
44 |
'rrdcached' =>array("addRRDcachedTest",array($computer))); //Data caching daemon for RRDtool |
|
45 |
} |
Vigilo/VigiloTest.php | ||
---|---|---|
9 | 9 |
{ |
10 | 10 |
$new_args = array(); |
11 | 11 |
foreach ($args as $arg) { |
12 |
if (!is_a($arg, 'VigiloArg')) |
|
12 |
if (!is_a($arg, 'VigiloArg')) {
|
|
13 | 13 |
throw new \RuntimeException(); |
14 |
} |
|
14 | 15 |
$new_args[$arg->getName()] = $arg; |
15 | 16 |
} |
16 | 17 |
|
... | ... | |
27 | 28 |
); |
28 | 29 |
} |
29 | 30 |
} |
30 |
|
Vigilo/VigiloTestSoftware.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
include 'VigiloSoftwareList.php'; |
|
4 |
|
|
5 |
class VigiloTestSoftware |
|
6 |
{ |
|
7 |
protected $testTable; |
|
8 |
protected $softwareBase; |
|
9 |
protected $computer; |
|
10 |
protected $addedTests; |
|
11 |
|
|
12 |
public function __construct($computer) |
|
13 |
{ |
|
14 |
$this->computer=$computer; |
|
15 |
$this->softwareBase = getSoftwareList($this->computer); |
|
16 |
$this->testTable=array(); |
|
17 |
$this->addedTests=array(); |
|
18 |
} |
|
19 |
|
|
20 |
public function getTable() |
|
21 |
{ |
|
22 |
return $this->testTable; |
|
23 |
} |
|
24 |
|
|
25 |
public function addRelevantTestWith($softwareName) |
|
26 |
{ |
|
27 |
$functionArray=$this->softwareBase[$softwareName]; |
|
28 |
$this->testTable[]=call_user_func_array(array($this,$functionArray[0]), $functionArray[1]); |
|
29 |
} |
|
30 |
|
|
31 |
protected function addNTPTest() |
|
32 |
{ |
|
33 |
//TODO : set up arguments |
|
34 |
$args=array(); |
|
35 |
//$address=0; |
|
36 |
//$args[]=new VigiloArg('address',$address); |
|
37 |
$args[]=new VigiloArg('crit', 0); |
|
38 |
$args[]=new VigiloArg('warn', 0); |
|
39 |
return new VigiloTest('NTP', $args); |
|
40 |
} |
|
41 |
|
|
42 |
protected function addNTPqTest() |
|
43 |
{ |
|
44 |
//TODO: set up arguments |
|
45 |
$args=array(); |
|
46 |
$args[]=new VigiloArg('crit', 0); |
|
47 |
$args[]=new VigiloArg('warn', 0); |
|
48 |
return new VigiloTest('NTPq', $args); |
|
49 |
} |
|
50 |
|
|
51 |
protected function addNTPSyncTest() |
|
52 |
{ |
|
53 |
return new VigiloTest('NTPSync'); |
|
54 |
} |
|
55 |
|
|
56 |
protected function addHTTPTest() |
|
57 |
{ |
|
58 |
return new VigiloTest('HTTP'); |
|
59 |
} |
|
60 |
|
|
61 |
protected function addMemcachedTest($computer) |
|
62 |
{ |
|
63 |
$args=array(); |
|
64 |
$args[]=new VigiloArg('port', 11211);//TODO: set up arguments |
|
65 |
return new VigiloTest('Memcached', $args); |
|
66 |
} |
|
67 |
|
|
68 |
protected function addNagiosTest() |
|
69 |
{ |
|
70 |
return new VigiloTest('Nagios'); |
|
71 |
} |
|
72 |
|
|
73 |
protected function addPGSQLTest($computer) |
|
74 |
{ |
|
75 |
//TODO: set up arguments |
|
76 |
//$args=array(); |
|
77 |
//$args[]=new VigiloArg('database',NULL); |
|
78 |
//$args[]=new VigiloArg('port',NULL); |
|
79 |
//$args[]=new VigiloArg('user',NULL); |
|
80 |
//return new VigiloTest('PostgreSQLConnection',$args); |
|
81 |
} |
|
82 |
|
|
83 |
protected function addProxyTest() |
|
84 |
{ |
|
85 |
//TODO: set up arguments |
|
86 |
//$args=array(); |
|
87 |
/*$args[]=new VigiloArg('auth',NULL); |
|
88 |
$args[]=new VigiloArg('port',NULL); |
|
89 |
$args[]=new VigiloArg('url',NULL);*/ |
|
90 |
//return new VigiloTest('Proxy',$args); |
|
91 |
} |
|
92 |
|
|
93 |
protected function addRRDcachedTest($computer) |
|
94 |
{ |
|
95 |
//TODO: set up arguments |
|
96 |
//$path= |
|
97 |
//$args=array(); |
|
98 |
//$args[]=new VigiloArg('crit',0); |
|
99 |
//$args[]=new VigiloArg('path',$path); |
|
100 |
//$args[]=new VigiloArg('warn',0); |
|
101 |
//return new VigiloTest('RRDcached',$args); |
|
102 |
} |
|
103 |
|
|
104 |
protected function addSSHTest() |
|
105 |
{ |
|
106 |
return new VigiloTest('SSH'); |
|
107 |
} |
|
108 |
|
|
109 |
protected function addVigiloConnectorTest($type) |
|
110 |
{ |
|
111 |
$args=array(); |
|
112 |
$args[]=new VigiloArg('type', $type); |
|
113 |
return new VigiloTest('VigiloConnector', $args); |
|
114 |
} |
|
115 |
|
|
116 |
protected function addVigiloCorrelatorTest() |
|
117 |
{ |
|
118 |
//TODO :set up arguments |
|
119 |
//$args=array(); |
|
120 |
//$args[]=new VigiloArg('rules',NULL); |
|
121 |
//$args[]=new VigiloArg('servicename',NULL); |
|
122 |
//return new VigiloTest('VigiloCorrelator',$args); |
|
123 |
} |
|
124 |
|
|
125 |
protected function TestService($computer) |
|
126 |
{ |
|
127 |
//TODO: set up arguments |
|
128 |
//$args=array(); |
|
129 |
//$args[]=new VigiloArg('svcname',NULL); |
|
130 |
//return new VigiloTest('Service',$args); |
|
131 |
} |
|
132 |
|
|
133 |
public function __toString() |
|
134 |
{ |
|
135 |
return $this->child; |
|
136 |
} |
|
137 |
} |
Vigilo/VigiloXml.php | ||
---|---|---|
13 | 13 |
foreach ($args as $arg) { |
14 | 14 |
if (is_string($arg)) { |
15 | 15 |
$new_args[] = htmlspecialchars($arg, ENT_XML1 | ENT_QUOTES, "utf-8"); |
16 |
} else if (is_array($arg)) {
|
|
16 |
} elseif (is_array($arg)) { |
|
17 | 17 |
$acc = ''; |
18 | 18 |
foreach ($arg as $sub) { |
19 |
if (is_object($sub)) |
|
19 |
if (is_object($sub)) {
|
|
20 | 20 |
$acc .= (string) $sub; |
21 |
} |
|
21 | 22 |
} |
22 | 23 |
$new_args[] = $acc; |
23 | 24 |
} else { |
... | ... | |
28 | 29 |
return vsprintf($s, $new_args); |
29 | 30 |
} |
30 | 31 |
} |
31 |
|
autoloader.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
function vigilo_autoloader($class_name){ |
|
4 |
if(strstr($class_name,'Vigilo')){ |
|
5 |
require_once __DIR__ . '/Vigilo/' . $class_name . '.php'; |
|
6 |
} |
|
3 |
function vigilo_autoloader($class_name) |
|
4 |
{ |
|
5 |
if (strncmp($class_name, 'Vigilo', 6)==0) { |
|
6 |
require_once __DIR__ . DIRECTORY_SEPARATOR .'Vigilo'. DIRECTORY_SEPARATOR . $class_name . '.php'; |
|
7 |
} |
|
7 | 8 |
} |
hook.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
//require_once(__DIR__ . DIRECTORY_SEPARATOR . ''); |
|
4 |
require __DIR__ . '/autoloader.php'; |
|
3 |
require __DIR__ . DIRECTORY_SEPARATOR .'autoloader.php'; |
|
5 | 4 |
class VigiloHooks |
6 | 5 |
{ |
7 | 6 |
private $confdir; |
8 | 7 |
|
9 |
public function __construct($confdir="/etc/vigilo/vigiconf/conf.d")
|
|
8 |
public function __construct($confdir = "/etc/vigilo/vigiconf/conf.d")
|
|
10 | 9 |
{ |
11 | 10 |
spl_autoload_register('vigilo_autoloader'); |
12 | 11 |
$this->confdir = $confdir; |
13 | 12 |
} |
14 | 13 |
|
15 |
public function add($computer)
|
|
14 |
public function updateGroups()
|
|
16 | 15 |
{ |
17 |
$host = new VigiloHost($computer);
|
|
18 |
$dirs = array($this->confdir, "hosts", "managed");
|
|
16 |
$host = new VigiloLocation();
|
|
17 |
$dirs = array($this->confdir, "groups", "managed");
|
|
19 | 18 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
20 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml";
|
|
19 |
$file = $confdir . DIRECTORY_SEPARATOR . "groups.xml";
|
|
21 | 20 |
|
22 | 21 |
mkdir($confdir, 0770, true); |
23 | 22 |
$acc = ""; |
... | ... | |
33 | 32 |
} |
34 | 33 |
} |
35 | 34 |
|
35 |
public function add($computer) |
|
36 |
{ |
|
37 |
if ($computer->getField("is_template")==0) { |
|
38 |
$host = new VigiloHost($computer); |
|
39 |
$dirs = array($this->confdir, "hosts", "managed"); |
|
40 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
|
41 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
|
42 |
|
|
43 |
mkdir($confdir, 0770, true); |
|
44 |
$acc = ""; |
|
45 |
foreach ($dirs as $dir) { |
|
46 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
|
47 |
chgrp($acc, "vigiconf"); |
|
48 |
} |
|
49 |
|
|
50 |
$res = file_put_contents($file, $host, LOCK_EX); |
|
51 |
if ($res !== false) { |
|
52 |
chgrp($file, "vigiconf"); |
|
53 |
chmod($file, 0660); |
|
54 |
} |
|
55 |
} |
|
56 |
} |
|
57 |
|
|
36 | 58 |
public function delete($computer) |
37 | 59 |
{ |
38 |
$this->_unmonitor($computer->fields["name"]);
|
|
60 |
$this->unmonitor($computer->fields["name"]); |
|
39 | 61 |
} |
40 | 62 |
|
41 | 63 |
public function update($computer) |
42 | 64 |
{ |
43 | 65 |
if (isset($computer->oldvalues["name"])) { |
44 |
$this->_unmonitor($computer->oldvalues["name"]);
|
|
66 |
$this->unmonitor($computer->oldvalues["name"]); |
|
45 | 67 |
} |
46 | 68 |
|
47 | 69 |
$this->add($computer); |
48 | 70 |
} |
49 | 71 |
|
50 |
public function _unmonitor($host)
|
|
72 |
public function unmonitor($host) |
|
51 | 73 |
{ |
52 | 74 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
53 | 75 |
unlink(implode(DIRECTORY_SEPARATOR, $dirs)); |
54 | 76 |
} |
55 | 77 |
|
56 |
public function manageDisks($disk){ |
|
57 |
|
|
58 |
global $DB; |
|
59 |
|
|
60 |
$query="SELECT computers_id FROM glpi_" . strtolower($disks->getType()) . "s WHERE id=" . $disks->getID() . ";"; |
|
61 |
foreach($DB->query($query) as $id){ |
|
62 |
$computer= new Computer(); |
|
63 |
$computer->getFromDB($id['id']); |
|
64 |
$this->update($computer); |
|
65 |
} |
|
78 |
public function manageSoftwares($software) |
|
79 |
{ |
|
80 |
global $DB; |
|
81 |
$softwareVer=new SoftwareVersion(); |
|
82 |
$idSoftwareVersion=$softwareVer->find('softwares_id=' . $software->getID()); |
|
83 |
foreach ($idSoftwareVersion as $idVersion) { |
|
84 |
if ($idVersion['id']) { |
|
85 |
$computerVer=new Computer_SoftwareVersion(); |
|
86 |
$goodField='softwareversions_id=' . $idVersion['id']; |
|
87 |
$updateComp=$computerVer->find($goodField); |
|
88 |
foreach ($updateComp as $idComputer) { |
|
89 |
if ($idComputer['computers_id'] != -1) { |
|
90 |
$computer=new Computer(); |
|
91 |
$computer->getFromDB($idComputer['computers_id']); |
|
92 |
$this->update($computer); |
|
93 |
} |
|
94 |
} |
|
95 |
} |
|
96 |
} |
|
97 |
} |
|
98 |
|
|
99 |
public function manageDisks($disk) |
|
100 |
{ |
|
101 |
global $DB; |
|
102 |
$id=$disk->getField('computers_id'); |
|
103 |
$computer=new Computer(); |
|
104 |
$computer->getFromDB($id); |
|
105 |
$this->update($computer); |
|
66 | 106 |
} |
67 | 107 |
|
68 |
public function manageNetworks($network){ |
|
69 |
|
|
70 |
global $DB; |
|
108 |
public function manageAddresses($address) |
|
109 |
{ |
|
110 |
global $DB; |
|
111 |
$id=$address->getField('mainitems_id'); |
|
112 |
$comp=new Computer(); |
|
113 |
$comp->getFromDB($id); |
|
114 |
$this->update($comp); |
|
115 |
} |
|
71 | 116 |
|
72 |
$query="SELECT computers_id FROM glpi_computers WHERE networks_id=" . $network->getID() . ";"; |
|
73 |
foreach($DB->query($query) as $id){ |
|
74 |
$computer=new Computer(); |
|
75 |
$computer->getFromDB($id['id']); |
|
76 |
$this->update($computer); |
|
77 |
} |
|
117 |
public function manageNetworks($network) |
|
118 |
{ |
|
119 |
global $DB; |
|
120 |
; |
|
121 |
$id=$network->getField('items_id'); |
|
122 |
$comp=new Computer(); |
|
123 |
$comp->getFromDB($id); |
|
124 |
$this->update($comp); |
|
78 | 125 |
} |
79 | 126 |
} |
80 |
|
inc/menu.class.php | ||
---|---|---|
70 | 70 |
break; |
71 | 71 |
} |
72 | 72 |
|
73 |
foreach ($read as $stream) |
|
73 |
foreach ($read as $stream){
|
|
74 | 74 |
echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
75 |
ob_flush(); |
|
75 |
}; |
|
76 |
//ob_flush(); |
|
76 | 77 |
flush(); |
77 |
|
|
78 |
if (feof($pipes[1]))
|
|
79 |
break;
|
|
78 |
if (feof($pipes[1])){ |
|
79 |
break;
|
|
80 |
}
|
|
80 | 81 |
} while (1); |
81 | 82 |
|
82 | 83 |
$info = proc_get_status($res); |
setup.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
include(__DIR__ . "/hook.php");
|
|
3 |
require __DIR__ . "/hook.php";
|
|
4 | 4 |
|
5 |
function plugin_init_vigilo() { |
|
5 |
function plugin_init_vigilo() |
|
6 |
{ |
|
6 | 7 |
global $PLUGIN_HOOKS; |
7 |
|
|
8 | 8 |
$hooks =& $PLUGIN_HOOKS; |
9 | 9 |
$p = "vigilo"; |
10 | 10 |
$hookObj = new VigiloHooks(); |
11 |
|
|
12 | 11 |
$hooks['csrf_compliant'][$p] = true; |
13 | 12 |
$hooks['item_add'][$p] = array("Computer" => array($hookObj, "add"), |
14 |
"ComputerDisk" => array($hookObj),"manageDisks", |
|
15 |
"Network" => array($hookObj),"manageNetworks"); |
|
13 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
14 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
15 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
16 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
17 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
18 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
19 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
20 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
21 |
"Software" => array($hookObj,"manageSoftwares"), |
|
22 |
"Location" => array($hookObj,"updateGroups"), |
|
23 |
"Entity" => array($hookObj,"updateGroups"), |
|
24 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
16 | 25 |
$hooks['item_update'][$p] = array("Computer" => array($hookObj, "update"), |
17 |
"ComputerDisk" => array($hookObj),"manageDisks", |
|
18 |
"Network" => array($hookObj),"manageNetworks"); |
|
26 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
27 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
28 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
29 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
30 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
31 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
32 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
33 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
34 |
"Software" => array($hookObj,"manageSoftwares"), |
|
35 |
"Location" => array($hookObj,"updateGroups"), |
|
36 |
"Entity" => array($hookObj,"updateGroups"), |
|
37 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
19 | 38 |
$hooks['item_purge'][$p] = array("Computer" => array($hookObj, "delete"), |
20 |
"ComputerDisk" => array($hookObj),"manageDisks", |
|
21 |
"Network" => array($hookObj),"manageNetworks"); |
|
39 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
40 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
41 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
42 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
43 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
44 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
45 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
46 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
47 |
"Software" => array($hookObj,"manageSoftwares"), |
|
48 |
"Location" => array($hookObj,"updateGroups"), |
|
49 |
"Entity" => array($hookObj,"updateGroups"), |
|
50 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
22 | 51 |
$hooks['item_delete'][$p] = array("Computer" => array($hookObj, "delete"), |
23 |
"ComputerDisk" => array($hookObj),"manageDisks", |
|
24 |
"Network" => array($hookObj),"manageNetworks"); |
|
52 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
53 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
54 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
55 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
56 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
57 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
58 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
59 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
60 |
"Software" => array($hookObj,"manageSoftwares"), |
|
61 |
"Location" => array($hookObj,"updateGroups"), |
|
62 |
"Entity" => array($hookObj,"updateGroups"), |
|
63 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
25 | 64 |
$hooks['item_restore'][$p] = array("Computer" => array($hookObj, "add"), |
26 |
"ComputerDisk" => array($hookObj),"manageDisks", |
|
27 |
"Network" => array($hookObj),"manageNetworks"); |
|
65 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
66 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
67 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
68 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
69 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
70 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
71 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
72 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
73 |
"Software" => array($hookObj,"manageSoftwares"), |
|
74 |
"Location" => array($hookObj,"updateGroups"), |
|
75 |
"Entity" => array($hookObj,"updateGroups"), |
|
76 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
28 | 77 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
29 | 78 |
$hooks['config_page'][$p] = 'front/menu.php?itemtype=vigilo'; |
30 | 79 |
} |
31 | 80 |
|
32 |
function plugin_version_vigilo() { |
|
33 |
return array('name' => 'Vigilo monitoring', |
|
81 |
function plugin_version_vigilo() |
|
82 |
{ |
|
83 |
return array('name' => 'Vigilo monitoring', |
|
34 | 84 |
'version' => '0.1', |
35 | 85 |
'author' => 'CSSI', |
36 | 86 |
'license' => 'GPLv2+', |
... | ... | |
38 | 88 |
'minGlpiVersion' => '9.1'); |
39 | 89 |
} |
40 | 90 |
|
41 |
function plugin_vigilo_check_config($verbose=false) { |
|
42 |
if (version_compare(GLPI_VERSION,'9.1','lt')) { |
|
91 |
function plugin_vigilo_check_config($verbose = false) |
|
92 |
{ |
|
93 |
if (version_compare(GLPI_VERSION, '9.1', 'lt')) { |
|
43 | 94 |
echo "This plugin requires GLPI >= 9.1"; |
44 | 95 |
return false; |
45 | 96 |
} |
46 | 97 |
return true; |
47 | 98 |
} |
48 | 99 |
|
49 |
function plugin_vigilo_check_prerequisites() { |
|
100 |
function plugin_vigilo_check_prerequisites() |
|
101 |
{ |
|
50 | 102 |
return true; |
51 | 103 |
} |
52 | 104 |
|
53 |
function plugin_vigilo_install() { |
|
105 |
function plugin_vigilo_install() |
|
106 |
{ |
|
54 | 107 |
return true; |
55 | 108 |
} |
56 | 109 |
|
57 |
function plugin_vigilo_uninstall() { |
|
110 |
function plugin_vigilo_uninstall() |
|
111 |
{ |
|
58 | 112 |
return true; |
59 | 113 |
} |
60 |
|
Also available in: Unified diff