-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhook.php
126 lines (113 loc) · 4.1 KB
/
hook.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
/**
* -------------------------------------------------------------------------
* Centreon plugin for GLPI
* -------------------------------------------------------------------------
*
* LICENSE
*
* This file is part of Centreon.
*
* Centreon is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Centreon is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Centreon. If not, see <http://www.gnu.org/licenses/>.
* -------------------------------------------------------------------------
* @copyright Copyright (C) 2022-2023 by Centreon plugin team.
* @license GPLv3 https://www.gnu.org/licenses/gpl-3.0.html
* @link https://github.com/pluginsGLPI/centreon
* -------------------------------------------------------------------------
*/
use GlpiPlugin\Centreon\Host;
use GLPIKey;
/**
* Plugin install process
*
* @return boolean
*/
function plugin_centreon_install($version)
{
/** @var DBmysql $DB */
global $DB;
$default_charset = DBConnection::getDefaultCharset();
$default_collation = DBConnection::getDefaultCollation();
$table = GlpiPlugin\Centreon\Host::getTable();
if (!$DB->tableExists($table)) {
$query = "CREATE TABLE `$table` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
`itemtype` VARCHAR(100) NOT NULL,
`items_id` INT(10) UNSIGNED NOT NULL DEFAULT '0',
`centreon_id` INT(10) NOT NULL,
`centreon_type` VARCHAR(100) DEFAULT 'host',
PRIMARY KEY (`id`),
KEY `items_id` (`items_id`)
) ENGINE=InnoDB
DEFAULT CHARSET={$default_charset}
COLLATE={$default_collation}";
$DB->queryOrDie($query, $DB->error());
}
$centreon_password = Config::getConfigurationValue('plugin:centreon', 'centreon-password');
/**Migration to 1.0.1 */
if ($centreon_password !== null) {
/** Check if pwd is already encrypted, if not, it returns empty string */
/** It's not necessary to encrypt again, because setConfigurationValues() check
* if the value is in secured_configs and if yes, and encrypt it
*/
$decrypted_pwd = @(new GLPIKey())->decrypt($centreon_password);
if ($decrypted_pwd == '') {
Config::setConfigurationValues('plugin:centreon', [
'centreon-password' => $centreon_password,
]);
}
}
return true;
}
/**
* Plugin uninstall process
*
* @return boolean
*/
function plugin_centreon_uninstall()
{
/** @var DBmysql $DB */
global $DB;
$tables = [GlpiPlugin\Centreon\Host::getTable(), ];
foreach ($tables as $table) {
$migration = new Migration(PLUGIN_CENTREON_VERSION);
$migration->displayMessage("Uninstalling $table");
$migration->dropTable($table);
$DB->error();
}
$config = new \Config();
$config->deleteByCriteria(['context' => 'plugin:centreon']);
return true;
}
function plugin_centreon_getAddSearchOptionsNew($itemtype)
{
$sopt = [];
if ($itemtype == 'Computer') {
$sopt[] = [
'id' => 2023,
'table' => GlpiPlugin\Centreon\Host::getTable(),
'field' => 'id',
'name' => __('Centreon Host Status', 'centreon'),
'additionalfields' => ['centreon_id'],
'datatype' => 'specific',
'nosearch' => true,
'nosort' => true,
'massiveaction' => false,
'joinparams' => [
'jointype' => 'itemtype_item',
],
];
}
return $sopt;
}