From f87696f81bcd0aaaf2258887f3fef494677f16a8 Mon Sep 17 00:00:00 2001 From: Progfou Date: Tue, 1 Apr 2014 12:00:26 -0400 Subject: [PATCH] glpi-plugin-auf : ajout rapport parc physique --- glpi-plugin-auf/plugin/report.computers.php | 225 ++++++++++++++++++++ glpi-plugin-auf/plugin/report.operatingsystems.php | 1 - glpi-plugin-auf/plugin/setup.php | 5 +- 3 files changed, 228 insertions(+), 3 deletions(-) create mode 100644 glpi-plugin-auf/plugin/report.computers.php diff --git a/glpi-plugin-auf/plugin/report.computers.php b/glpi-plugin-auf/plugin/report.computers.php new file mode 100644 index 0000000..d37511a --- /dev/null +++ b/glpi-plugin-auf/plugin/report.computers.php @@ -0,0 +1,225 @@ +'; + $svg .= ""; + $svg .= ''; + return $svg; +} + +function svg_pie_chart($values, $size=16) { + $colors = Array("#ffa0a0", "#a0ffa0", "#ffffa0", "#a0a0ff"); $color_idx = 0; + $total = 0.0; foreach ($values as $v) { $total += $v; } + $r = (int)$size; $cx = $r+1; $cy = $r+1; $rad = 2*pi()/$total; $old_a = 0; + $svg = ''; + foreach ($values as $a) { + $x1 = $cx + $r * cos(-$old_a * $rad); + $y1 = $cy + $r * sin(-$old_a * $rad); + $x2 = $cx + $r * cos(-($old_a + $a) * $rad); + $y2 = $cy + $r * sin(-($old_a + $a) * $rad); + $big = ($a > ($total/2)) ? '1' : '0'; + $color = $colors[$color_idx++]; + $svg .= ""; + $old_a += $a; + } + $svg .= ''; + return $svg; +} + +echo "\nOrdinateurs par implantation

"; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo ""; +echo "\n"; + +# récupération de la liste des régions +$grand_total = 0; +$query = "SELECT id FROM glpi_entities WHERE (id=0 OR entities_id=0)"; +$query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name"; +$region_result = $DB->query($query); +# parcours des régions +while ($region_data = $DB->fetch_assoc($region_result)) { + $region_id = $region_data['id']; + if ($region_id != 0) { + $region_name = getTreeLeafValueName("glpi_entities", $region_id); + } else { + $region_name = "AUF"; + } + $table_lines = Array(); + $region_serveurs_total = 0; $region_serveurs_prod = 0; + $region_internes_total = 0; $region_internes_prod = 0; + $region_publics_total = 0; $region_publics_prod = 0; + $region_total = 0; $region_virtuels_total = 0; + $region_autres_total = 0; + + # récupération de la liste des implantations + $query = "SELECT id,level FROM glpi_entities WHERE "; + if ($region_id != 0) { + $query .= getRealQueryForTreeItem("glpi_entities", $region_id, "id"); + } else { + $query .= "id=0"; + } + $query .= " ".getEntitiesRestrictRequest("AND", "glpi_entities")." ORDER BY name"; + $implant_result = $DB->query($query); + # parcours des implantations + while ($implant_data = $DB->fetch_assoc($implant_result)) { + $implant_id = $implant_data['id']; + if ($implant_id != 0) { + $implant_name = getTreeLeafValueName("glpi_entities", $implant_id); + } else { + $implant_name = "(non classé)"; + } + + # récupération de la liste des systèmes de l'implantation + $nb_serveurs_total = 0; $nb_serveurs_prod = 0; + $nb_internes_total = 0; $nb_internes_prod = 0; + $nb_publics_total = 0; $nb_publics_prod = 0; + $nb_virtuels_total = 0; $nb_autres_total = 0; + $query = "SELECT COUNT(c.id) AS count, s.id AS sid, s.completename AS sname + FROM `$table_item` c + LEFT JOIN glpi_entities e ON (c.entities_id = e.id) + LEFT JOIN glpi_states s ON (c.states_id = s.id) + WHERE c.is_deleted = '0' AND c.is_template = '0' + AND c.entities_id = '".$implant_id."' + GROUP BY 2 ORDER BY 2"; + $result = $DB->query($query); + while ($data=$DB->fetch_assoc($result)) { + if (preg_match("/^système.*virtu.l/i", $data['sname'])) { + $nb_virtuels_total += $data['count']; + } elseif (preg_match("/^réserv.*serveur.*test/i", $data['sname'])) { + $nb_serveurs_total += $data['count']; + } elseif (preg_match("/^attrib.*serveur.*production/i", $data['sname'])) { + $nb_serveurs_total += $data['count']; + $nb_serveurs_prod += $data['count']; + } elseif (preg_match("/^réserv.*poste.*mission/i", $data['sname'])) { + $nb_internes_total += $data['count']; + } elseif (preg_match("/^attrib.*poste.*interne/i", $data['sname'])) { + $nb_internes_total += $data['count']; + $nb_internes_prod += $data['count']; + } elseif (preg_match("/^réserv.*poste.*stock/i", $data['sname'])) { + $nb_publics_total += $data['count']; + } elseif (preg_match("/^attrib.*poste.*public/i", $data['sname'])) { + $nb_publics_total += $data['count']; + $nb_publics_prod += $data['count']; + } elseif (preg_match("/^sortie/i", $data['sname'])) { + // on ne compte pas les sorties d'inventaire + } else { + $nb_autres_total += $data['count']; + } + } // systèmes dans l'implantation + + $total = $nb_serveurs_total + $nb_internes_total + $nb_publics_total + $nb_autres_total; + if ($total > 0) { + $spaces = ""; + for ($i=1;$i<$implant_data['level'];$i++) { $spaces .= "  "; } + $line = ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $autres = ($nb_autres_total > 0) ? "(".$nb_autres_total." +) " : ""; + $line .= ""; + $line .= ""; + $table_lines[] = $line; + } + $region_serveurs_total += $nb_serveurs_total; + $region_serveurs_prod += $nb_serveurs_prod; + $region_internes_total += $nb_internes_total; + $region_internes_prod += $nb_internes_prod; + $region_publics_total += $nb_publics_total; + $region_publics_prod += $nb_publics_prod; + $region_total += $total; + $region_virtuels_total += $nb_virtuels_total; + $region_autres_total += $nb_autres_total; + //$table_lines[] = ""; + } // fin des implantations de la région + + $line = ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $line .= ""; + $autres = ($region_autres_total > 0) ? "(".$region_autres_total." +) " : ""; + $line .= ""; + $line .= ""; + $table_lines[] = $line; + + $region_name = svg_pie_chart(Array($region_serveurs_total, $region_internes_total, $region_publics_total, $region_virtuels_total), 16) . $region_name; + $table_lines[0] = str_replace("", "", $table_lines[0]); + echo implode("\n", $table_lines); + + $grand_serveurs_total += $region_serveurs_total; + $grand_serveurs_prod += $region_serveurs_prod; + $grand_internes_total += $region_internes_total; + $grand_internes_prod += $region_internes_prod; + $grand_publics_total += $region_publics_total; + $grand_publics_prod += $region_publics_prod; + $grand_total += $region_total; + $grand_virtuels_total += $region_virtuels_total; + $grand_autres_total += $region_autres_total; +} // fin des régions + +// echo ""; + +/* +# total operating systems +$query = "SELECT COUNT(DISTINCT fia.`tag`) FROM `".$table_item."` + LEFT JOIN `glpi_computers_items` ci + ON (ci.`itemtype` = '".$itemtype."' + AND ci.`items_id` = `".$table_item."`.`id`) + LEFT JOIN `glpi_plugin_fusioninventory_agents` fia + ON (fia.`computers_id` = `".$table_item."`.`id`) + WHERE `".$table_item."`.`is_deleted` = '0' + AND `".$table_item."`.`is_template` = '0' ". + getEntitiesRestrictRequest("AND", $table_item); +$result = $DB->query($query); +$grand_total = $DB->result($result, 0, 0); +*/ +$line = ""; +$line .= ""; +$line .= ""; +$line .= ""; +$line .= ""; +$line .= ""; +$line .= ""; +$autres = ($grand_autres_total > 0) ? "(".$grand_autres_total." +) " : ""; +$line .= ""; +$line .= ""; +echo $line; + +echo "
Implantation".svg_circle("#ffa0a0")." Serveurs".svg_circle("#a0ffa0")." Clients internes".svg_circle("#ffffa0")." Clients publicsTotal
(+ sans statut)
".svg_circle("#a0a0ff")." Virtuels
TotalProductionTotalAttribuéTotalAttribué
".$spaces.$implant_name."".$nb_serveurs_total."".$nb_serveurs_prod."".$nb_internes_total."".$nb_internes_prod."".$nb_publics_total."".$nb_publics_prod."".$autres.$total."".$nb_virtuels_total."
".$implant_name."
Sous-total".$region_serveurs_total."".$region_serveurs_prod."".$region_internes_total."".$region_internes_prod."".$region_publics_total."".$region_publics_prod."".$autres.$region_total."".$region_virtuels_total."
$region_name
 
Total général".$grand_serveurs_total."".$grand_serveurs_prod."".$grand_internes_total."".$grand_internes_prod."".$grand_publics_total."".$grand_publics_prod."".$autres.$grand_total."$grand_virtuels_total
"; + +Html::footer(); +?> diff --git a/glpi-plugin-auf/plugin/report.operatingsystems.php b/glpi-plugin-auf/plugin/report.operatingsystems.php index b061b84..87bcdc2 100644 --- a/glpi-plugin-auf/plugin/report.operatingsystems.php +++ b/glpi-plugin-auf/plugin/report.operatingsystems.php @@ -58,7 +58,6 @@ $query = "SELECT COUNT(c.id) AS count, e.name AS ename, WHEN o.name REGEXP '^Mac ' THEN REPLACE(o.name,'Mac ','') ELSE o.name END) AS oname FROM `$table_item` c - LEFT JOIN glpi_computers_items i ON (i.itemtype = 'Computer' AND i.items_id = c.id) LEFT JOIN glpi_entities e ON (c.entities_id = e.id) LEFT JOIN glpi_operatingsystems o ON (c.operatingsystems_id = o.id) WHERE c.is_deleted = '0' AND c.is_template = '0' diff --git a/glpi-plugin-auf/plugin/setup.php b/glpi-plugin-auf/plugin/setup.php index 829e1b4..459f09d 100644 --- a/glpi-plugin-auf/plugin/setup.php +++ b/glpi-plugin-auf/plugin/setup.php @@ -19,7 +19,8 @@ function plugin_init_auf() { $report_list = array(); if (Session::haveRight("computer", "r")) { $report_list["report.operatingsystems.php"] = "Systèmes d'exploitation par implantation"; - $report_list["report.wip.php"] = 'WIP (rapport en cours de développement)'; + $report_list["report.computers.php"] = "Ordinateurs par implantation"; + // $report_list["report.wip.php"] = 'WIP (rapport en cours de développement)'; } $PLUGIN_HOOKS['reports']['auf'] = $report_list; } @@ -30,7 +31,7 @@ function plugin_init_auf() { function plugin_version_auf() { return array( 'name' => 'AUF', - 'version' => '0.1.0', + 'version' => '0.2.0', 'author' => 'Jean Christophe André', 'license' => 'GPLv2+', 'homepage' => 'http://git.auf.org/?p=glpi', -- 1.7.10.4