glpi / hook.php @ bef4271a
History | View | Annotate | Download (2.06 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
//require_once(__DIR__ . DIRECTORY_SEPARATOR . '');
|
4 |
require __DIR__ . '/autoloader.php'; |
5 |
class VigiloHooks |
6 |
{ |
7 |
private $confdir; |
8 |
|
9 |
public function __construct($confdir="/etc/vigilo/vigiconf/conf.d") |
10 |
{ |
11 |
spl_autoload_register('vigilo_autoloader');
|
12 |
$this->confdir = $confdir; |
13 |
} |
14 |
|
15 |
public function add($computer) |
16 |
{ |
17 |
$host = new VigiloHost($computer); |
18 |
$dirs = array($this->confdir, "hosts", "managed"); |
19 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
20 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
21 |
|
22 |
mkdir($confdir, 0770, true); |
23 |
$acc = ""; |
24 |
foreach ($dirs as $dir) { |
25 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
26 |
chgrp($acc, "vigiconf"); |
27 |
} |
28 |
|
29 |
$res = file_put_contents($file, $host, LOCK_EX); |
30 |
if ($res !== false) { |
31 |
chgrp($file, "vigiconf"); |
32 |
chmod($file, 0660); |
33 |
} |
34 |
} |
35 |
|
36 |
public function delete($computer) |
37 |
{ |
38 |
$this->_unmonitor($computer->fields["name"]); |
39 |
} |
40 |
|
41 |
public function update($computer) |
42 |
{ |
43 |
if (isset($computer->oldvalues["name"])) { |
44 |
$this->_unmonitor($computer->oldvalues["name"]); |
45 |
} |
46 |
|
47 |
$this->add($computer); |
48 |
} |
49 |
|
50 |
public function _unmonitor($host) |
51 |
{ |
52 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
53 |
unlink(implode(DIRECTORY_SEPARATOR, $dirs)); |
54 |
} |
55 |
|
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 |
} |
66 |
} |
67 |
|
68 |
public function manageNetworks($network){ |
69 |
|
70 |
global $DB; |
71 |
|
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 |
} |
78 |
} |
79 |
} |
80 |
|