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 2018-08-24 19:22:18

tacitus
Member
Registered: 2013-01-23
Posts: 17

import of ip networks

Bonjour smile

We use both gestioip and glpi for many years. (gestioip manages all IP networks.)

I'm looking for a way to import the information from gestioip into glpi.
And I would like to avoid adding the ip networks directly to the table glpi_ipnetworks.

Unfortunately (till now) , I have not found an other suitable possibility. sad

I had hoped that I could insert IP networks with the "datainjection" plugin. But unfortunately that does not seem to work.

Does anybody know a safe way to use an existing php function in GLPI for this ?
If so, what class and function should I use? And how ? Or does someone have a small php program for this?

Or maybe there a possibility to user fusioninventory-injector  with some fake xml files ?
Or some other workarounds ?

I made a debug on the database , this is the insert made by glpi:

INSERT INTO `glpi_ipnetworks` (`entities_id`,`is_recursive`,`name`,`comment`,`gateway`,`addressable`,`version`,`address`,`address_0`,`address_1`,`address_2`,`address_3`,`netmask`,`netmask_0`,`netmask_1`,`netmask_2`,`netmask_3`,`gateway_0`,`gateway_1`,`gateway_2`,`gateway_3`,`ipnetworks_id`,`level`,`completename`,`date_creation`,`date_mod`)
VALUES ('0','0','10.14.136.0','TEST','10.14.136.1','1','4','10.14.136.0',0,0,'65535','168724480','255.255.255.0','4294967295','4294967295','4294967295','4294967040',0,0,'65535','168724481','230','2','10.0.0.0 > 10.14.136.0','2018-08-24 18:42:43','2018-08-24 18:42:43')

Best regards from Munich

Karsten

EDIT:

50+ visits and no answer sad
But i was looking around and found script/ldap_mass_sync.php  smile
So I'll try to use script/ldap_mass_sync.php  as an "example" with IPNetwork::prepareInputForAdd for the import ...

Last edited by tacitus (2018-08-28 15:04:50)

Offline

#2 2018-08-29 23:28:29

KKAdmin
Member
From: Germany
Registered: 2010-03-05
Posts: 959

Re: import of ip networks

Do you use ldap_mass_sync.php for ldap user sync too?
Sometimes would be nice if we could have a german user group wink
I can't help you with your problem. I don't know gestioip. We use the microsoft tool from server manager (IPAM). We don't have a sync function but imho i don't miss this so much but it would be nice.


You can mark this threat as [resolved] in subject of your threat. (This is only available edit of the first post.) It is good for users who help others to quickly see which post is still open.
##############################################
GLPI 9.3.3

Offline

#3 2018-08-31 14:14:01

tacitus
Member
Registered: 2013-01-23
Posts: 17

Re: import of ip networks

Yes, I'm using ldap_mass_sync.php , works perfect. I'm using two jobs

to add users:
/somewhere/glpi/scripts/ldap_mass_sync.php action=0 

to update users:
/somewhere/glpi/scripts/ldap_mass_sync.php action=1

And i'm using a bunch of python scripts to sync the following tables from an internal database:
* glpi_entities (sync from a special db)
* glpi_budgets (sync from sap)
* glpi_locations (sync from a special db)
* glpi_groups and glpi_groups_users (sync from a special db)

The next i'm try to implement is the import of:
* glpi_ipnetworks (sync from nagiosql) , unfortunately  not so straight forward like the other tables sad
* glpi_netpoints (sync from a special db)

unfortunately the design of the "ip network" dropdown and the table glpi_ipnetworks is "inadequate".
I would prefer to have this IP network management functionality integrated in glpi, but for that the tab should contain some more information's (owner , site, ... ) and some more functionality  (split networks in multiple networks , ranges (dhcp) , ... ) .

The same with the "network outlets" , missing there is that a network cable is ALWAYS between two rooms ("locations") - but currently there is only one location per "outlet". So the design doesn't match the "reality".
And i would need a view inside the "network outlet dropdown" where this outlet is connected to (switchport, server, phone , .... ).

So therefore unfortunately  i have to do the sync by my own and cant use this functionalities in glpi sad

But don't get me wrong: GLPI IS GREAT ! smile

And no ... we don't need a german or spanish or whatever language "glpi forum" , one forum in English will be enough ...

( i know , "Gestionnaire Libre de Parc Informatique" is french smile )

Last edited by tacitus (2018-08-31 14:16:35)

Offline

#4 2018-10-18 15:48:16

Jean-Christophe
Moderator
Registered: 2007-08-22
Posts: 734

Re: import of ip networks

To do that is not complicated as soon as you use the REST API.
You can import, edit, delete, etc. lots of objects from a JSON upload.

I do it already to sync the IPNetworks of GLPI with our self made IPManagement application.

Here, I do it with a powershell script but any script system can manage that kind of task.

Offline

#5 2018-11-13 15:51:38

tacitus
Member
Registered: 2013-01-23
Posts: 17

Re: import of ip networks

meanwhile i wrote a small python script to sync ...
here the code ...


------------------------------------------

#!/usr/bin/python3
import socket
import os
import sys
import MySQLdb
import re
import warnings
import ipaddress

# we maybe have two different databases , so lets connect
db1 = MySQLdb.connect("1.2.3.4","glpi","superSecret4gestioAccess","gestioip",init_command='SET NAMES UTF8',charset='utf8' )
db2 = MySQLdb.connect("2.3.4.5","glpi","the_same_or_other_superSecret4GLPIaccess","glpi",init_command='SET NAMES UTF8',charset='utf8' )

# tables
# read gestioip.network_view
# +-------------+--------------+------+-----+---------+-------+
# | Field       | Type         | Null | Key | Default | Extra |
# +-------------+--------------+------+-----+---------+-------+
# | NETWORK     | varchar(40)  | YES  |     | NULL    |       |
# | BITMASK     | varchar(3)   | NO   |     | NULL    |       |
# | DESCRIPTION | varchar(100) | YES  |     | NULL    |       |
# | COMMENT     | varchar(500) | YES  |     | NULL    |       |
# | SITE        | varchar(60)  | YES  |     | NULL    |       |
# | CATEGORIE   | varchar(60)  | YES  |     | NULL    |       |
# +-------------+--------------+------+-----+---------+-------+
#
# to create this view in gestioip use this SQL
#
#   create or replace view gestioip.network_view as
#   select
#   a.red as NETWORK,
#   a.bm as BITMASK,
#   a.descr as DESCRIPTION,
#   a.comentario as COMMENT,
#   b.loc as SITE,
#   c.cat as CATEGORIE
#   from gestioip.net a,  gestioip.locations b, gestioip.categorias_net c
#   where
#   a.rootnet=0 and
#   a.ip_version='v4' and
#   a.loc=b.id and
#   a.categoria=c.id ;
#
# if you use any other ip mgmt just create a view with the same content :-)
#
# we then write to glpi_ipnetworks
# +-----------------+---------------------+------+-----+---------+----------------+
# | Field           | Type                | Null | Key | Default | Extra          |
# +-----------------+---------------------+------+-----+---------+----------------+
# | date_creation   | datetime            | YES  | MUL | NULL    |                |
# | date_mod        | datetime            | YES  | MUL | NULL    |                |
# | id              | int(11)             | NO   | PRI | NULL    | auto_increment |
# | entities_id     | int(11)             | NO   | MUL | 0       |                |
# | is_recursive    | tinyint(1)          | NO   |     | 0       |                |
# | ipnetworks_id   | int(11)             | NO   |     | 0       |                |
# | completename    | text                | YES  |     | NULL    |                |
# | level           | int(11)             | NO   |     | 0       |                |
# | ancestors_cache | longtext            | YES  |     | NULL    |                |
# | sons_cache      | longtext            | YES  |     | NULL    |                |
# | addressable     | tinyint(1)          | NO   |     | 0       |                |
# | version         | tinyint(3) unsigned | YES  |     | 0       |                |
# | name            | varchar(255)        | YES  | MUL | NULL    |                |
# | address         | varchar(40)         | YES  |     | NULL    |                |
# | address_0       | int(10) unsigned    | NO   | MUL | 0       |                |
# | address_1       | int(10) unsigned    | NO   |     | 0       |                |
# | address_2       | int(10) unsigned    | NO   |     | 0       |                |
# | address_3       | int(10) unsigned    | NO   |     | 0       |                |
# | netmask         | varchar(40)         | YES  |     | NULL    |                |
# | netmask_0       | int(10) unsigned    | NO   | MUL | 0       |                |
# | netmask_1       | int(10) unsigned    | NO   |     | 0       |                |
# | netmask_2       | int(10) unsigned    | NO   |     | 0       |                |
# | netmask_3       | int(10) unsigned    | NO   |     | 0       |                |
# | gateway         | varchar(40)         | YES  |     | NULL    |                |
# | gateway_0       | int(10) unsigned    | NO   | MUL | 0       |                |
# | gateway_1       | int(10) unsigned    | NO   |     | 0       |                |
# | gateway_2       | int(10) unsigned    | NO   |     | 0       |                |
# | gateway_3       | int(10) unsigned    | NO   |     | 0       |                |
# | comment         | text                | YES  |     | NULL    |                |
# +-----------------+---------------------+------+-----+---------+----------------+
#

# we loop the select of gestioip.network_view , a view based on gestioip.net,  gestioip.locations and gestioip.categorias_net
#
gestioipnet = db1.cursor()

# destination is glpi.glpi_ipnetworks , so we need a second courser
glpinet = db2.cursor()


# some maintainance ... we must take care that the name and complatename are allways  identical to the address
glpinetSQL="update glpi_ipnetworks  set name=address "
try:
        glpinet.execute(glpinetSQL)
except (MySQLdb.Error, MySQLdb.Warning) as e:
        print(e)

glpinetSQL="update glpi_ipnetworks  set completename=address "
try:
        glpinet.execute(glpinetSQL)
except (MySQLdb.Error, MySQLdb.Warning) as e:
        print(e)


# search all networks in gestioip
#gestioipnetSQL="select NETWORK,BITMASK,DESCRIPTION,COMMENT,SITE,CATEGORIE from gestioip.network_view where NETWORK like %(string1)s "
#data= { 'string1' :  '10.4.%' }
gestioipnetSQL="select NETWORK,BITMASK,DESCRIPTION,COMMENT,SITE,CATEGORIE from gestioip.network_view"
try:
        #gestioipnet.execute(gestioipnetSQL,data)
        gestioipnet.execute(gestioipnetSQL)
except (MySQLdb.Error, MySQLdb.Warning) as e:
        print(e)

gestioipnetDATA = gestioipnet.fetchall()

# inner loop
#
for row in gestioipnetDATA :
        NETWORK=row[0]
        BITMASK=row[1]
        NETWORKBITMASK=row[0]+"/"+row[1]
        DESCRIPTION="--- FROM GESTIOIP ---\nDESCRIPTION: "+row[2]+"\nCOMMENT: "+row[3]+"\nSITE: "+row[4]+"\nCATEGORIE: "+row[5]+"\n--- DONT CHANGE IN GLPI ---"
        #print(NETWORK,BITMASK,DESCRIPTION)

        address_3=int(ipaddress.IPv4Address(NETWORK))
        gateway=str(ipaddress.IPv4Address(NETWORK)+1)
        gateway_3=int(ipaddress.IPv4Address(NETWORK)+1)
        netmask=str(ipaddress.ip_network(NETWORKBITMASK).netmask)
        netmask_3=int(ipaddress.ip_network(NETWORKBITMASK).netmask)


        glpinetSQL="select name from glpi.glpi_ipnetworks where name = %(string1)s "
        data = { 'string1' : NETWORK }
        try:
                glpinet.execute(glpinetSQL,data)
        except (MySQLdb.Error, MySQLdb.Warning) as e:
                print(e)

        glpinetDATA=glpinet.fetchone()
        #
        # network not found in glpi
        #
        if not glpinetDATA:
                print("Missing ",NETWORK)
                print(NETWORKBITMASK,DESCRIPTION,address_3,gateway,gateway_3,netmask,netmask_3)
                #
                # insert
                glpinetSQL="INSERT INTO glpi_ipnetworks (entities_id, is_recursive, name, comment, gateway, addressable, version, address, address_0, address_1, address_2, address_3, netmask, netmask_0, netmask_1, netmask_2, netmask_3, gateway_0, gateway_1, gateway_2, gateway_3, ipnetworks
_id, level, completename, date_creation, date_mod,ancestors_cache,sons_cache) VALUES ('0', '0', %(string1)s, %(string7)s,  %(string3)s, 1, 4, %(string1)s, 0,0, 65535,  %(string2)s,  %(string5)s, 4294967295,4294967295,4294967295, %(string6)s,0,0,65535,%(string4)s,0,1,%(string1)s,%(string8)s
,%(string8)s,NULL,NULL )  "
                data = {
                        'string1' : NETWORK ,
                        'string2' : address_3,
                        'string3' : gateway,
                        'string4' : gateway_3,
                        'string5' : netmask,
                        'string6' : netmask_3,
                        'string7' : DESCRIPTION,
                        'string8' : '2018-01-01 00:00:00',
                        }
                try:
                        glpinet.execute(glpinetSQL,data)
                        db2.commit()
                except (MySQLdb.Error, MySQLdb.Warning) as e:
                        print(e)

        #
        # network found in glpi
        #
        if glpinetDATA:
                print("Found ",NETWORK," ",glpinetDATA)
                data = {
                        'string1' : NETWORK ,
                        'string2' : address_3,
                        'string3' : gateway,
                        'string4' : gateway_3,
                        'string5' : netmask,
                        'string6' : netmask_3,
                        'string7' : DESCRIPTION,
                        'string8' : '2018-01-01 00:00:00',
                        }
                glpinetSQL="update glpi_ipnetworks set comment=%(string7)s where name=%(string1)s"
                try:
                        glpinet.execute(glpinetSQL,data)
                        db2.commit()
                except (MySQLdb.Error, MySQLdb.Warning) as e:
                        print(e)

                glpinetSQL="update glpi_ipnetworks set gateway=%(string1)s, gateway_0=0 , gateway_1=0, gateway_2=65535, gateway_3=%(string4)s where  name=%(string1)s and gateway=NULL"
                try:
                        glpinet.execute(glpinetSQL,data)
                        db2.commit()
                except (MySQLdb.Error, MySQLdb.Warning) as e:
                        print(e)

------------------------------------------

Offline

Board footer

Powered by FluxBB