fusioninventory / fusioninventory-for-glpi

FusionInventory plugin for GLPI
http://www.FusionInventory.org/
GNU Affero General Public License v3.0
361 stars 148 forks source link

Incorrect structure under '<basepath>/glpi/files/_plugins/fusioninventory'. #2034

Open tabad opened 7 years ago

tabad commented 7 years ago

The environment

The issue

Just after install and activate FI4G the tree structure of <basepath>/glpi/files/_plugins/fusioninventory is as follows

# tree <basepath>/glpi/files/_plugins/fusioninventory/
<basepath>/glpi/files/_plugins/fusioninventory/
.
├── files
│   ├── export
│   ├── import
│   ├── manifests
│   └── repository
├── tmp
├── tmpmodels
├── upload
├── walks
└── xml
    ├── computer
    ├── networkequipment
    └── printer

After registering the agent, and perform a network discovery task and a network inventory task, the tree structure of <basepath>/glpi/files/_plugins/fusioninventory is now as follows

# tree <basepath>/glpi/files/_plugins/fusioninventory/
<basepath>/glpi/files/_plugins/fusioninventory/
.
├── files
│   ├── export
│   ├── import
│   ├── manifests
│   └── repository
├── tmp
├── tmpmodels
├── upload
├── walks
└── xml
    ├── computer
    │   └── 0
    │       └── 1
    ├── networkequipment
    ├── NetworkEquipment  <---- (*)
    │   ├── 0
    │   │   ├── 1
    │   │   ├── 2
    │   │   ├── 3
    │   │   ├── 4
    │   │   ├── 5
    │   │   ├── 6
    │   │   ├── 7
    │   │   ├── 8
    │   │   └── 9
    │   └── 1
    │       ├── 10
    │       ├── 11
    │       └── 12
    ├── printer
    └── Printer           <---- (*)
        └── 0
            ├── 1
            └── 2

As you can see, FI4G stores the information of network equipments under ./xml/NetworkEquipment and not under ./xml/networkequipment, and the information of printers under ./xml/Printer and not under ./xml/printer, while it does the correct for the information of computers.

It's not an important problem but it's very confuse.

jhaddan392 commented 7 years ago

Hello, Why phone is not present under XML, └── xml ├── computer ├── networkequipment └── printer I think is that what we can't scan devices phones into "Phones group", Fore scan them i must change the type while importing (unmanageable device) to "Network group" not to "Phones group". BR,

spamy commented 6 years ago

Hello, This issue continues in GLPI 9.2.3 with FI4G 9.2+2.0

ddurieux commented 6 years ago

You havephone XML ???

tabad commented 6 years ago

Hello @ddurieux,

The installation process of FI4G 9.2+2.0 (running with GLPI 9.2.3) only creates this tree structure:

[root@ilab glpi]# tree files/_plugins/fusioninventory/xml/
files/_plugins/fusioninventory/xml/
├── computer
├── networkequipment
└── printer

It does't create any files/_plugins/fusioninventory/xml/phone directory.

The update process neither creates that directory.

Regards,

tabad commented 6 years ago

Hello @ddurieux,

I have used the following Bash script to resolve this issue in one of my tests servers. Perhaps a similar code written in PHP and integrated into the FI4G upgrade process could resolve this issue globally.

#!/bin/bash
#
#
#     Author: Tomas Abad Gomez-Pastrana <tabadgp@gmail.com>
# Maintainer: Tomas Abad Gomez-Pastrana <tabadgp@gmail.com>
#
#     Copyright: Copyright (c) 2018 Tomas Abad Gomez-Pastrana
#
#       License: GNU GPL version 3 or (at your option) any later version
#       https://www.gnu.org/licenses/gpl-3.0-standalone.html
#

declare -r _file_mode='0644'
declare -r _file_owner='apache'
declare -r _file_group='apache'

declare -r _dir_mode='0755'
declare -r _dir_owner="${_file_owner}"
declare -r _dir_group="${_file_group}"

declare -r _glpi_path='/usr/local/share/glpi'

#
# Please, do not touch below this code line. :D
#

declare -i _index=0
declare _old_asset_path=''
declare _new_asset_path=''
declare _source_xml_file=''
declare _target_xml_file=''

declare -i _xml_files=0
declare -i _xml_files_moved=0
declare -i _xml_files_removed=0

declare -ar _old_asset_names=('NetworkEquipment' 'Printer')
declare -ar _new_asset_names=('networkequipment' 'printer')

declare -r _glpi_plugin_file_path="${_glpi_path}/files/_plugins"
declare -r _fi4g_xml_files_path="${_glpi_plugin_file_path}/fusioninventory/xml"

declare -r find=$(type -Pf find)
declare -r install=$(type -Pf install)
declare -r rm=$(type -Pf rm)
declare -r wc=$(type -Pf wc)

# Asset loop.
#   0 -> Network equipments
#   1 -> Printers

for _index in 0 1; do
   _xml_files=0
   _xml_files_moved=0
   _xml_files_removed=0

   _old_asset_path="${_fi4g_xml_files_path}/${_old_asset_names[${_index}]}"
   _new_asset_path="${_fi4g_xml_files_path}/${_new_asset_names[${_index}]}"

   if [ -d "${_old_asset_path}" ]; then
      _xml_files="$(${find} "${_old_asset_path}" -type f | ${wc} -l)"

      echo "Working on '${_old_asset_path}' directory."
      echo "  Detected ${_xml_files} (XML?) files."
      echo -n "  Relocating (XML?) files. Please wait... "

      # Process XML files from old versions of FI4G.
      #   > XML files with '.xml' extension.
      for _source_xml_file in $(${find} "${_old_asset_path}" -type f -name '*.xml'); do
         _target_xml_file="${_source_xml_file/${_old_asset_path}/${_new_asset_path}}"

         if [ -f "${_target_xml_file}" ]; then
            # The asset has already been inventory with FI4G 9.2+2.0.
            # _source_xml_file is an orphaned file that should be removed.
            ${rm} -f "${_source_xml_file}" > /dev/null 2>&1 && \
              _xml_files_removed=$(( _xml_files_removed + 1 ))
         else
            # The asset was inventoried by a version of FI4G earlier than 9.2+2.0.
            # FI4G 9.2+2.0 is able to search for XML files in both the new an the
            # old asset path. As the new XML files are located in the new asset
            # path, I move the _source_xml_file file.
            ${install} -m ${_dir_mode}  \
                       -o ${_dir_owner} \
                       -g ${_dir_group} \
                       -d "${_target_xml_file%/*}" > /dev/null 2>&1 && \
               ${install} -m ${_file_mode}      \
                          -o ${_file_owner}     \
                          -g ${_file_group}     \
                          "${_source_xml_file}" \
                          "${_target_xml_file}" > /dev/null 2>&1    && \
                  ${rm} -f "${_source_xml_file}" > /dev/null 2>&1   && \
                     _xml_files_moved=$(( _xml_files_moved + 1 ))
         fi
      done

      # Process XML files from *very* old versions of FI4G.
      #   > XML files without '.xml' extension.
      for _source_xml_file in $(${find} "${_old_asset_path}" -type f ! -name '*.xml'); do
         _target_xml_file="${_source_xml_file/${_old_asset_path}/${_new_asset_path}}"

         if [ -f "${_target_xml_file}.xml" ]; then
            # The asset has already been inventory with FI4G 9.2+2.0.
            # _source_xml_file is an orphaned file that should be removed.
            ${rm} -f "${_source_xml_file}" > /dev/null 2>&1 && \
              _xml_files_removed=$(( _xml_files_removed + 1 ))
         else
            # The asset was inventoried by a version of FI4G earlier than 9.2+2.0.
            # FI4G 9.2+2.0 is able to search for XML files in both the new an the
            # old asset path. As the new XML files are located in the new asset
            # path, I move the _source_xml_file file.
            ${install} -m ${_dir_mode}  \
                       -o ${_dir_owner} \
                       -g ${_dir_group} \
                       -d "${_target_xml_file%/*}" > /dev/null 2>&1 && \
               ${install} -m ${_file_mode}      \
                          -o ${_file_owner}     \
                          -g ${_file_group}     \
                          "${_source_xml_file}" \
                          "${_target_xml_file}" > /dev/null 2>&1    && \
                  ${rm} -f "${_source_xml_file}" > /dev/null 2>&1   && \
                     _xml_files_moved=$(( _xml_files_moved + 1 ))
         fi
      done

      echo "Done!"
      echo "  Files moved to '${_new_asset_path}': ${_xml_files_moved}"
      echo "  Files removed from '${_old_asset_path}': ${_xml_files_removed}"

      if (( _xml_files == _xml_files_moved + _xml_files_removed )); then
         # Every XML file has been processed.
         # The _old_asset_path can be removed.
         echo "  Every (XML?) file has been processed sucessfully!"
         echo "  '${_old_asset_path}' will be removed."

         ${rm} -rf "${_old_asset_path}" > /dev/null 2>&1 && \
            echo "  '${_old_asset_path}' has been removed successfully!"
      else
         # Some XML file has not been processed correctly.
         echo "   Oops! Some (XML?) file has not been processed correctly."
         echo "   Please, check the '${_old_asset_path}' directory."
      fi
   fi
done

You can download the Bash script here.

Regards,

tabad commented 5 years ago

Hello,

Is there or have you any news about this issue?

Thanks in advance,