glpi / src / plugins / vigilo / plugin.php @ 0ff49d9f
History | View | Annotate | Download (4.67 KB)
1 |
<?php
|
---|---|
2 |
|
3 |
define('VIGILO_MIN_GLPI_VERSION', '9.1.1'); |
4 |
|
5 |
function plugin_init_vigilo() |
6 |
{ |
7 |
global $PLUGIN_HOOKS; |
8 |
global $DB; |
9 |
|
10 |
$hooks =& $PLUGIN_HOOKS; |
11 |
$p = "vigilo"; |
12 |
$hookObj = new VigiloHooks(); |
13 |
|
14 |
$hooks['csrf_compliant'][$p] = true; |
15 |
|
16 |
foreach (array("Computer", "Printer", "NetworkEquipment") as $itemtype) { |
17 |
$hooks['pre_item_update'][$p][$itemtype] = array($hookObj, "preItemUpdate"); |
18 |
$hooks['item_add'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
19 |
$hooks['item_update'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
20 |
$hooks['item_restore'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
21 |
$hooks['item_delete'][$p][$itemtype] = array($hookObj, "itemPurge"); |
22 |
$hooks['item_purge'][$p][$itemtype] = array($hookObj, "itemPurge"); |
23 |
} |
24 |
|
25 |
$events = array('item_add', 'item_update', 'item_purge', 'item_delete', 'item_restore'); |
26 |
foreach ($events as $event) { |
27 |
$hooks[$event][$p] += array( |
28 |
"IPAddress" => array($hookObj, "refreshAddress"), |
29 |
"ComputerDisk" => array($hookObj, "refreshDisk"), |
30 |
"NetworkPort" => array($hookObj, "refreshDevice"), |
31 |
"DeviceProcessor" => array($hookObj, "refreshDevice"), |
32 |
"DeviceMemory" => array($hookObj, "refreshDevice"), |
33 |
"DeviceHardDrive" => array($hookObj, "refreshDevice"), |
34 |
"DeviceControl" => array($hookObj, "refreshDevice"), |
35 |
"DeviceSoundCard" => array($hookObj, "refreshDevice"), |
36 |
"Software" => array($hookObj, "refreshSoftware"), |
37 |
"Computer_SoftwareVersion" => array($hookObj, "refreshSoftwareVersion"), |
38 |
"Location" => array($hookObj, "updateGroups"), |
39 |
"Entity" => array($hookObj, "updateGroups"), |
40 |
"Manufacturer" => array($hookObj, "updateGroups"), |
41 |
); |
42 |
} |
43 |
|
44 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
45 |
$hooks['config_page'][$p] = 'front/menu.php'; |
46 |
$hooks['post_item_form'][$p] = array('PluginVigiloTemplate', 'showForm'); |
47 |
} |
48 |
|
49 |
function plugin_version_vigilo() |
50 |
{ |
51 |
return array('name' => 'Vigilo monitoring', |
52 |
'version' => '0.1', |
53 |
'author' => 'CSSI', |
54 |
'license' => 'GPLv2+', |
55 |
'homepage' => 'http://vigilo-nms.org', |
56 |
'minGlpiVersion' => VIGILO_MIN_GLPI_VERSION); |
57 |
} |
58 |
|
59 |
function plugin_vigilo_check_config($verbose = false) |
60 |
{ |
61 |
if (version_compare(GLPI_VERSION, VIGILO_MIN_GLPI_VERSION, 'lt')) { |
62 |
echo "This plugin requires GLPI >= " . VIGILO_MIN_GLPI_VERSION; |
63 |
return false; |
64 |
} |
65 |
return true; |
66 |
} |
67 |
|
68 |
function plugin_vigilo_check_prerequisites() |
69 |
{ |
70 |
return true; |
71 |
} |
72 |
|
73 |
function plugin_vigilo_install() |
74 |
{ |
75 |
global $DB; |
76 |
|
77 |
if (!TableExists('glpi_plugin_vigilo_template')) { |
78 |
$query = <<<SQL |
79 |
CREATE TABLE `glpi_plugin_vigilo_template` (
|
80 |
`id` int(11) NOT NULL default '0',
|
81 |
`template` varchar(255) collate utf8_unicode_ci default NULL,
|
82 |
PRIMARY KEY (`id`)
|
83 |
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
84 |
SQL;
|
85 |
$DB->query($query) or die($DB->error()); |
86 |
} |
87 |
|
88 |
if (!TableExists('glpi_plugin_vigilo_config')) { |
89 |
$query = <<<SQL |
90 |
CREATE TABLE `glpi_plugin_vigilo_config` (
|
91 |
`key` varchar(255) collate utf8_unicode_ci NOT NULL,
|
92 |
`value` varchar(255) collate utf8_unicode_ci NULL,
|
93 |
PRIMARY KEY (`key`)
|
94 |
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
95 |
SQL;
|
96 |
$DB->query($query) or die($DB->error()); |
97 |
|
98 |
$query = "INSERT INTO `glpi_plugin_vigilo_config` VALUES('needs_deploy', 0);"; |
99 |
$DB->query($query) or die($DB->error()); |
100 |
} |
101 |
|
102 |
return true; |
103 |
} |
104 |
|
105 |
function plugin_vigilo_uninstall() |
106 |
{ |
107 |
global $DB; |
108 |
|
109 |
foreach (array('template', 'deployment') as $table) { |
110 |
$DB->query("DROP TABLE IF EXISTS `glpi_plugin_vigilo_$table`;"); |
111 |
} |
112 |
|
113 |
return true; |
114 |
} |
115 |
|
116 |
// @codingStandardsIgnoreStart
|
117 |
function plugin_vigilo_getAddSearchOptions($itemtype) |
118 |
{ |
119 |
// Le nom de la méthode est imposé par GLPI.
|
120 |
// @codingStandardsIgnoreEnd
|
121 |
$options = array(); |
122 |
|
123 |
if (!in_array($itemtype, array('Computer', 'NetworkEquipment', 'Printer'))) { |
124 |
return $options; |
125 |
} |
126 |
|
127 |
$options[7007]['table'] = 'glpi_plugin_vigilo_template'; |
128 |
$options[7007]['field'] = 'template'; |
129 |
$options[7007]['linkfield'] = 'id'; |
130 |
$options[7007]['name'] = 'Template Vigilo'; |
131 |
$options[7007]['massiveaction'] = true; |
132 |
$options[7007]['datatype'] = 'dropdown'; |
133 |
|
134 |
return $options; |
135 |
} |