You are not logged in.

Announcement

 Téléchargez la dernière version stable de GLPI      -     Et vous, que pouvez vous faire pour le projet GLPI ? :  Contribuer
 Download last stable version of GLPI                      -     What can you do for GLPI ? :  Contribute

#1 2006-03-03 09:54:45

Erwin
Member
Registered: 2006-03-03
Posts: 4

Modification Archires pour VoIP

Bonjour à tous,

Voici un petit patch VoIP pour faire fonctionner Archires et GLPI en version cvs du 02.03.2006 afin de visioner les téléphones IP sur le graphique.

Remplacer juste le fichier fonctions.php qui se trouve dans plugins\archires\fonctions.php par celui-ci.

Have fun ..!

Excellente journée à tous et Meilleures salutations.

Erwin

<?php
/*
 ----------------------------------------------------------------------
 GLPI - Gestionnaire Libre de Parc Informatique
 Copyright (C) 2003-2005 by the INDEPNET Development Team.
 
 http://indepnet.net/   http://glpi.indepnet.org
 ----------------------------------------------------------------------

 LICENSE

    This file is part of GLPI.

    GLPI is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    GLPI is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with GLPI; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ------------------------------------------------------------------------
*/
 
// ----------------------------------------------------------------------
// Original Author of file: Sébastien Prud'homme
// Purpose of file:
// ----------------------------------------------------------------------

function graphviz_fetch($format) {
    global $cfg_install;
    global $phproot;

    $db = new DB();

    $devices = array();
    $ports = array();

    $query = "SELECT np.ID, np.on_device, c.name";
    $query .= " FROM glpi_networking_ports np, glpi_computers c";
    $query .= " WHERE np.device_type = " . COMPUTER_TYPE . " AND np.on_device = c.ID";
    $query .= " AND c.deleted = 'N' AND c.is_template = '0'";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $devices[COMPUTER_TYPE][$data["on_device"]]["name"] = $data["name"];
            $ports[$data["ID"]]["on_device"] = $data["on_device"];
            $ports[$data["ID"]]["device_type"] = COMPUTER_TYPE;
        }
    }

    $query = "SELECT np.ID, np.on_device, n.name";
    $query .= " FROM glpi_networking_ports np, glpi_networking n";
    $query .= " WHERE np.device_type = " . NETWORKING_TYPE . " AND np.on_device = n.ID";
    $query .= " AND n.deleted = 'N' AND n.is_template = '0'";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $devices[NETWORKING_TYPE][$data["on_device"]]["name"] = $data["name"];
            $ports[$data["ID"]]["on_device"] = $data["on_device"];
            $ports[$data["ID"]]["device_type"] = NETWORKING_TYPE;
        }
    }

    $query = "SELECT np.ID, np.on_device, p.name";
    $query .= " FROM glpi_networking_ports np, glpi_peripherals p";
    $query .= " WHERE np.device_type = " . PERIPHERAL_TYPE . " AND np.on_device = p.ID";
    $query .= " AND p.deleted = 'N' AND p.is_template = '0'";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $devices[PERIPHERAL_TYPE][$data["on_device"]]["name"] = $data["name"];
            $ports[$data["ID"]]["on_device"] = $data["on_device"];
            $ports[$data["ID"]]["device_type"] = PERIPHERAL_TYPE;
        }
    }

    $query = "SELECT np.ID, np.on_device, p.name";
    $query .= " FROM glpi_networking_ports np, glpi_printers p";
    $query .= " WHERE np.device_type = " . PRINTER_TYPE . " AND np.on_device = p.ID";
    $query .= " AND p.deleted = 'N' AND p.is_template = '0'";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $devices[PRINTER_TYPE][$data["on_device"]]["name"] = $data["name"];
            $ports[$data["ID"]]["on_device"] = $data["on_device"];
            $ports[$data["ID"]]["device_type"] = PRINTER_TYPE;
        }
    }

    $query = "SELECT np.ID, np.on_device, p.name";
    $query .= " FROM glpi_networking_ports np, glpi_phones p";
    $query .= " WHERE np.device_type = " . PHONE_TYPE . " AND np.on_device = p.ID";
    $query .= " AND p.deleted = 'N' AND p.is_template = '0'";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $devices[PHONE_TYPE][$data["on_device"]]["name"] = $data["name"];
            $ports[$data["ID"]]["on_device"] = $data["on_device"];
            $ports[$data["ID"]]["device_type"] = PHONE_TYPE;
        }
    }

    $wires = array();

    $query = "SELECT nw.ID, nw.end1, nw.end2";
    $query .= " FROM glpi_networking_wire nw";

    if ($result = $db->query($query)) {
        while ($data = $db->fetch_array($result)) {
            $wires[$data["ID"]]["end1"] = $data["end1"];
            $wires[$data["ID"]]["end2"] = $data["end2"];
        }
    }

    $graph = "graph G {\n";
    $graph .= "overlap=false;\n";

    foreach ($devices as $device_type => $typed_devices) {
        foreach ($typed_devices as $device_id => $device) {
            $device_unique_name = $device_type . "_" . $device_id . "_";
            $device_unique_name .= $device["name"];

            switch ($device_type) {
                case COMPUTER_TYPE:
                    $image_name = $phproot . "/pics/computer.png";
                    $url = $cfg_install["root"] . "/computers/computers-info-form.php?ID=" . $device_id;
                    break;
                case NETWORKING_TYPE:
                    $image_name = $phproot . "/pics/networking.png";
                    $url = $cfg_install["root"] . "/networking/networking-info-form.php?ID=" . $device_id;
                    break;
                case PERIPHERAL_TYPE:
                    $image_name = $phproot . "/pics/periphs.png";
                    $url = $cfg_install["root"] . "/peripherals/peripherals-info-form.php?ID=" . $device_id;
                    break;
                case PRINTER_TYPE:
                    $image_name = $phproot . "/pics/printer.png";
                    $url = $cfg_install["root"] . "/printers/printers-info-form.php?ID=" . $device_id;
                    break;
                case PHONE_TYPE:
                    $image_name = $phproot . "/pics/phones.png";
                    $url = $cfg_install["root"] . "/phones/phones-info-form.php?ID=" . $device_id;
                    break;
            }

            $graph .= "\"" . $device_unique_name . "\" [shape=plaintext";
            $graph .= ", label=<<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
            $graph .= "<tr><td><img src=\"" . $image_name . "\"/></td></tr>";
            $graph .= "<tr><td>" . $device["name"] . "</td></tr></table>>";
            $graph .= "URL=\"" . $url . "\" tooltip=\"" . $device["name"] . "\"];\n";
        }
    }

    foreach ($wires as $wire) {
        if (!is_null($ports[$wire["end1"]]) && !is_null($ports[$wire["end2"]])) {
            $on_device1 = $ports[$wire["end1"]]["on_device"];
            $device_type1 = $ports[$wire["end1"]]["device_type"];

            $device_unique_name1 = $device_type1 . "_" . $on_device1 . "_";
            $device_unique_name1 .= $devices[$device_type1][$on_device1]["name"];

            $on_device2 = $ports[$wire["end2"]]["on_device"];
            $device_type2 = $ports[$wire["end2"]]["device_type"];

            $device_unique_name2 = $device_type2 . "_" . $on_device2 . "_";
            $device_unique_name2 .= $devices[$device_type2][$on_device2]["name"];

            $graph .= "\"" . $device_unique_name1 . "\"";
            $graph .= " -- \"" . $device_unique_name2 . "\";\n";
        }
    }

    $graph .= "}\n";

    $graph_name = tempnam("", "");
    $output_name = tempnam("", "");

    if ($graph_file = fopen($graph_name, "w")) {
        fputs($graph_file, $graph);
        fclose($graph_file);

        $command = "dot -T" . $format . " -o " . $output_name . " " . $graph_name;

        `$command`;
        unlink($graph_name);

        if ($output_file = fopen($output_name, "rb")) {
            $output_data = fread($output_file, filesize($output_name));
            fclose($output_file);
            unlink($output_name);

            return $output_data;
        }
    }
}

?>

Offline

#2 2006-04-12 00:15:51

tsmr
GLPI-DEV
From: Rennes
Registered: 2005-08-26
Posts: 11,632
Website

Re: Modification Archires pour VoIP

ajouté dans la nouvelle version en tléchargement sur le site.
Merci pour ta contribution.
Sujet fermé


Xavier Caillaud
Blog GLPI Infotel

Offline

Board footer

Powered by FluxBB