Revision 0d761a49
[#1571] Ajout du champ Vigilo Template
Change-Id: Ib31d45245cbbbeb845df30f013bec479878ee627
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2321
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Tested-by: Francois POIROTTE <francois.poirotte@c-s.fr>
Vigilo/VigiloHost.php | ||
---|---|---|
67 | 67 |
} |
68 | 68 |
|
69 | 69 |
$this->children[] = new VigiloHostTemplate($model);*/ |
70 |
|
|
70 |
|
|
71 | 71 |
|
72 | 72 |
$template_number = $this->computer->getField("vigilo_template"); |
73 |
if ($template_number !== '0') { |
|
73 |
if ($template_number !== '0' && $template_number !== 'N/A') {
|
|
74 | 74 |
$common_dbtm = new CommonDBTM(); |
75 |
$template_name = $this->computer->getVigiloTemplateName($template_number); |
|
75 |
$template_name = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($template_number); |
|
76 |
$this->children[] = new VigiloHostTemplate($template_name); |
|
76 | 77 |
} |
77 | 78 |
else { |
78 |
$template_name = "default"; |
|
79 |
if (empty($this->children)) { |
|
80 |
$template_name = "default"; |
|
81 |
$this->children[] = new VigiloHostTemplate($template_name); |
|
82 |
} |
|
79 | 83 |
} |
80 |
$this->children[] = new VigiloHostTemplate($template_name); |
|
81 | 84 |
} |
82 | 85 |
|
83 | 86 |
protected function selectGroups() |
Vigilo/VigiloTestSoftware.php | ||
---|---|---|
24 | 24 |
|
25 | 25 |
public function addRelevantTestWith($softwareName) |
26 | 26 |
{ |
27 |
if (strstr($softwareName, "vigilo-test")) |
|
27 |
if (strstr($softwareName, "vigilo-test"))
|
|
28 | 28 |
{ |
29 | 29 |
$functionArray=array("addCustomTest", array($softwareName)); |
30 | 30 |
} |
31 | 31 |
else |
32 | 32 |
{ |
33 |
if (!array_key_exists($softwareName, $this->softwareBase)) |
|
34 |
{ |
|
33 |
if (!array_key_exists($softwareName, $this->softwareBase)) { |
|
35 | 34 |
return; |
36 | 35 |
} |
37 | 36 |
$functionArray=$this->softwareBase[$softwareName]; |
... | ... | |
42 | 41 |
protected function addCustomTest($softwareName) |
43 | 42 |
{ |
44 | 43 |
$software_name = str_replace('vigilo-test-', '', $softwareName); |
45 |
$explode_software_name = explode('-', $software_name, 2);
|
|
44 |
$explode_software_name = explode('-', $software_name, 2);
|
|
46 | 45 |
$args=array(); |
47 | 46 |
switch(strtolower($explode_software_name[0])) |
48 | 47 |
{ |
49 |
case "process": |
|
48 |
case "process":
|
|
50 | 49 |
$args[]=new VigiloArg('processname', $explode_software_name[1]); |
51 | 50 |
$explode_software_name[0] = "Process"; |
52 | 51 |
break; |
53 |
case "service": |
|
52 |
case "service":
|
|
54 | 53 |
$args[]=new VigiloArg('svcname', $explode_software_name[1]); |
55 | 54 |
$explode_software_name[0] = "Service"; |
56 | 55 |
break; |
57 |
case "tcp": |
|
58 |
$args[]=new VigiloArg('port', $explode_software_name[1]); |
|
56 |
case "tcp":
|
|
57 |
$args[]=new VigiloArg('port', $explode_software_name[1]);
|
|
59 | 58 |
$explode_software_name[0] = "TCP"; |
60 | 59 |
break; |
61 | 60 |
default: return; |
62 | 61 |
} |
63 | 62 |
|
64 |
return new VigiloTest($explode_software_name[0], $args); |
|
63 |
return new VigiloTest($explode_software_name[0], $args);
|
|
65 | 64 |
} |
66 | 65 |
|
67 | 66 |
protected function addNTPTest() |
hook.php | ||
---|---|---|
18 | 18 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
19 | 19 |
$file = $confdir . DIRECTORY_SEPARATOR . "groups.xml"; |
20 | 20 |
|
21 |
if (!file_exists($confdir)) { |
|
22 |
mkdir($confdir, 0770, true); |
|
23 |
} |
|
24 |
|
|
21 |
mkdir($confdir, 0770, true); |
|
25 | 22 |
$acc = ""; |
26 | 23 |
foreach ($dirs as $dir) { |
27 | 24 |
$acc .= DIRECTORY_SEPARATOR . $dir; |
... | ... | |
38 | 35 |
public function add($computer) |
39 | 36 |
{ |
40 | 37 |
if ($computer->getField("is_template")==0) { |
38 |
global $DB; |
|
39 |
$template_id = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")); |
|
40 |
|
|
41 |
if(!empty($template_id)) { |
|
42 |
$query = "UPDATE glpi_computers |
|
43 |
SET vigilo_template = '" . PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($computer->getField("vigilo_template")) . |
|
44 |
"' WHERE id = " . $computer->getField("id") . ";"; |
|
45 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
46 |
} |
|
47 |
|
|
48 |
$query = "UPDATE glpi_computers |
|
49 |
SET is_dynamic = ' 1 |
|
50 |
' WHERE id = " . $computer->getField("id") . ";"; |
|
51 |
$DB->queryOrDie($query, "update vigilo_template field"); |
|
41 | 52 |
$host = new VigiloHost($computer); |
42 | 53 |
$dirs = array($this->confdir, "hosts", "managed"); |
43 | 54 |
$confdir = implode(DIRECTORY_SEPARATOR, $dirs); |
... | ... | |
67 | 78 |
|
68 | 79 |
public function update($computer) |
69 | 80 |
{ |
70 |
global $PLUGIN_HOOKS; |
|
81 |
global $PLUGIN_HOOKS, $DB;
|
|
71 | 82 |
if (isset($computer->oldvalues["name"])) { |
72 | 83 |
$this->unmonitor($computer->oldvalues["name"]); |
73 | 84 |
} |
74 |
|
|
75 | 85 |
$this->add($computer); |
76 | 86 |
} |
77 | 87 |
|
... | ... | |
86 | 96 |
global $DB; |
87 | 97 |
$computer=new Computer(); |
88 | 98 |
$computer->getFromDB($computer_software_version->getField("computers_id")); |
89 |
$this->update($computer); |
|
99 |
$this->update($computer);
|
|
90 | 100 |
} |
91 | 101 |
|
92 | 102 |
public function manageSoftwares($software) |
... | ... | |
136 | 146 |
$comp->getFromDB($id); |
137 | 147 |
$this->update($comp); |
138 | 148 |
} |
149 |
|
|
150 |
public function plugin_vigilo_getAddSearchOptions($itemtype) |
|
151 |
{ |
|
152 |
$options = array(); |
|
153 |
if ($itemtype == 'Computer' or $itemtype == 'PluginVigiloComputer') |
|
154 |
{ |
|
155 |
$options['7007']['table'] = 'glpi_computers'; |
|
156 |
$options['7007']['field'] = 'vigilo_template'; |
|
157 |
$options['7007']['name'] = 'vigilo_template'; |
|
158 |
$options['7007']['massiveaction'] = 'TRUE'; |
|
159 |
$options['7007']['datatype'] = 'dropdown'; |
|
160 |
return $options; |
|
161 |
} |
|
162 |
} |
|
139 | 163 |
} |
inc/computer.class.php | ||
---|---|---|
1 |
<?php |
|
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) { |
|
9 |
global $CFG_GLPI; |
|
10 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
|
11 |
$value = array_search($item->getField('vigilo_template'), $templates); |
|
12 |
if (empty($value)) { |
|
13 |
$value = 0; |
|
14 |
} |
|
15 |
echo '<table class="tab_cadre_fixe tab_glpi" width="100%">'; |
|
16 |
echo '<tr class="tab_bg_1"><th colspan="4">Vigilo Template</th></tr>'; |
|
17 |
echo '<tr class="tab_bg_1">'; |
|
18 |
echo '<td>Vigilo Template</td>'; |
|
19 |
echo '<td>'; |
|
20 |
Dropdown::showFromArray('vigilo_template', $templates, array('value' => $value)); |
|
21 |
echo '</td></tr>'; |
|
22 |
echo '</table>'; |
|
23 |
return TRUE; |
|
24 |
} |
|
25 |
|
|
26 |
function getSearchOptions() { |
|
27 |
global $CFG_GLPI; |
|
28 |
|
|
29 |
$computer = new Computer(); |
|
30 |
$options = $computer->getSearchOptions(); |
|
31 |
|
|
32 |
$options['vigilo'] = 'Vigilo Template'; |
|
33 |
|
|
34 |
$options['7007']['table'] = 'glpi_computers'; |
|
35 |
$options['7007']['field'] = 'vigilo_template'; |
|
36 |
$options['7007']['name'] = 'vigilo_template'; |
|
37 |
//$options['7007']['searchtype'] = 'equals'; |
|
38 |
$options['7007']['datatype'] = 'dropdown'; |
|
39 |
|
|
40 |
return $options; |
|
41 |
} |
|
42 |
} |
inc/vigilotemplate.class.php | ||
---|---|---|
1 |
<?php |
|
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() { |
|
9 |
$hosttdir = "/etc/vigilo/vigiconf/conf.d/hosttemplates"; |
|
10 |
$hosttemplates_files = scandir($hosttdir); |
|
11 |
$templates = array(); |
|
12 |
$pattern = "<template name=\"(\w*)\">"; |
|
13 |
|
|
14 |
foreach($hosttemplates_files as $file) { |
|
15 |
$filepath = $hosttdir . DIRECTORY_SEPARATOR . $file; |
|
16 |
$test_filepath = preg_match("/(.*).xml$/", $filepath); |
|
17 |
if (is_file($filepath) AND !empty($test_filepath)) { |
|
18 |
preg_match_all($pattern, file_get_contents($filepath), $matches); |
|
19 |
foreach ($matches[1] as $match) { |
|
20 |
$templates[] = $match; |
|
21 |
} |
|
22 |
} |
|
23 |
} |
|
24 |
|
|
25 |
sort($templates, SORT_STRING); |
|
26 |
array_unshift($templates, '-----'); |
|
27 |
return $templates; |
|
28 |
} |
|
29 |
|
|
30 |
static function getVigiloTemplateNameByID($id) { |
|
31 |
|
|
32 |
if (is_numeric($id)) { |
|
33 |
if ($id === '0') return "NULL"; |
|
34 |
$templates = PluginVigiloVigiloTemplate::getAllTemplates(); |
|
35 |
return $templates[$id]; |
|
36 |
} |
|
37 |
} |
|
38 |
} |
setup.php | ||
---|---|---|
5 | 5 |
function plugin_init_vigilo() |
6 | 6 |
{ |
7 | 7 |
global $PLUGIN_HOOKS; |
8 |
global $DB; |
|
8 | 9 |
$hooks =& $PLUGIN_HOOKS; |
9 | 10 |
$p = "vigilo"; |
10 | 11 |
$hookObj = new VigiloHooks(); |
... | ... | |
21 | 22 |
"Software" => array($hookObj,"manageSoftwares"), |
22 | 23 |
"Location" => array($hookObj,"updateGroups"), |
23 | 24 |
"Entity" => array($hookObj,"updateGroups"), |
24 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
25 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
25 | 26 |
"Manufacturer" => array($hookObj,"updateGroups")); |
26 | 27 |
$hooks['item_update'][$p] = array("Computer" => array($hookObj, "update"), |
27 | 28 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
... | ... | |
34 | 35 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
35 | 36 |
"Software" => array($hookObj,"manageSoftwares"), |
36 | 37 |
"Location" => array($hookObj,"updateGroups"), |
37 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
38 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
38 | 39 |
"Entity" => array($hookObj,"updateGroups"), |
39 |
"Manufacturer" => array($hookObj,"updateGroups"));
|
|
40 |
"Manufacturer" => array($hookObj,"updateGroups")); |
|
40 | 41 |
$hooks['item_purge'][$p] = array("Computer" => array($hookObj, "delete"), |
41 | 42 |
"ComputerDisk" => array($hookObj,"manageDisks"), |
42 | 43 |
"NetworkPort" => array($hookObj,"manageNetworks"), |
... | ... | |
48 | 49 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
49 | 50 |
"Software" => array($hookObj,"manageSoftwares"), |
50 | 51 |
"Location" => array($hookObj,"updateGroups"), |
51 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
52 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
52 | 53 |
"Entity" => array($hookObj,"updateGroups"), |
53 | 54 |
"Manufacturer" => array($hookObj,"updateGroups")); |
54 | 55 |
$hooks['item_delete'][$p] = array("Computer" => array($hookObj, "delete"), |
... | ... | |
62 | 63 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
63 | 64 |
"Software" => array($hookObj,"manageSoftwares"), |
64 | 65 |
"Location" => array($hookObj,"updateGroups"), |
65 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
66 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
66 | 67 |
"Entity" => array($hookObj,"updateGroups"), |
67 | 68 |
"Manufacturer" => array($hookObj,"updateGroups")); |
68 | 69 |
$hooks['item_restore'][$p] = array("Computer" => array($hookObj, "add"), |
... | ... | |
76 | 77 |
"DeviceSoundCard" => array($hookObj,"manageNetworks"), |
77 | 78 |
"Software" => array($hookObj,"manageSoftwares"), |
78 | 79 |
"Location" => array($hookObj,"updateGroups"), |
79 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
80 |
"Computer_SoftwareVersion" => array($hookObj, "manageComputerSoftwareVersion"),
|
|
80 | 81 |
"Entity" => array($hookObj,"updateGroups"), |
81 | 82 |
"Manufacturer" => array($hookObj,"updateGroups")); |
82 | 83 |
$hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu'; |
83 | 84 |
$hooks['config_page'][$p] = 'front/menu.php?itemtype=vigilo'; |
85 |
$hooks['autoinventory_information'][$p] = array( |
|
86 |
'Computer' => array('PluginVigiloComputer', |
|
87 |
'showComputerInfo')); |
|
88 |
$hooks['autoinventory_information'][$p] = array( |
|
89 |
'Printer' => array('PluginVigiloPrinter', |
|
90 |
'showPrinterInfo')); |
|
91 |
|
|
92 |
if (!FieldExists('glpi_computers', 'vigilo_template')) |
|
93 |
{ |
|
94 |
$query = "ALTER TABLE glpi_computers ADD vigilo_template VARCHAR(30)"; |
|
95 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_computers"); |
|
96 |
} |
|
97 |
|
|
98 |
if (!FieldExists('glpi_printers', 'vigilo_template')) |
|
99 |
{ |
|
100 |
$query = "ALTER TABLE glpi_printers ADD vigilo_template VARCHAR(30)"; |
|
101 |
$DB->queryOrDie($query, "Ajout d'une colonne vigilo_template dans la table glpi_printers"); |
|
102 |
} |
|
103 |
} |
|
104 |
|
|
105 |
function getSearchOptions() { |
|
106 |
$computer = new Computer(); |
|
107 |
$options = $computer->getSearchOptions(); |
|
108 |
|
|
109 |
$options['vigilo'] = 'Vigilo Template'; |
|
110 |
|
|
111 |
$options['7007']['name'] = 'vigilo_template'; |
|
112 |
$options['7007']['table'] = 'glpi_computers'; |
|
113 |
$options['7007']['field'] = 'vigilo_template'; |
|
114 |
$options['7007']['searchtype'] = 'equals'; |
|
115 |
$options['7007']['datatype'] = 'dropdown'; |
|
116 |
|
|
117 |
return $options; |
|
84 | 118 |
} |
85 | 119 |
|
86 | 120 |
function plugin_version_vigilo() |
Also available in: Unified diff