glpi / src / plugins / vigilo / plugin.php @ f1634ea8
History | View | Annotate | Download (5.32 KB)
1 | 166be9d2 | Francois POIROTTE | <?php
|
---|---|---|---|
2 | |||
3 | 22269799 | Francois POIROTTE | /* GLPI 9.1.2+ est nécessaire pour disposer du hook "post_show_item". */
|
4 | define('VIGILO_MIN_GLPI_VERSION', '9.1.2'); |
||
5 | 166be9d2 | Francois POIROTTE | |
6 | function plugin_init_vigilo() |
||
7 | { |
||
8 | global $PLUGIN_HOOKS; |
||
9 | global $DB; |
||
10 | |||
11 | $hooks =& $PLUGIN_HOOKS; |
||
12 | $p = "vigilo"; |
||
13 | $hookObj = new VigiloHooks(); |
||
14 | |||
15 | $hooks['csrf_compliant'][$p] = true; |
||
16 | |||
17 | foreach (array("Computer", "Printer", "NetworkEquipment") as $itemtype) { |
||
18 | $hooks['pre_item_update'][$p][$itemtype] = array($hookObj, "preItemUpdate"); |
||
19 | $hooks['item_add'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
20 | $hooks['item_update'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
21 | $hooks['item_restore'][$p][$itemtype] = array($hookObj, "itemAddOrUpdate"); |
||
22 | $hooks['item_delete'][$p][$itemtype] = array($hookObj, "itemPurge"); |
||
23 | $hooks['item_purge'][$p][$itemtype] = array($hookObj, "itemPurge"); |
||
24 | } |
||
25 | |||
26 | $events = array('item_add', 'item_update', 'item_purge', 'item_delete', 'item_restore'); |
||
27 | foreach ($events as $event) { |
||
28 | $hooks[$event][$p] += array( |
||
29 | "IPAddress" => array($hookObj, "refreshAddress"), |
||
30 | "ComputerDisk" => array($hookObj, "refreshDisk"), |
||
31 | "NetworkPort" => array($hookObj, "refreshDevice"), |
||
32 | "DeviceProcessor" => array($hookObj, "refreshDevice"), |
||
33 | "DeviceMemory" => array($hookObj, "refreshDevice"), |
||
34 | "DeviceHardDrive" => array($hookObj, "refreshDevice"), |
||
35 | "DeviceControl" => array($hookObj, "refreshDevice"), |
||
36 | "DeviceSoundCard" => array($hookObj, "refreshDevice"), |
||
37 | "Software" => array($hookObj, "refreshSoftware"), |
||
38 | 09aac931 | Francois POIROTTE | "SoftwareVersion" => array($hookObj, "refreshSoftware"), |
39 | "Computer_SoftwareVersion" => array($hookObj, "refreshComputerSoftwareVersion"), |
||
40 | 166be9d2 | Francois POIROTTE | "Location" => array($hookObj, "updateGroups"), |
41 | "Entity" => array($hookObj, "updateGroups"), |
||
42 | "Manufacturer" => array($hookObj, "updateGroups"), |
||
43 | ); |
||
44 | } |
||
45 | |||
46 | $hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
||
47 | $hooks['config_page'][$p] = 'front/menu.php'; |
||
48 | $hooks['post_item_form'][$p] = array('PluginVigiloTemplate', 'showForm'); |
||
49 | } |
||
50 | |||
51 | function plugin_version_vigilo() |
||
52 | { |
||
53 | return array('name' => 'Vigilo monitoring', |
||
54 | 7ca31ee8 | Francois POIROTTE | 'version' => trim(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'VERSION.txt')), |
55 | 'author' => 'CSSI', |
||
56 | 'license' => 'GPLv2+', |
||
57 | b2feaa03 | Francois POIROTTE | 'homepage' => 'https://www.vigilo-nms.com', |
58 | 7ca31ee8 | Francois POIROTTE | 'minGlpiVersion' => VIGILO_MIN_GLPI_VERSION); |
59 | 166be9d2 | Francois POIROTTE | } |
60 | |||
61 | function plugin_vigilo_check_config($verbose = false) |
||
62 | { |
||
63 | if (version_compare(GLPI_VERSION, VIGILO_MIN_GLPI_VERSION, 'lt')) { |
||
64 | echo "This plugin requires GLPI >= " . VIGILO_MIN_GLPI_VERSION; |
||
65 | return false; |
||
66 | } |
||
67 | return true; |
||
68 | } |
||
69 | |||
70 | function plugin_vigilo_check_prerequisites() |
||
71 | { |
||
72 | return true; |
||
73 | } |
||
74 | |||
75 | function plugin_vigilo_install() |
||
76 | { |
||
77 | global $DB; |
||
78 | |||
79 | if (!TableExists('glpi_plugin_vigilo_template')) { |
||
80 | $query = <<<SQL |
||
81 | CREATE TABLE `glpi_plugin_vigilo_template` (
|
||
82 | cdde5484 | Francois POIROTTE | `id` int(11) NOT NULL default '0',
|
83 | 166be9d2 | Francois POIROTTE | `template` varchar(255) collate utf8_unicode_ci default NULL,
|
84 | cdde5484 | Francois POIROTTE | PRIMARY KEY (`id`)
|
85 | 166be9d2 | Francois POIROTTE | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
86 | SQL;
|
||
87 | $DB->query($query) or die($DB->error()); |
||
88 | } |
||
89 | |||
90 | if (!TableExists('glpi_plugin_vigilo_config')) { |
||
91 | $query = <<<SQL |
||
92 | CREATE TABLE `glpi_plugin_vigilo_config` (
|
||
93 | `key` varchar(255) collate utf8_unicode_ci NOT NULL,
|
||
94 | `value` varchar(255) collate utf8_unicode_ci NULL,
|
||
95 | PRIMARY KEY (`key`)
|
||
96 | ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
|
||
97 | SQL;
|
||
98 | $DB->query($query) or die($DB->error()); |
||
99 | |||
100 | $query = "INSERT INTO `glpi_plugin_vigilo_config` VALUES('needs_deploy', 0);"; |
||
101 | $DB->query($query) or die($DB->error()); |
||
102 | } |
||
103 | |||
104 | return true; |
||
105 | } |
||
106 | |||
107 | function plugin_vigilo_uninstall() |
||
108 | { |
||
109 | global $DB; |
||
110 | |||
111 | foreach (array('template', 'deployment') as $table) { |
||
112 | $DB->query("DROP TABLE IF EXISTS `glpi_plugin_vigilo_$table`;"); |
||
113 | } |
||
114 | |||
115 | return true; |
||
116 | } |
||
117 | cdde5484 | Francois POIROTTE | |
118 | // @codingStandardsIgnoreStart
|
||
119 | function plugin_vigilo_getAddSearchOptions($itemtype) |
||
120 | { |
||
121 | // Le nom de la méthode est imposé par GLPI.
|
||
122 | // @codingStandardsIgnoreEnd
|
||
123 | $options = array(); |
||
124 | |||
125 | if (!in_array($itemtype, array('Computer', 'NetworkEquipment', 'Printer'))) { |
||
126 | return $options; |
||
127 | } |
||
128 | |||
129 | 14b31af4 | Francois POIROTTE | // @HACK: pour que les actions en masse fonctionnent,
|
130 | // on doit utiliser le nom réel du champ dans "linkfield",
|
||
131 | // alors que pour les actions sur un objet, il faut utiliser
|
||
132 | // le nom faisant le lien avec le type de l'objet.
|
||
133 | if (strpos($_SERVER["SCRIPT_FILENAME"], "/ajax/dropdownMassiveAction.php") !== false) { |
||
134 | $linkfield = 'vigilo_template'; |
||
135 | } else {
|
||
136 | $linkfield = 'id'; |
||
137 | } |
||
138 | |||
139 | cdde5484 | Francois POIROTTE | $options[7007]['table'] = 'glpi_plugin_vigilo_template'; |
140 | $options[7007]['field'] = 'template'; |
||
141 | 14b31af4 | Francois POIROTTE | $options[7007]['linkfield'] = $linkfield; |
142 | cdde5484 | Francois POIROTTE | $options[7007]['name'] = 'Template Vigilo'; |
143 | $options[7007]['massiveaction'] = true; |
||
144 | $options[7007]['datatype'] = 'dropdown'; |
||
145 | |||
146 | return $options; |
||
147 | } |