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>
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 |
|
Also available in: Unified diff