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 2013-04-10 19:03:49

npeters
Member
Registered: 2013-01-19
Posts: 6

GLPI webservices plugin

Good day!

I have successfully been able to add network devices through the webservices plugin using a perl script i have designed. Now that i have the basics in place, i want to add a few thousand devices using this method, but i would like to apply a template for the various types of devices so that i (or rather somebody else in the company) doesn't have to configure ports etc for each device.

I have tried setting the values for the test device in question for is_template and template_name with no success. After i import using these values and view the device from inside GLPI the values for the dropdowns etc are proper, however none of the ports etc that are defined in the template i am trying to use are listed for the device.

Below is part of my perl code (can't show it all as it conencts to external db's etc):

use warnings;
use strict;
use XML::RPC;
use DBI;
use Data::Dumper;

my $glpi = 'localhost';
my $uri = 'glpi/plugins/webservices/xmlrpc.php';

my $xmlrpc = XML::RPC->new("http://$glpi/$uri");
my $result = $xmlrpc->call('glpi.doLogin', { login_name => 'xxxxx', login_password => 'xxxxxx' });

if (exists $result->{faultCode})
{
    #something went wrong with the login.
    print "Error loging into the xml rpc service.\n";
    print "Error: $result->{faultString}\n";
}
else
{
    #good login. we need to use the session id for the rest of the requests....
    #session contains the session id.
    my $session = $result->{session};
    #now that that's out of the way, i can start building a device list.
    #setup db stuff
    my $database = "info_hub";
        my $hostname = "xxxxxx";
        my $port = xxxx;
        my $user = "xxxxx";
        my $pass = "xxxxx";
    my $dsn = "DBI:mysql:database=$database;host=$hostname;port=$port";

    my $dbh = DBI->connect($dsn, $user, $pass) or die "Issues Connecting to the database!..\n";
    #shed_sql and rru_sql contain statements to grab list of hardware etc from my external database.
    my $shed_sth = $dbh->prepare($shed_sql);
    my $ap_sth = $dbh->prepare($rru_sql);
    $shed_sth->execute();
    $ap_sth->execute();
    my $shed_result = $shed_sth->fetchall_hashref( [ qw(tower_name) ]);
    my $ap_result = $ap_sth->fetchall_hashref( [ qw(tower_name) ]);
    my @network_equipment;
    foreach my $k (keys %{$shed_result})
    {
        #loop through all the sheds and build our data structure for import into glpi.
        my $site_id = $shed_result->{$k}->{site_id};
                #start with just the bbu's until i figure out things.....
        my %bbu = (
            name => "$site_id BBU",
            groups_id_tech => x,
            comment => "BBU for $site_id",
            locations_id => $site_id, #wrong values, need to get proper locations_id from glpi db.
            networkequipmenttypes_id => 13,
            networkequipmentmodels_id => 38,
            manufacturers_id => 8,
            template_name => 'BBU3900', #correct template name for a "bbu"
            is_template => 0,
            ip => $shed_result->{$k}->{bbu_management},
            groups_id => 11,
            domains_id => 1,
            states_id => 1 
        );
        push @network_equipment, \%bbu;
    }
    my %args = (
        NetworkEquipment => \@network_equipment
    );
    my $test_results = $xmlrpc->call('glpi.createObjects', { session => $session, fields => \%args });
    print Dumper($test_results); #dumps the request results to the terminal screen.
}

I have tried to comment the code fully with lines that start with # (if your no familar with perl, # is a comment). Like i said above, the device is created, but the template in question doesn't seem to be applied (i am more interested in gettting the ports etc that are in the template into the device, cause boy i got a metric *$(@*$ ton of devices to import/configure).

Is there something i am missing for the createObject method to get it to create a device using a template? Can one create objects/devices through the webservices plugin using templates or am i trying something that can't/shouldn't be done?

Thanks in advance for any help the community can offer.

Offline

#2 2013-04-15 19:46:27

npeters
Member
Registered: 2013-01-19
Posts: 6

Re: GLPI webservices plugin

So a bit of an update.

I have been trying to create the network ports after the network device has been created, but with no success.

if i do a help on the NetworkPort object type the webservices plugin returns nothing.

Does this mean that Network Ports can't be created through the plugin and must be added to the object manually as templates through the webservice plugin seem not to work?

Thanks again for any help.

Offline

#3 2013-04-15 22:52:18

npeters
Member
Registered: 2013-01-19
Posts: 6

Re: GLPI webservices plugin

Another Update,

After trying for a few hours, i decided to import the network ports through SQL instead of the webservice plugin.

Everything seems to be working just fine afterwords.

Thanks.

Offline

Board footer

Powered by FluxBB