Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

glpi / src / plugins / vigilo / plugin.php @ 2fd8023e

History | View | Annotate | Download (4.81 KB)

1
<?php
2

    
3
/* GLPI 9.1.2+ est nécessaire pour disposer du hook "post_show_item". */
4
define('VIGILO_MIN_GLPI_VERSION', '9.1.2');
5

    
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
            "Computer_SoftwareVersion"  => array($hookObj, "refreshSoftwareVersion"),
39
            "Location"                  => array($hookObj, "updateGroups"),
40
            "Entity"                    => array($hookObj, "updateGroups"),
41
            "Manufacturer"              => array($hookObj, "updateGroups"),
42
        );
43
    }
44

    
45
    $hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu';
46
    $hooks['config_page'][$p]           = 'front/menu.php';
47
    $hooks['post_item_form'][$p]        = array('PluginVigiloTemplate', 'showForm');
48
}
49

    
50
function plugin_version_vigilo()
51
{
52
    return array('name'           => 'Vigilo monitoring',
53
                 'version'        => trim(file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'VERSION.txt')),
54
                 'author'         => 'CSSI',
55
                 'license'        => 'GPLv2+',
56
                 'homepage'       => 'http://vigilo-nms.com',
57
                 'minGlpiVersion' => VIGILO_MIN_GLPI_VERSION);
58
}
59

    
60
function plugin_vigilo_check_config($verbose = false)
61
{
62
    if (version_compare(GLPI_VERSION, VIGILO_MIN_GLPI_VERSION, 'lt')) {
63
        echo "This plugin requires GLPI >= " . VIGILO_MIN_GLPI_VERSION;
64
        return false;
65
    }
66
    return true;
67
}
68

    
69
function plugin_vigilo_check_prerequisites()
70
{
71
    return true;
72
}
73

    
74
function plugin_vigilo_install()
75
{
76
    global $DB;
77

    
78
    if (!TableExists('glpi_plugin_vigilo_template')) {
79
        $query = <<<SQL
80
CREATE TABLE `glpi_plugin_vigilo_template` (
81
    `id` int(11) NOT NULL default '0',
82
    `template` varchar(255) collate utf8_unicode_ci default NULL,
83
    PRIMARY KEY (`id`)
84
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
85
SQL;
86
        $DB->query($query) or die($DB->error());
87
    }
88

    
89
    if (!TableExists('glpi_plugin_vigilo_config')) {
90
        $query = <<<SQL
91
CREATE TABLE `glpi_plugin_vigilo_config` (
92
    `key` varchar(255) collate utf8_unicode_ci NOT NULL,
93
    `value` varchar(255) collate utf8_unicode_ci NULL,
94
    PRIMARY KEY (`key`)
95
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
96
SQL;
97
        $DB->query($query) or die($DB->error());
98

    
99
        $query = "INSERT INTO `glpi_plugin_vigilo_config` VALUES('needs_deploy', 0);";
100
        $DB->query($query) or die($DB->error());
101
    }
102

    
103
    return true;
104
}
105

    
106
function plugin_vigilo_uninstall()
107
{
108
    global $DB;
109

    
110
    foreach (array('template', 'deployment') as $table) {
111
        $DB->query("DROP TABLE IF EXISTS `glpi_plugin_vigilo_$table`;");
112
    }
113

    
114
    return true;
115
}
116

    
117
// @codingStandardsIgnoreStart
118
function plugin_vigilo_getAddSearchOptions($itemtype)
119
{
120
    // Le nom de la méthode est imposé par GLPI.
121
    // @codingStandardsIgnoreEnd
122
    $options = array();
123

    
124
    if (!in_array($itemtype, array('Computer', 'NetworkEquipment', 'Printer'))) {
125
        return $options;
126
    }
127

    
128
    $options[7007]['table']           = 'glpi_plugin_vigilo_template';
129
    $options[7007]['field']           = 'template';
130
    $options[7007]['linkfield']       = 'id';
131
    $options[7007]['name']            = 'Template Vigilo';
132
    $options[7007]['massiveaction']   = true;
133
    $options[7007]['datatype']        = 'dropdown';
134

    
135
    return $options;
136
}