Revision 077e4de7
Prise en compte conventions de codage
Change-Id: I74d6ea904e099519e7d2b08f0586696470514280
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2367
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
src/Vigilo/VigiloHost.php | ||
---|---|---|
38 | 38 |
|
39 | 39 |
protected function selectTemplates() |
40 | 40 |
{ |
41 |
$template_name = $this->computer->getField("template_name");
|
|
41 |
$template_name = $this->computer->getField("template_name");
|
|
42 | 42 |
|
43 | 43 |
if ($template_name && $template_name !== "N/A") { |
44 | 44 |
$this->children[] = new VigiloHostTemplate($this->computer->getField("template_name")); |
... | ... | |
49 | 49 |
$common_dbtm = new CommonDBTM(); |
50 | 50 |
$template_name = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($template_number); |
51 | 51 |
$this->children[] = new VigiloHostTemplate($template_name); |
52 |
} |
|
53 |
else { |
|
54 |
if (empty($this->children)) { |
|
55 |
$template_name = "default"; |
|
56 |
$this->children[] = new VigiloHostTemplate($template_name); |
|
57 |
} |
|
52 |
} elseif (empty($this->children)) { |
|
53 |
$template_name = "default"; |
|
54 |
$this->children[] = new VigiloHostTemplate($template_name); |
|
58 | 55 |
} |
59 | 56 |
} |
60 | 57 |
|
... | ... | |
62 | 59 |
{ |
63 | 60 |
$location = new Location(); |
64 | 61 |
$location->getFromDB($this->computer->fields["locations_id"]); |
65 |
if (!($location->getName()=='N/A')) {
|
|
62 |
if (!($location->getName() == 'N/A')) {
|
|
66 | 63 |
$locationCompleteName=explode(" > ", $location->getField("completename")); |
67 | 64 |
$locationRealName=implode("/", $locationCompleteName); |
68 | 65 |
$this->children[] = new VigiloGroup($locationRealName); |
... | ... | |
70 | 67 |
|
71 | 68 |
$entity = new Entity(); |
72 | 69 |
$entity->getFromDB($this->computer->fields["entities_id"]); |
73 |
if (!($entity->getName()=='N/A')) {
|
|
70 |
if (!($entity->getName() == 'N/A')) {
|
|
74 | 71 |
$entityCompleteName=explode(" > ", $entity->getField("completename")); |
75 | 72 |
$entityRealName=implode("/", $entityCompleteName); |
76 | 73 |
$this->children[] = new VigiloGroup($entityRealName); |
... | ... | |
78 | 75 |
|
79 | 76 |
$manufacturer = new Manufacturer(); |
80 | 77 |
$manufacturer->getFromDB($this->computer->fields["manufacturers_id"]); |
81 |
if (!($manufacturer->getName()=='N/A')) {
|
|
78 |
if (!($manufacturer->getName() == 'N/A')) {
|
|
82 | 79 |
$this->children[] = new VigiloGroup($manufacturer->getName()); |
83 | 80 |
} |
84 | 81 |
} |
src/Vigilo/VigiloNetworkEquipment.php | ||
---|---|---|
12 | 12 |
{ |
13 | 13 |
$this->agent = null; |
14 | 14 |
$this->ventilation = "Servers"; |
15 |
$this->network = $network; |
|
15 |
$this->network = $network;
|
|
16 | 16 |
$this->addresses = array(); |
17 | 17 |
$this->children = array(); |
18 | 18 |
|
... | ... | |
35 | 35 |
|
36 | 36 |
protected function selectTemplates() |
37 | 37 |
{ |
38 |
$template_name = $this->network->getField("template_name");
|
|
38 |
$template_name = $this->network->getField("template_name");
|
|
39 | 39 |
|
40 |
if ($template_name && $template_name !== "N/A") {
|
|
40 |
if ($template_name !== "N/A") { |
|
41 | 41 |
$this->children[] = new VigiloHostTemplate($this->network->getField("template_name")); |
42 | 42 |
} |
43 | 43 |
} |
src/Vigilo/VigiloPrinter.php | ||
---|---|---|
35 | 35 |
|
36 | 36 |
protected function selectTemplates() |
37 | 37 |
{ |
38 |
$template_name = $this->network->getField("template_name");
|
|
38 |
$template_name = $this->network->getField("template_name");
|
|
39 | 39 |
|
40 |
if ($template_name && $template_name !== "N/A") {
|
|
40 |
if ($template_name !== "N/A") { |
|
41 | 41 |
$this->children[] = new VigiloHostTemplate($this->network->getField("template_name")); |
42 | 42 |
} |
43 | 43 |
} |
src/Vigilo/VigiloSoftwareList.php | ||
---|---|---|
1 | 1 |
<?php |
2 |
|
|
2 | 3 |
function getSoftwareList($computer) |
3 | 4 |
{ |
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 |
//'ntp'=>array("addNTPTest",array()), //Network Time Protocol deamon and utility programs |
|
19 |
|
|
20 |
'vigilo-connector-metro' =>array("addVigiloConnectorTest",array("metro")), //Vigilo module receiving and stocking metrology data |
|
21 |
'vigilo-connector-nagios' =>array("addVigiloConnectorTest",array("nagios")), //Vigilo module sharing data with Nagios |
|
22 |
'vigilo-connector-syncevent' =>array("addVigiloConnectorTest",array("syncevent")), |
|
23 |
'vigilo-connector-vigiconf' =>array("addVigiloConnectorTest",array("vigiconf")), |
|
24 |
|
|
25 |
'nagios' =>array("addNagiosTest",array()), //Host/service/network monitoring and management system for CentOS |
|
26 |
'nagios3' =>array("addNagiosTest",array()), //Host/service/network monitoring and management system for Debian |
|
27 |
|
|
28 |
'memcached' =>array("addMemcachedTest",array($computer)), //High-performance memory object caching system |
|
29 |
'yrmcds' =>array("addMemcachedTest",array($computer)), //Memory object caching system with master/slave replication and server-side locking. |
|
30 |
|
|
31 |
'openssh-server' =>array("addSSHTest",array()), //Secure shell (SSH) server, for secure access from remote machines |
|
32 |
'ssh' =>array("addSSHTest",array()), //Secure shell client and server (metapackage) |
|
33 |
|
|
34 |
'mariadb-server' =>array("addPGSQLTest",array($computer)), //MariaDB database server |
|
35 |
'mysql-server' =>array("addPGSQLTest",array($computer)), //MySQL database server |
|
36 |
|
|
37 |
'micro-proxy' =>array("addProxyTest",array($computer)), //Really small HTTP/HTTPS proxy |
|
38 |
'ntlmaps' =>array("addProxyTest",array($computer)), //NTLM Authorization Proxy Server |
|
39 |
'privoxy' =>array("addProxyTest",array($computer)), //Privacy enhancing HTTP Proxy |
|
40 |
'squid3' =>array("addProxyTest",array($computer)), //Full featured Web Proxy cache (HTTP proxy) |
|
41 |
'tinyproxy' =>array("addProxyTest",array($computer)), //A lightweight, non-caching, optionally anonymizing HTTP proxy |
|
42 |
|
|
43 |
'rrdcached' =>array("addRRDcachedTest",array($computer))); //Data caching daemon for RRDtool |
|
5 |
return array( |
|
6 |
/** |
|
7 |
* Serveurs web |
|
8 |
*/ |
|
9 |
// Apache HTTP Server (RHEL/CentOS) |
|
10 |
'httpd' => array("addHTTPTest", array()), |
|
11 |
|
|
12 |
// Apache HTTP Server (Debian) |
|
13 |
'apache2' => array("addHTTPTest", array()), |
|
14 |
|
|
15 |
// AOL web server |
|
16 |
'aolserver-4' => array("addHTTPTest", array()), |
|
17 |
|
|
18 |
// Event-based HTTP/WSGI server |
|
19 |
'gunicorn' => array("addHTTPTest", array()), |
|
20 |
|
|
21 |
// Specialized HTTP server to access CD-ROM books |
|
22 |
'ebhttpd' => array("addHTTPTest", array()), |
|
23 |
|
|
24 |
// Fast webserver with minimal memory footprint |
|
25 |
'lighttpd' => array("addHTTPTest", array()), |
|
26 |
|
|
27 |
// Really small HTTP server |
|
28 |
'micro-httpd' => array("addHTTPTest", array()), |
|
29 |
|
|
30 |
// nghttp HTTP 2.0 servers |
|
31 |
'nghttp2' => array("addHTTPTest", array()), |
|
32 |
|
|
33 |
// Small, powerful, scalable web/proxy server |
|
34 |
'nginx' => array("addHTTPTest", array()), |
|
35 |
|
|
36 |
// Lightweight HTTP server for static content |
|
37 |
'webfs' => array("addHTTPTest", array()), |
|
38 |
|
|
39 |
// High performance HTTP 1.1 webserver written by Erlang |
|
40 |
'yaws' => array("addHTTPTest", array()), |
|
41 |
|
|
42 |
// HTTP server that runs on Emacsen |
|
43 |
'elserv' => array("addHTTPTest", array()), |
|
44 |
|
|
45 |
// Fast and very simple Ruby web server |
|
46 |
'thin' => array("addHTTPTest", array()), |
|
47 |
|
|
48 |
// Web server providing an HTTP interface to Redis |
|
49 |
'webdis' => array("addHTTPTest", array()), |
|
50 |
|
|
51 |
|
|
52 |
//'ntp'=> array("addNTPTest", array()), //Network Time Protocol deamon and utility programs |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* Connecteurs de Vigilo |
|
57 |
*/ |
|
58 |
// Vigilo module receiving and stocking metrology data |
|
59 |
'vigilo-connector-metro' => array("addVigiloConnectorTest", array("metro")), |
|
60 |
|
|
61 |
// Vigilo module sharing data with Nagios |
|
62 |
'vigilo-connector-nagios' => array("addVigiloConnectorTest", array("nagios")), |
|
63 |
|
|
64 |
'vigilo-connector-syncevent' => array("addVigiloConnectorTest", array("syncevent")), |
|
65 |
|
|
66 |
'vigilo-connector-vigiconf' => array("addVigiloConnectorTest", array("vigiconf")), |
|
67 |
|
|
68 |
|
|
69 |
/** |
|
70 |
* Nagios |
|
71 |
*/ |
|
72 |
// Host/service/network monitoring and management system (RHEL/CentOS) |
|
73 |
'nagios' => array("addNagiosTest", array()), |
|
74 |
|
|
75 |
// Host/service/network monitoring and management system (Debian) |
|
76 |
'nagios3' => array("addNagiosTest", array()), |
|
77 |
|
|
78 |
|
|
79 |
/** |
|
80 |
* Caches mémoires |
|
81 |
*/ |
|
82 |
// High-performance memory object caching system |
|
83 |
'memcached' => array("addMemcachedTest", array($computer)), |
|
84 |
|
|
85 |
//Memory object caching system with master/slave replication and server-side locking |
|
86 |
'yrmcds' => array("addMemcachedTest", array($computer)), |
|
87 |
|
|
88 |
//Data caching daemon for RRDtool |
|
89 |
'rrdcached' => array("addRRDcachedTest", array($computer)), |
|
90 |
|
|
91 |
|
|
92 |
/** |
|
93 |
* Serveurs SSH |
|
94 |
*/ |
|
95 |
// Secure shell (SSH) server, for secure access from remote machines |
|
96 |
'openssh-server' => array("addSSHTest", array()), |
|
97 |
|
|
98 |
// Secure shell client and server (metapackage) |
|
99 |
'ssh' => array("addSSHTest", array()), |
|
100 |
|
|
101 |
|
|
102 |
/** |
|
103 |
* Bases de données |
|
104 |
*/ |
|
105 |
// MariaDB database server |
|
106 |
'mariadb-server' => array("addPGSQLTest", array($computer)), |
|
107 |
|
|
108 |
// MySQL database server |
|
109 |
'mysql-server' => array("addPGSQLTest", array($computer)), |
|
110 |
|
|
111 |
|
|
112 |
/** |
|
113 |
* Serveurs mandataires |
|
114 |
*/ |
|
115 |
// Really small HTTP/HTTPS proxy |
|
116 |
'micro-proxy' => array("addProxyTest", array($computer)), |
|
117 |
|
|
118 |
// NTLM Authorization Proxy Server |
|
119 |
'ntlmaps' => array("addProxyTest", array($computer)), |
|
120 |
|
|
121 |
// Privacy enhancing HTTP Proxy |
|
122 |
'privoxy' => array("addProxyTest", array($computer)), |
|
123 |
|
|
124 |
// Full featured Web Proxy cache (HTTP proxy) |
|
125 |
'squid3' => array("addProxyTest", array($computer)), |
|
126 |
|
|
127 |
// A lightweight, non-caching, optionally anonymizing HTTP proxy |
|
128 |
'tinyproxy' => array("addProxyTest", array($computer)), |
|
129 |
); |
|
44 | 130 |
} |
src/Vigilo/VigiloTestSoftware.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
include 'VigiloSoftwareList.php'; |
|
4 |
|
|
5 | 3 |
class VigiloTestSoftware |
6 | 4 |
{ |
7 | 5 |
protected $testTable; |
... | ... | |
24 | 22 |
|
25 | 23 |
public function addRelevantTestWith($softwareName) |
26 | 24 |
{ |
27 |
if (strstr($softwareName, "vigilo-test")) |
|
28 |
{ |
|
29 |
$functionArray=array("addCustomTest", array($softwareName)); |
|
30 |
} |
|
31 |
else |
|
32 |
{ |
|
25 |
if (strstr($softwareName, "vigilo-test")) { |
|
26 |
$functionArray = array("addCustomTest", array($softwareName)); |
|
27 |
} else { |
|
33 | 28 |
if (!array_key_exists($softwareName, $this->softwareBase)) { |
34 | 29 |
return; |
35 | 30 |
} |
36 |
$functionArray=$this->softwareBase[$softwareName];
|
|
31 |
$functionArray = $this->softwareBase[$softwareName];
|
|
37 | 32 |
} |
38 |
$this->testTable[]=call_user_func_array(array($this,$functionArray[0]), $functionArray[1]);
|
|
33 |
$this->testTable[] = call_user_func_array(array($this, $functionArray[0]), $functionArray[1]);
|
|
39 | 34 |
} |
40 | 35 |
|
41 | 36 |
protected function addCustomTest($softwareName) |
42 | 37 |
{ |
43 | 38 |
$software_name = str_replace('vigilo-test-', '', $softwareName); |
44 | 39 |
$explode_software_name = explode('-', $software_name, 2); |
45 |
$args=array();
|
|
46 |
switch(strtolower($explode_software_name[0])) |
|
47 |
{ |
|
40 |
$args = array();
|
|
41 |
|
|
42 |
switch (strtolower($explode_software_name[0])) {
|
|
48 | 43 |
case "process": |
49 |
$args[]=new VigiloArg('processname', $explode_software_name[1]);
|
|
44 |
$args[] = new VigiloArg('processname', $explode_software_name[1]);
|
|
50 | 45 |
$explode_software_name[0] = "Process"; |
51 | 46 |
break; |
47 |
|
|
52 | 48 |
case "service": |
53 |
$args[]=new VigiloArg('svcname', $explode_software_name[1]);
|
|
49 |
$args[] = new VigiloArg('svcname', $explode_software_name[1]);
|
|
54 | 50 |
$explode_software_name[0] = "Service"; |
55 | 51 |
break; |
52 |
|
|
56 | 53 |
case "tcp": |
57 |
$args[]=new VigiloArg('port', $explode_software_name[1]);
|
|
54 |
$args[] = new VigiloArg('port', $explode_software_name[1]);
|
|
58 | 55 |
$explode_software_name[0] = "TCP"; |
59 | 56 |
break; |
60 |
default: return; |
|
57 |
|
|
58 |
default: |
|
59 |
return; |
|
61 | 60 |
} |
62 | 61 |
|
63 | 62 |
return new VigiloTest($explode_software_name[0], $args); |
... | ... | |
65 | 64 |
|
66 | 65 |
protected function addNTPTest() |
67 | 66 |
{ |
68 |
$args=array();
|
|
67 |
$args = array();
|
|
69 | 68 |
//$address=0; |
70 |
//$args[]=new VigiloArg('address',$address);
|
|
71 |
$args[]=new VigiloArg('crit', 0);
|
|
72 |
$args[]=new VigiloArg('warn', 0);
|
|
69 |
//$args[] = new VigiloArg('address', $address);
|
|
70 |
$args[] = new VigiloArg('crit', 0);
|
|
71 |
$args[] = new VigiloArg('warn', 0);
|
|
73 | 72 |
return new VigiloTest('NTP', $args); |
74 | 73 |
} |
75 | 74 |
|
76 | 75 |
protected function addNTPqTest() |
77 | 76 |
{ |
78 | 77 |
$args=array(); |
79 |
$args[]=new VigiloArg('crit', 2000);
|
|
80 |
$args[]=new VigiloArg('warn', 5000);
|
|
78 |
$args[] = new VigiloArg('crit', 2000);
|
|
79 |
$args[] = new VigiloArg('warn', 5000);
|
|
81 | 80 |
return new VigiloTest('NTPq', $args); |
82 | 81 |
} |
83 | 82 |
|
... | ... | |
94 | 93 |
protected function addMemcachedTest($computer) |
95 | 94 |
{ |
96 | 95 |
$args=array(); |
97 |
$args[]=new VigiloArg('port', 11211);
|
|
96 |
$args[] = new VigiloArg('port', 11211);
|
|
98 | 97 |
return new VigiloTest('Memcached', $args); |
99 | 98 |
} |
100 | 99 |
|
... | ... | |
106 | 105 |
protected function addPGSQLTest($computer) |
107 | 106 |
{ |
108 | 107 |
$args=array(); |
109 |
$args[]=new VigiloArg('database',"postgres");
|
|
110 |
$args[]=new VigiloArg('port',5432);
|
|
111 |
$args[]=new VigiloArg('user',"postgres");
|
|
112 |
return new VigiloTest('PostgreSQLConnection',$args); |
|
108 |
$args[] = new VigiloArg('database', "postgres");
|
|
109 |
$args[] = new VigiloArg('port', 5432);
|
|
110 |
$args[] = new VigiloArg('user', "postgres");
|
|
111 |
return new VigiloTest('PostgreSQLConnection', $args);
|
|
113 | 112 |
} |
114 | 113 |
|
115 | 114 |
protected function addProxyTest() |
116 | 115 |
{ |
117 | 116 |
$args=array(); |
118 |
$args[]=new VigiloArg('auth',"False");
|
|
119 |
$args[]=new VigiloArg('port',8080);
|
|
120 |
$args[]=new VigiloArg('url',"http://www.google.fr");
|
|
121 |
return new VigiloTest('Proxy',$args); |
|
117 |
$args[] = new VigiloArg('auth', "False");
|
|
118 |
$args[] = new VigiloArg('port', 8080);
|
|
119 |
$args[] = new VigiloArg('url', "http://www.google.fr");
|
|
120 |
return new VigiloTest('Proxy', $args);
|
|
122 | 121 |
} |
123 | 122 |
|
124 | 123 |
protected function addRRDcachedTest($computer) |
125 | 124 |
{ |
126 | 125 |
$path="/var/lib/vigilo/connector-metro/rrdcached.sock"; |
127 | 126 |
$args=array(); |
128 |
$args[]=new VigiloArg('crit',0);
|
|
129 |
$args[]=new VigiloArg('path',$path);
|
|
130 |
$args[]=new VigiloArg('warn',0);
|
|
131 |
return new VigiloTest('RRDcached',$args); |
|
127 |
$args[] = new VigiloArg('crit', 0);
|
|
128 |
$args[] = new VigiloArg('path', $path);
|
|
129 |
$args[] = new VigiloArg('warn', 0);
|
|
130 |
return new VigiloTest('RRDcached', $args);
|
|
132 | 131 |
} |
133 | 132 |
|
134 | 133 |
protected function addSSHTest() |
... | ... | |
139 | 138 |
protected function addVigiloConnectorTest($type) |
140 | 139 |
{ |
141 | 140 |
$args=array(); |
142 |
$args[]=new VigiloArg('type', $type);
|
|
141 |
$args[] = new VigiloArg('type', $type);
|
|
143 | 142 |
return new VigiloTest('VigiloConnector', $args); |
144 | 143 |
} |
145 | 144 |
|
146 | 145 |
protected function addVigiloCorrelatorTest() |
147 | 146 |
{ |
148 | 147 |
$args=array(); |
149 |
//$args[]=new VigiloArg('rules','');
|
|
150 |
$args[]=new VigiloArg('servicename','vigilo-correlator');
|
|
151 |
return new VigiloTest('VigiloCorrelator',$args); |
|
148 |
//$args[] = new VigiloArg('rules', '');
|
|
149 |
$args[] = new VigiloArg('servicename', 'vigilo-correlator');
|
|
150 |
return new VigiloTest('VigiloCorrelator', $args);
|
|
152 | 151 |
} |
153 | 152 |
|
154 | 153 |
protected function addTestService($computer, $service) |
155 | 154 |
{ |
156 | 155 |
$args=array(); |
157 |
$args[]=new VigiloArg('svcname',$service);
|
|
158 |
return new VigiloTest('Service',$args); |
|
156 |
$args[] = new VigiloArg('svcname', $service);
|
|
157 |
return new VigiloTest('Service', $args);
|
|
159 | 158 |
} |
160 | 159 |
|
161 | 160 |
public function __toString() |
src/ajax/getVTValue.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
if (strpos(filter_input(INPUT_SERVER, "PHP_SELF"), "getVTValue.php")) { |
4 |
include(dirname(dirname(__DIR__)) . |
|
5 |
DIRECTORY_SEPARATOR . "inc" . |
|
6 |
DIRECTORY_SEPARATOR . "includes.php"); |
|
4 |
include(dirname(dirname(__DIR__)) .
|
|
5 |
DIRECTORY_SEPARATOR . "inc" .
|
|
6 |
DIRECTORY_SEPARATOR . "includes.php");
|
|
7 | 7 |
|
8 |
header("Content-Type: text/html; charset=UTF-8"); |
|
9 |
Html::header_nocache(); |
|
8 |
header("Content-Type: text/html; charset=UTF-8");
|
|
9 |
Html::header_nocache();
|
|
10 | 10 |
} |
11 | 11 |
|
12 | 12 |
if (!defined('GLPI_ROOT')) { |
13 |
die("Can not acces directly to this file"); |
|
13 |
die("Can not acces directly to this file");
|
|
14 | 14 |
} |
15 | 15 |
|
16 | 16 |
$ret = array(); |
... | ... | |
23 | 23 |
$ret['count'] = count($ret['results']); |
24 | 24 |
|
25 | 25 |
echo json_encode($ret); |
26 |
|
|
27 |
?> |
src/front/menu.php | ||
---|---|---|
5 | 5 |
DIRECTORY_SEPARATOR . "includes.php"); |
6 | 6 |
|
7 | 7 |
if (PluginVigiloMenu::canView()) { |
8 |
Html::header(__('Vigilo', 'vigilo'), $_SERVER["PHP_SELF"], "plugins", |
|
9 |
"PluginVigiloMenu", "menu"); |
|
8 |
Html::header( |
|
9 |
__('Vigilo', 'vigilo'), |
|
10 |
$_SERVER["PHP_SELF"], |
|
11 |
"plugins", |
|
12 |
"PluginVigiloMenu", |
|
13 |
"menu" |
|
14 |
); |
|
10 | 15 |
|
11 | 16 |
$res = null; |
12 | 17 |
$pipes = array(); |
... | ... | |
18 | 23 |
); |
19 | 24 |
$cmd = "/usr/bin/sudo -n /usr/bin/vigiconf deploy -f --debug"; |
20 | 25 |
$res = proc_open($cmd, $fds, $pipes); |
21 |
if (!is_resource($res)) |
|
26 |
if (!is_resource($res)) {
|
|
22 | 27 |
$res = false; |
28 |
} |
|
23 | 29 |
} |
24 | 30 |
PluginVigiloMenu::displayMenu($res, $pipes); |
25 | 31 |
} else { |
... | ... | |
27 | 33 |
} |
28 | 34 |
|
29 | 35 |
Html::footer(); |
30 |
|
src/hook.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
require __DIR__ . DIRECTORY_SEPARATOR .'autoloader.php'; |
|
4 |
|
|
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 saveHost($host, $dir_type) |
|
16 |
{ |
|
17 |
$dirs = array($this->confdir, $dir_type, "managed"); |
|
18 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
|
19 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
|
20 |
|
|
21 |
if (!file_exists($confdir)) { |
|
22 |
mkdir($confdir, 0770, true); |
|
23 |
} |
|
24 |
|
|
25 |
$res = file_put_contents($file, $host, LOCK_EX); |
|
26 |
if ($res !== false) { |
|
27 |
chgrp($file, "vigiconf"); |
|
28 |
chmod($file, 0660); |
|
29 |
} |
|
30 |
} |
|
31 |
|
|
32 |
public function updateGroups() |
|
33 |
{ |
|
34 |
$host = new VigiloLocation(); |
|
35 |
$this->saveHost($host, "groups"); |
|
36 |
} |
|
37 |
|
|
38 |
public function addComputer($computer) |
|
39 |
{ |
|
40 |
if ($computer->getField("is_template")==0) { |
|
41 |
global $DB; |
|
42 |
$template_id = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")); |
|
43 |
|
|
44 |
if(!empty($template_id)) { |
|
45 |
$query = "UPDATE glpi_computers |
|
46 |
SET vigilo_template = '" . PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")) . |
|
47 |
"' WHERE id = " . $computer->getField("id") . ";"; |
|
48 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
49 |
} |
|
50 |
|
|
51 |
$query = "UPDATE glpi_computers |
|
52 |
SET is_dynamic = ' 1 |
|
53 |
' WHERE id = " . $computer->getField("id") . ";"; |
|
54 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
55 |
|
|
56 |
$host = new VigiloHost($computer); |
|
57 |
$this->saveHost($host, "hosts"); |
|
58 |
} |
|
59 |
} |
|
60 |
|
|
61 |
public function addNetworkEquipment($networkequipment) |
|
62 |
{ |
|
63 |
if ($networkequipment->getField("is_template")==0) { |
|
64 |
global $DB; |
|
65 |
|
|
66 |
$host = new VigiloNetworkEquipment($networkequipment); |
|
67 |
$this->saveHost($host, "hosts"); |
|
68 |
} |
|
69 |
} |
|
70 |
|
|
71 |
public function addPrinter($printer) |
|
72 |
{ |
|
73 |
if ($printer->getField("is_template")==0) { |
|
74 |
global $DB; |
|
75 |
|
|
76 |
$host = new VigiloPrinter($printer); |
|
77 |
$this->saveHost($host, "hosts"); |
|
78 |
} |
|
79 |
} |
|
80 |
|
|
81 |
public function delete($computer) |
|
82 |
{ |
|
83 |
$this->unmonitor($computer->fields["name"]); |
|
84 |
} |
|
85 |
|
|
86 |
public function update($computer) |
|
87 |
{ |
|
88 |
global $PLUGIN_HOOKS, $DB; |
|
89 |
if (isset($computer->oldvalues["name"])) { |
|
90 |
$this->unmonitor($computer->oldvalues["name"]); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
public function updateComputer($computer) |
|
95 |
{ |
|
96 |
$this->update($computer); |
|
97 |
$this->addComputer($computer); |
|
98 |
} |
|
99 |
|
|
100 |
public function updateNetworkEquipment($networkEquipment) |
|
101 |
{ |
|
102 |
$this->update($networkEquipment); |
|
103 |
$this->addNetworkEquipment($networkEquipment); |
|
104 |
} |
|
105 |
|
|
106 |
public function updatePrinter($printer) |
|
107 |
{ |
|
108 |
$this->update($printer); |
|
109 |
$this->addPrinter($printer); |
|
110 |
} |
|
111 |
|
|
112 |
public function unmonitor($host) |
|
113 |
{ |
|
114 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
|
115 |
$filename = implode(DIRECTORY_SEPARATOR, $dirs); |
|
116 |
if (file_exists($filename)) |
|
117 |
{ |
|
118 |
unlink($filename); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
public function manageComputerSoftwareVersion($computer_software_version) |
|
123 |
{ |
|
124 |
global $DB; |
|
125 |
$computer=new Computer(); |
|
126 |
$computer->getFromDB($computer_software_version->getField("computers_id")); |
|
127 |
$this->updateComputer($computer); |
|
128 |
} |
|
129 |
|
|
130 |
public function manageSoftwares($software) |
|
131 |
{ |
|
132 |
global $DB; |
|
133 |
$softwareVer=new SoftwareVersion(); |
|
134 |
$idSoftwareVersion=$softwareVer->find('softwares_id=' . $software->getID()); |
|
135 |
foreach ($idSoftwareVersion as $idVersion) { |
|
136 |
if ($idVersion['id']) { |
|
137 |
$computerVer=new Computer_SoftwareVersion(); |
|
138 |
$goodField='softwareversions_id=' . $idVersion['id']; |
|
139 |
$updateComp=$computerVer->find($goodField); |
|
140 |
foreach ($updateComp as $idComputer) { |
|
141 |
if ($idComputer['computers_id'] != -1) { |
|
142 |
$computer=new Computer(); |
|
143 |
$computer->getFromDB($idComputer['computers_id']); |
|
144 |
$this->updateComputer($computer); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
public function manageDisks($disk) |
|
152 |
{ |
|
153 |
global $DB; |
|
154 |
$id=$disk->getField('computers_id'); |
|
155 |
$computer=new Computer(); |
|
156 |
$computer->getFromDB($id); |
|
157 |
$this->updateComputer($computer); |
|
158 |
} |
|
159 |
|
|
160 |
public function manageAddresses($address) |
|
161 |
{ |
|
162 |
global $DB; |
|
163 |
$id=$address->getField('mainitems_id'); |
|
164 |
$comp=new Computer(); |
|
165 |
$comp->getFromDB($id); |
|
166 |
$this->updateComputer($comp); |
|
167 |
} |
|
168 |
|
|
169 |
public function manageNetworks($network) |
|
170 |
{ |
|
171 |
global $DB; |
|
172 |
$id=$network->getField('items_id'); |
|
173 |
$itemtype = $network->getField('itemtype'); |
|
174 |
if ($itemtype === 'Computer') { |
|
175 |
$comp=new Computer(); |
|
176 |
$comp->getFromDB($id); |
|
177 |
$this->updateComputer($comp); |
|
178 |
} |
|
179 |
else if ($itemtype === 'NetworkEquipment') { |
|
180 |
$ne=new NetworkEquipment(); |
|
181 |
$ne->getFromDB($id); |
|
182 |
$this->updateNetworkEquipment($ne); |
|
183 |
} |
|
184 |
else if ($itemtype === 'Printer') { |
|
185 |
$printer=new Printer(); |
|
186 |
$printer->getFromDB($id); |
|
187 |
$this->updatePrinter($printer); |
|
188 |
} |
|
189 |
} |
|
190 |
|
|
191 |
public function plugin_vigilo_getAddSearchOptions($itemtype) |
|
192 |
{ |
|
193 |
$options = array(); |
|
194 |
if ($itemtype == 'Computer' or $itemtype == 'PluginVigiloComputer') |
|
195 |
{ |
|
196 |
$options['7007']['table'] = 'glpi_computers'; |
|
197 |
$options['7007']['field'] = 'vigilo_template'; |
|
198 |
$options['7007']['name'] = 'vigilo_template'; |
|
199 |
$options['7007']['massiveaction'] = 'TRUE'; |
|
200 |
$options['7007']['datatype'] = 'dropdown'; |
|
201 |
return $options; |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
3 |
require(__DIR__ . DIRECTORY_SEPARATOR . 'autoloader.php'); |
|
4 |
require(__DIR__ . DIRECTORY_SEPARATOR . 'Vigilo' . DIRECTORY_SEPARATOR . 'VigiloSoftwareList.php'); |
|
5 |
require(__DIR__ . DIRECTORY_SEPARATOR . 'vigilo_hooks.php'); |
src/inc/computer.class.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
if (!defined('GLPI_ROOT')) { |
|
4 |
die("Sorry. You can't access directly to this file"); |
|
5 |
} |
|
6 |
|
|
7 |
class PluginVigiloComputer extends Computer { |
|
8 |
static function showComputerInfo($item) { |
|
3 |
class PluginVigiloComputer extends Computer |
|
4 |
{ |
|
5 |
public static function showComputerInfo($item) |
|
6 |
{ |
|
9 | 7 |
global $CFG_GLPI; |
10 | 8 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
11 | 9 |
$value = $item->getField('vigilo_template'); |
12 | 10 |
if ($value === 'NULL') { |
13 |
$value = '-----'; |
|
11 |
$value = '-----';
|
|
14 | 12 |
} |
15 | 13 |
echo '<table class="tab_cadre_fixe tab_glpi" width="100%">'; |
16 | 14 |
echo '<tr class="tab_bg_1"><th colspan="4">Vigilo Template</th></tr>'; |
17 | 15 |
echo '<tr class="tab_bg_1">'; |
18 | 16 |
echo '<td>Vigilo Template</td>'; |
19 | 17 |
echo '<td>'; |
20 |
Dropdown::show('PluginVigiloComputer', array("name" => "vigilo_template", |
|
21 |
"emptylabel" => $value, |
|
22 |
"url" => $CFG_GLPI["root_doc"] . "/plugins/vigilo/ajax/getVTValue.php")); |
|
18 |
Dropdown::show( |
|
19 |
'PluginVigiloComputer', |
|
20 |
array( |
|
21 |
"name" => "vigilo_template", |
|
22 |
"emptylabel" => $value, |
|
23 |
"url" => $CFG_GLPI["root_doc"] . "/plugins/vigilo/ajax/getVTValue.php" |
|
24 |
) |
|
25 |
); |
|
23 | 26 |
$ret = array(); |
24 | 27 |
$tmp = PluginVigiloVigiloTemplate::getAllTemplates(); |
25 | 28 |
echo '</td></tr>'; |
26 | 29 |
echo '</table>'; |
27 |
return TRUE;
|
|
30 |
return true;
|
|
28 | 31 |
} |
29 | 32 |
|
30 |
function getSearchOptions() { |
|
33 |
public function getSearchOptions() |
|
34 |
{ |
|
31 | 35 |
global $CFG_GLPI; |
32 | 36 |
|
33 | 37 |
$computer = new Computer(); |
src/inc/menu.class.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
if (!defined('GLPI_ROOT')) { |
|
4 |
die("Sorry. You can't access directly to this file"); |
|
5 |
} |
|
6 |
|
|
7 |
|
|
8 | 3 |
class PluginVigiloMenu extends CommonGLPI |
9 | 4 |
{ |
10 | 5 |
const TIMEOUT = 30; |
... | ... | |
14 | 9 |
* |
15 | 10 |
* @param $nb integer number of item in the type (default 0) |
16 | 11 |
**/ |
17 |
static function getTypeName($nb=0) { |
|
12 |
public static function getTypeName($nb = 0) |
|
13 |
{ |
|
18 | 14 |
return 'Vigilo'; |
19 | 15 |
} |
20 | 16 |
|
21 |
static function canView() { |
|
17 |
public static function canView() |
|
18 |
{ |
|
22 | 19 |
return true; |
23 | 20 |
} |
24 | 21 |
|
25 |
static function canCreate() { |
|
22 |
public static function canCreate() |
|
23 |
{ |
|
26 | 24 |
return false; |
27 | 25 |
} |
28 | 26 |
|
29 |
static function getMenuName() { |
|
27 |
public static function getMenuName() |
|
28 |
{ |
|
30 | 29 |
return self::getTypeName(); |
31 | 30 |
} |
32 | 31 |
|
33 |
static function getAdditionalMenuOptions() { |
|
32 |
public static function getAdditionalMenuOptions() |
|
33 |
{ |
|
34 | 34 |
return array(); |
35 | 35 |
} |
36 | 36 |
|
37 |
static function getAdditionalMenuContent() { |
|
37 |
public static function getAdditionalMenuContent() |
|
38 |
{ |
|
38 | 39 |
return array(); |
39 | 40 |
} |
40 | 41 |
|
41 |
static function displayMenu($res, $pipes) { |
|
42 |
public static function displayMenu($res, $pipes) |
|
43 |
{ |
|
42 | 44 |
echo '<h1>Vigilo</h1><form method="post" action="?itemtype=vigilo">'; |
43 | 45 |
|
44 | 46 |
if (is_resource($res)) { |
... | ... | |
54 | 56 |
$nb = stream_select($read, $write, $exc, static::TIMEOUT, 0); |
55 | 57 |
|
56 | 58 |
// Error |
57 |
if ($nb === FALSE) {
|
|
59 |
if ($nb === false) {
|
|
58 | 60 |
echo "UNKNOWN ERROR\n"; |
59 | 61 |
break; |
60 | 62 |
} |
... | ... | |
69 | 71 |
break; |
70 | 72 |
} |
71 | 73 |
|
72 |
foreach ($read as $stream){ |
|
74 |
foreach ($read as $stream) {
|
|
73 | 75 |
echo htmlspecialchars(fread($stream, 1024), ENT_HTML5 | ENT_QUOTES, "utf-8"); |
74 | 76 |
}; |
75 | 77 |
|
76 | 78 |
flush(); |
77 |
if (feof($pipes[1])){ |
|
78 |
break; |
|
79 |
if (feof($pipes[1])) {
|
|
80 |
break;
|
|
79 | 81 |
} |
80 | 82 |
} while (1); |
81 | 83 |
|
... | ... | |
83 | 85 |
if ($info === false) { |
84 | 86 |
echo "ERROR: could not determine process status\n"; |
85 | 87 |
} else { |
86 |
if ($info["signaled"]) |
|
88 |
if ($info["signaled"]) {
|
|
87 | 89 |
echo "Command terminated by signal ${info['termsig']}\n"; |
88 |
if ($info["stopped"]) |
|
90 |
} |
|
91 |
if ($info["stopped"]) { |
|
89 | 92 |
echo "Command stopped by signal ${info['stopsig']}\n"; |
93 |
} |
|
90 | 94 |
echo "Command exited with return code ${info['exitcode']}\n"; |
91 | 95 |
} |
92 | 96 |
|
src/inc/vigilotemplate.class.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 |
if (!defined('GLPI_ROOT')) { |
|
4 |
die("Sorry. You can't access directly to this file"); |
|
5 |
} |
|
6 |
|
|
7 |
class PluginVigiloVigiloTemplate extends CommonDBTM { |
|
8 |
static function getAllTemplates() { |
|
3 |
class PluginVigiloVigiloTemplate extends CommonDBTM |
|
4 |
{ |
|
5 |
public static function getAllTemplates() |
|
6 |
{ |
|
9 | 7 |
$hosttdir = "/etc/vigilo/vigiconf/conf.d/hosttemplates"; |
10 | 8 |
$hosttemplates_files = scandir($hosttdir); |
11 | 9 |
$templates = array(); |
12 | 10 |
$pattern = "<template name=\"(\w*)\">"; |
13 | 11 |
|
14 |
foreach($hosttemplates_files as $file) { |
|
12 |
foreach ($hosttemplates_files as $file) {
|
|
15 | 13 |
$filepath = $hosttdir . DIRECTORY_SEPARATOR . $file; |
16 | 14 |
$test_filepath = preg_match("/(.*).xml$/", $filepath); |
17 | 15 |
|
18 |
if (is_file($filepath) AND !empty($test_filepath)) {
|
|
16 |
if (is_file($filepath) && !empty($test_filepath)) {
|
|
19 | 17 |
preg_match_all($pattern, file_get_contents($filepath), $matches); |
20 | 18 |
|
21 | 19 |
foreach ($matches[1] as $match) { |
... | ... | |
29 | 27 |
return $templates; |
30 | 28 |
} |
31 | 29 |
|
32 |
static function getAjaxArrayTemplates() {
|
|
33 |
|
|
30 |
public static function getAjaxArrayTemplates()
|
|
31 |
{ |
|
34 | 32 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
35 | 33 |
$id = 0; |
36 | 34 |
$ret = array(); |
37 | 35 |
|
38 |
foreach($templates as $t) { |
|
36 |
foreach ($templates as $t) {
|
|
39 | 37 |
$ret[] = array("id" => $id, "text" => $t); |
40 | 38 |
$id++; |
41 | 39 |
} |
... | ... | |
43 | 41 |
return $ret; |
44 | 42 |
} |
45 | 43 |
|
46 |
static function getVigiloTemplateNameByID($id) {
|
|
47 |
|
|
44 |
public static function getVigiloTemplateNameByID($id)
|
|
45 |
{ |
|
48 | 46 |
if (is_numeric($id)) { |
49 |
if ($id === '0') return "NULL"; |
|
47 |
if ($id === '0') { |
|
48 |
return "NULL"; |
|
49 |
} |
|
50 | 50 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
51 | 51 |
return $templates[$id]; |
52 | 52 |
} |
src/plugin.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
function plugin_init_vigilo() |
|
4 |
{ |
|
5 |
global $PLUGIN_HOOKS; |
|
6 |
global $DB; |
|
7 |
$hooks =& $PLUGIN_HOOKS; |
|
8 |
$p = "vigilo"; |
|
9 |
$hookObj = new VigiloHooks(); |
|
10 |
|
|
11 |
$hooks['csrf_compliant'][$p] = true; |
|
12 |
$hooks['item_add'][$p] = array("Computer" => array($hookObj, "addComputer"), |
|
13 |
"NetworkEquipment" => array($hookObj, "addNetworkEquipment"), |
|
14 |
"Printer" => array($hookObj, "addPrinter")); |
|
15 |
$hooks['item_update'][$p] = array("Computer" => array($hookObj, "updateComputer"), |
|
16 |
"NetworkEquipment" => array($hookObj, "updateNetworkEquipment"), |
|
17 |
"Printer" => array($hookObj, "updatePrinter")); |
|
18 |
$hooks['item_purge'][$p] = array("Computer" => array($hookObj, "delete"), |
|
19 |
"NetworkEquipment" => array($hookObj, "delete"), |
|
20 |
"Printer" => array($hookObj, "delete")); |
|
21 |
$hooks['item_delete'][$p] = array("Computer" => array($hookObj, "delete"), |
|
22 |
"NetworkEquipment" => array($hookObj, "delete"), |
|
23 |
"Printer" => array($hookObj, "delete")); |
|
24 |
$hooks['item_restore'][$p] = array("Computer" => array($hookObj, "addComputer"), |
|
25 |
"NetworkEquipment" => array($hookObj, "addNetworkEquipment"), |
|
26 |
"Printer" => array($hookObj, "addPrinter")); |
|
27 |
|
|
28 |
$events = array('item_add', 'item_update', 'item_purge', 'item_delete', 'item_restore'); |
|
29 |
foreach ($events as $event) { |
|
30 |
$hooks[$event][$p] += array( |
|
31 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
32 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
33 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
34 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
35 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
36 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
37 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
38 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
39 |
"Software" => array($hookObj,"manageSoftwares"), |
|
40 |
"Location" => array($hookObj,"updateGroups"), |
|
41 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
42 |
"Entity" => array($hookObj,"updateGroups"), |
|
43 |
"Manufacturer" => array($hookObj,"updateGroups"), |
|
44 |
); |
|
45 |
} |
|
46 |
|
|
47 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
|
48 |
$hooks['config_page'][$p] = 'front/menu.php?itemtype=vigilo'; |
|
49 |
$hooks['autoinventory_information'][$p] = array( |
|
50 |
'Computer' => array('PluginVigiloComputer', |
|
51 |
'showComputerInfo')); |
|
52 |
|
|
53 |
if (!FieldExists('glpi_computers', 'vigilo_template')) { |
|
54 |
$query = "ALTER TABLE glpi_computers ADD vigilo_template VARCHAR(30)"; |
|
55 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_computers"); |
|
56 |
} |
|
57 |
} |
|
58 |
|
|
59 |
function getSearchOptions() |
|
60 |
{ |
|
61 |
$computer = new Computer(); |
|
62 |
$options = $computer->getSearchOptions(); |
|
63 |
|
|
64 |
$options['vigilo'] = 'Vigilo Template'; |
|
65 |
|
|
66 |
$options['7007']['name'] = 'vigilo_template'; |
|
67 |
$options['7007']['table'] = 'glpi_computers'; |
|
68 |
$options['7007']['field'] = 'vigilo_template'; |
|
69 |
$options['7007']['searchtype'] = 'equals'; |
|
70 |
$options['7007']['datatype'] = 'dropdown'; |
|
71 |
|
|
72 |
return $options; |
|
73 |
} |
|
74 |
|
|
75 |
function plugin_version_vigilo() |
|
76 |
{ |
|
77 |
return array('name' => 'Vigilo monitoring', |
|
78 |
'version' => '0.1', |
|
79 |
'author' => 'CSSI', |
|
80 |
'license' => 'GPLv2+', |
|
81 |
'homepage' => 'http://vigilo-nms.org', |
|
82 |
'minGlpiVersion' => '9.1'); |
|
83 |
} |
|
84 |
|
|
85 |
function plugin_vigilo_check_config($verbose = false) |
|
86 |
{ |
|
87 |
if (version_compare(GLPI_VERSION, '9.1', 'lt')) { |
|
88 |
echo "This plugin requires GLPI >= 9.1"; |
|
89 |
return false; |
|
90 |
} |
|
91 |
return true; |
|
92 |
} |
|
93 |
|
|
94 |
function plugin_vigilo_check_prerequisites() |
|
95 |
{ |
|
96 |
return true; |
|
97 |
} |
|
98 |
|
|
99 |
function plugin_vigilo_install() |
|
100 |
{ |
|
101 |
return true; |
|
102 |
} |
|
103 |
|
|
104 |
function plugin_vigilo_uninstall() |
|
105 |
{ |
|
106 |
return true; |
|
107 |
} |
src/setup.php | ||
---|---|---|
1 | 1 |
<?php |
2 | 2 |
|
3 | 3 |
require(__DIR__ . DIRECTORY_SEPARATOR . "hook.php"); |
4 |
|
|
5 |
function plugin_init_vigilo() |
|
6 |
{ |
|
7 |
global $PLUGIN_HOOKS; |
|
8 |
global $DB; |
|
9 |
$hooks =& $PLUGIN_HOOKS; |
|
10 |
$p = "vigilo"; |
|
11 |
$hookObj = new VigiloHooks(); |
|
12 |
$hooks['csrf_compliant'][$p] = true; |
|
13 |
$hooks['item_add'][$p] = array("Computer" => array($hookObj, "addComputer"), |
|
14 |
"NetworkEquipment" => array($hookObj, "addNetworkEquipment"), |
|
15 |
"Printer" => array($hookObj, "addPrinter"), |
|
16 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
17 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
18 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
19 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
20 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
21 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
22 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
23 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
24 |
"Software" => array($hookObj,"manageSoftwares"), |
|
25 |
"Location" => array($hookObj,"updateGroups"), |
|
26 |
"Entity" => array($hookObj,"updateGroups"), |
|
27 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
28 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
29 |
$hooks['item_update'][$p] = array("Computer" => array($hookObj, "updateComputer"), |
|
30 |
"NetworkEquipment" => array($hookObj, "updateNetworkEquipment"), |
|
31 |
"Printer" => array($hookObj, "updatePrinter"), |
|
32 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
33 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
34 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
35 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
36 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
37 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
38 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
39 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
40 |
"Software" => array($hookObj,"manageSoftwares"), |
|
41 |
"Location" => array($hookObj,"updateGroups"), |
|
42 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
43 |
"Entity" => array($hookObj,"updateGroups"), |
|
44 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
45 |
$hooks['item_purge'][$p] = array("Computer" => array($hookObj, "delete"), |
|
46 |
"NetworkEquipment" => array($hookObj, "delete"), |
|
47 |
"Printer" => array($hookObj, "delete"), |
|
48 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
49 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
50 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
51 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
52 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
53 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
54 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
55 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
56 |
"Software" => array($hookObj,"manageSoftwares"), |
|
57 |
"Location" => array($hookObj,"updateGroups"), |
|
58 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
59 |
"Entity" => array($hookObj,"updateGroups"), |
|
60 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
61 |
$hooks['item_delete'][$p] = array("Computer" => array($hookObj, "delete"), |
|
62 |
"NetworkEquipment" => array($hookObj, "delete"), |
|
63 |
"Printer" => array($hookObj, "delete"), |
|
64 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
65 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
66 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
67 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
68 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
69 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
70 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
71 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
72 |
"Software" => array($hookObj,"manageSoftwares"), |
|
73 |
"Location" => array($hookObj,"updateGroups"), |
|
74 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
75 |
"Entity" => array($hookObj,"updateGroups"), |
|
76 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
77 |
$hooks['item_restore'][$p] = array("Computer" => array($hookObj, "addComputer"), |
|
78 |
"NetworkEquipment" => array($hookObj, "addNetworkEquipment"), |
|
79 |
"Printer" => array($hookObj, "addPrinter"), |
|
80 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
|
81 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
|
82 |
"IPAddress" => array($hookObj,"manageAddresses"), |
|
83 |
"DeviceProcessor" => array($hookObj,"manageNetworks"), |
|
84 |
"DeviceMemory" => array($hookObj,"manageNetworks"), |
|
85 |
"DeviceHardDrive" => array($hookObj,"manageNetworks"), |
|
86 |
"DeviceControl" => array($hookObj,"manageNetworks"), |
|
87 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
|
88 |
"Software" => array($hookObj,"manageSoftwares"), |
|
89 |
"Location" => array($hookObj,"updateGroups"), |
|
90 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"), |
|
91 |
"Entity" => array($hookObj,"updateGroups"), |
|
92 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
93 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
|
94 |
$hooks['config_page'][$p] = 'front/menu.php?itemtype=vigilo'; |
|
95 |
$hooks['autoinventory_information'][$p] = array( |
|
96 |
'Computer' => array('PluginVigiloComputer', |
|
97 |
'showComputerInfo')); |
|
98 |
|
|
99 |
if (!FieldExists('glpi_computers', 'vigilo_template')) |
|
100 |
{ |
|
101 |
$query = "ALTER TABLE glpi_computers ADD vigilo_template VARCHAR(30)"; |
|
102 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_computers"); |
|
103 |
} |
|
104 |
} |
|
105 |
|
|
106 |
function getSearchOptions() { |
|
107 |
$computer = new Computer(); |
|
108 |
$options = $computer->getSearchOptions(); |
|
109 |
|
|
110 |
$options['vigilo'] = 'Vigilo Template'; |
|
111 |
|
|
112 |
$options['7007']['name'] = 'vigilo_template'; |
|
113 |
$options['7007']['table'] = 'glpi_computers'; |
|
114 |
$options['7007']['field'] = 'vigilo_template'; |
|
115 |
$options['7007']['searchtype'] = 'equals'; |
|
116 |
$options['7007']['datatype'] = 'dropdown'; |
|
117 |
|
|
118 |
return $options; |
|
119 |
} |
|
120 |
|
|
121 |
function plugin_version_vigilo() |
|
122 |
{ |
|
123 |
return array('name' => 'Vigilo monitoring', |
|
124 |
'version' => '0.1', |
|
125 |
'author' => 'CSSI', |
|
126 |
'license' => 'GPLv2+', |
|
127 |
'homepage' => 'http://vigilo-nms.org', |
|
128 |
'minGlpiVersion' => '9.1'); |
|
129 |
} |
|
130 |
|
|
131 |
function plugin_vigilo_check_config($verbose = false) |
|
132 |
{ |
|
133 |
if (version_compare(GLPI_VERSION, '9.1', 'lt')) { |
|
134 |
echo "This plugin requires GLPI >= 9.1"; |
|
135 |
return false; |
|
136 |
} |
|
137 |
return true; |
|
138 |
} |
|
139 |
|
|
140 |
function plugin_vigilo_check_prerequisites() |
|
141 |
{ |
|
142 |
return true; |
|
143 |
} |
|
144 |
|
|
145 |
function plugin_vigilo_install() |
|
146 |
{ |
|
147 |
return true; |
|
148 |
} |
|
149 |
|
|
150 |
function plugin_vigilo_uninstall() |
|
151 |
{ |
|
152 |
return true; |
|
153 |
} |
|
4 |
require(__DIR__ . DIRECTORY_SEPARATOR . "plugin.php"); |
src/vigilo_hooks.php | ||
---|---|---|
1 |
<?php |
|
2 |
|
|
3 |
class VigiloHooks |
|
4 |
{ |
|
5 |
private $confdir; |
|
6 |
|
|
7 |
public function __construct($confdir = "/etc/vigilo/vigiconf/conf.d") |
|
8 |
{ |
|
9 |
spl_autoload_register('vigilo_autoloader'); |
|
10 |
$this->confdir = $confdir; |
|
11 |
} |
|
12 |
|
|
13 |
public function saveHost($host, $dir_type) |
|
14 |
{ |
|
15 |
$dirs = array($this->confdir, $dir_type, "managed"); |
|
16 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
|
17 |
$file = $confdir . DIRECTORY_SEPARATOR . $host->getName() . ".xml"; |
|
18 |
|
|
19 |
if (!file_exists($confdir)) { |
|
20 |
mkdir($confdir, 0770, true); |
|
21 |
} |
|
22 |
|
|
23 |
$res = file_put_contents($file, $host, LOCK_EX); |
|
24 |
if ($res !== false) { |
|
25 |
chgrp($file, "vigiconf"); |
|
26 |
chmod($file, 0660); |
|
27 |
} |
|
28 |
} |
|
29 |
|
|
30 |
public function updateGroups() |
|
31 |
{ |
|
32 |
$host = new VigiloLocation(); |
|
33 |
$this->saveHost($host, "groups"); |
|
34 |
} |
|
35 |
|
|
36 |
public function addComputer($computer) |
|
37 |
{ |
|
38 |
global $DB; |
|
39 |
|
|
40 |
if ($computer->getField("is_template") == 0) { |
|
41 |
$template_id = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID( |
|
42 |
$computer->getField("vigilo_template") |
|
43 |
); |
|
44 |
|
|
45 |
if (!empty($template_id)) { |
|
46 |
$query = "UPDATE glpi_computers |
|
47 |
SET vigilo_template = '" . $template_id . |
|
48 |
"' WHERE id = " . $computer->getField("id") . ";"; |
|
49 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
50 |
} |
|
51 |
|
|
52 |
$query = "UPDATE glpi_computers |
|
53 |
SET is_dynamic = ' 1 |
|
54 |
' WHERE id = " . $computer->getField("id") . ";"; |
|
55 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
56 |
|
|
57 |
$host = new VigiloHost($computer); |
|
58 |
$this->saveHost($host, "hosts"); |
|
59 |
} |
|
60 |
} |
|
61 |
|
|
62 |
public function addNetworkEquipment($networkequipment) |
|
63 |
{ |
|
64 |
if ($networkequipment->getField("is_template") == 0) { |
|
65 |
global $DB; |
|
66 |
|
|
67 |
$host = new VigiloNetworkEquipment($networkequipment); |
|
68 |
$this->saveHost($host, "hosts"); |
|
69 |
} |
|
70 |
} |
|
71 |
|
|
72 |
public function addPrinter($printer) |
|
73 |
{ |
|
74 |
if ($printer->getField("is_template") == 0) { |
|
75 |
global $DB; |
|
76 |
|
|
77 |
$host = new VigiloPrinter($printer); |
|
78 |
$this->saveHost($host, "hosts"); |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
public function delete($computer) |
|
83 |
{ |
|
84 |
$this->unmonitor($computer->fields["name"]); |
|
85 |
} |
|
86 |
|
|
87 |
public function update($computer) |
|
88 |
{ |
|
89 |
global $PLUGIN_HOOKS, $DB; |
|
90 |
if (isset($computer->oldvalues["name"])) { |
|
91 |
$this->unmonitor($computer->oldvalues["name"]); |
|
92 |
} |
|
93 |
} |
|
94 |
|
|
95 |
public function updateComputer($computer) |
|
96 |
{ |
|
97 |
$this->update($computer); |
|
98 |
$this->addComputer($computer); |
|
99 |
} |
|
100 |
|
|
101 |
public function updateNetworkEquipment($networkEquipment) |
|
102 |
{ |
|
103 |
$this->update($networkEquipment); |
|
104 |
$this->addNetworkEquipment($networkEquipment); |
|
105 |
} |
|
106 |
|
|
107 |
public function updatePrinter($printer) |
|
108 |
{ |
|
109 |
$this->update($printer); |
|
110 |
$this->addPrinter($printer); |
|
111 |
} |
|
112 |
|
|
113 |
public function unmonitor($host) |
|
114 |
{ |
|
115 |
$dirs = array($this->confdir, "hosts", "managed", $host . ".xml"); |
|
116 |
$filename = implode(DIRECTORY_SEPARATOR, $dirs); |
|
117 |
if (file_exists($filename)) { |
|
118 |
unlink($filename); |
|
119 |
} |
|
120 |
} |
|
121 |
|
|
122 |
public function manageComputerSoftwareVersion($computer_software_version) |
|
123 |
{ |
|
124 |
global $DB; |
|
125 |
$computer=new Computer(); |
|
126 |
$computer->getFromDB($computer_software_version->getField("computers_id")); |
|
127 |
$this->updateComputer($computer); |
|
128 |
} |
|
129 |
|
|
130 |
public function manageSoftwares($software) |
|
131 |
{ |
|
132 |
global $DB; |
|
133 |
$softwareVer=new SoftwareVersion(); |
|
134 |
$idSoftwareVersion=$softwareVer->find('softwares_id=' . $software->getID()); |
|
135 |
foreach ($idSoftwareVersion as $idVersion) { |
|
136 |
if ($idVersion['id']) { |
|
137 |
$computerVer=new Computer_SoftwareVersion(); |
|
138 |
$goodField='softwareversions_id=' . $idVersion['id']; |
|
139 |
$updateComp=$computerVer->find($goodField); |
|
140 |
foreach ($updateComp as $idComputer) { |
|
141 |
if ($idComputer['computers_id'] != -1) { |
|
142 |
$computer=new Computer(); |
|
143 |
$computer->getFromDB($idComputer['computers_id']); |
|
144 |
$this->updateComputer($computer); |
|
145 |
} |
|
146 |
} |
|
147 |
} |
|
148 |
} |
|
149 |
} |
|
150 |
|
|
151 |
public function manageDisks($disk) |
|
152 |
{ |
|
153 |
global $DB; |
|
154 |
$id=$disk->getField('computers_id'); |
|
155 |
$computer=new Computer(); |
|
156 |
$computer->getFromDB($id); |
|
157 |
$this->updateComputer($computer); |
|
158 |
} |
|
159 |
|
|
160 |
public function manageAddresses($address) |
|
161 |
{ |
|
162 |
global $DB; |
|
163 |
$id = $address->getField('mainitems_id'); |
|
164 |
$comp = new Computer(); |
|
165 |
$comp->getFromDB($id); |
|
166 |
$this->updateComputer($comp); |
|
167 |
} |
|
168 |
|
|
169 |
public function manageNetworks($network) |
|
170 |
{ |
|
171 |
global $DB; |
|
172 |
$id = $network->getField('items_id'); |
|
173 |
$itemtype = $network->getField('itemtype'); |
|
174 |
if ($itemtype === 'Computer') { |
|
175 |
$comp = new Computer(); |
|
176 |
$comp->getFromDB($id); |
|
177 |
$this->updateComputer($comp); |
|
178 |
} elseif ($itemtype === 'NetworkEquipment') { |
|
179 |
$ne = new NetworkEquipment(); |
|
180 |
$ne->getFromDB($id); |
|
181 |
$this->updateNetworkEquipment($ne); |
|
182 |
} elseif ($itemtype === 'Printer') { |
|
183 |
$printer = new Printer(); |
|
184 |
$printer->getFromDB($id); |
|
185 |
$this->updatePrinter($printer); |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
// @codingStandardsIgnoreStart |
|
190 |
public function plugin_vigilo_getAddSearchOptions($itemtype) |
|
191 |
{ |
|
192 |
// Le nom de la méthode est imposé par GLPI. |
|
193 |
// @codingStandardsIgnoreEnd |
|
194 |
$options = array(); |
|
195 |
if ($itemtype == 'Computer' || $itemtype == 'PluginVigiloComputer') { |
|
196 |
$options['7007']['table'] = 'glpi_computers'; |
|
197 |
$options['7007']['field'] = 'vigilo_template'; |
|
198 |
$options['7007']['name'] = 'vigilo_template'; |
|
199 |
$options['7007']['massiveaction'] = 'TRUE'; |
|
200 |
$options['7007']['datatype'] = 'dropdown'; |
|
201 |
} |
|
202 |
return $options; |
|
203 |
} |
|
204 |
} |
Also available in: Unified diff