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 2012-10-05 22:25:20

clint.grimsley
Member
Registered: 2012-07-04
Posts: 5

GLPI webservices Python API

Hey guys,

If anyone is interested, I'm putting together a python api to interface with GLPI webservice. Initial thought was to be able to use it to create a nagios plugin that automatically generates tickets when servers fail. Good for metrics and all that.

Hope someone finds it useful.

https://github.com/mcphargus/python-glpi

If this has been done before, someone please point me at the current code and I'll be happy to contribute or start using it.

Warm regards,
Clint

Offline

#2 2012-10-06 09:00:38

remi
GLPI-DEV
From: Champagne
Registered: 2007-04-28
Posts: 7,127
Website

Re: GLPI webservices Python API

Great idea !

I don't think anybody have work on this before (or have make its work publicly available).

If you agree, I can add a link from the Webservice wiki page to your project (which could probably have be hosted on glpi forge...)


Small note

        self.url = 'http://'+host+'/plugins/webservices/rest.php?'

You probably also need a "baseurl" option.
I don't know if "rest" is the best choice... I know there is some issues with multi-line data encoding.

        params = {'method':'glpi.status',
                  'session':self.session}

A few methods, this one included, doesn't required an open session.

Why a try / raise block, only for connect method ? other could also fail.


Dév. Fedora 29 - PHP 5.6/7.0/7.1/7.2/7.3/7.4 - MariaDB 10.3 - GLPI master
Certifié ITILv3 - RPM pour Fedora, RHEL et CentOS sur https://blog.remirepo.net/

Offline

#3 2012-10-07 23:14:41

clint.grimsley
Member
Registered: 2012-07-04
Posts: 5

Re: GLPI webservices Python API

Feel free to add a link from the webservices wiki.

I'll add a baseurl option, but I'm a little worried that urllib2 might not like SSL/TLS, so anyone trying to use an https connection might have issues. I'll research this further.

A few methods, this one included, doesn't required an open session.

Duly noted, I've made connecting optional where a session is not required.

I don't know if "rest" is the best choice... I know there is some issues with multi-line data encoding.

I haven't spent lots of time with SOAP or XML-RPC webservices in python, and I'm pretty sure some methods, like glpi.addTicketDocument, will have a problem with base64 encoded documents being shoved into a GET request, mostly due to request size constraints. I'll do my best to address these concerns in documentation.

Why a try / raise block, only for connect method ? other could also fail.

I have a ton of error handling to add, and I'll be adding as time permits.

Offline

#4 2012-10-08 07:23:35

remi
GLPI-DEV
From: Champagne
Registered: 2007-04-28
Posts: 7,127
Website

Re: GLPI webservices Python API

clint.grimsley wrote:

Feel free to add a link from the webservices wiki.

Done.

clint.grimsley wrote:

I'll add a baseurl option, but I'm a little worried that urllib2 might not like SSL/TLS, so anyone trying to use an https connection might have issues. I'll research this further

I don"t mean the "http" part of the URL, but the part between "host" and "/plugins/webs...". Default value should be "/glpi"


Dév. Fedora 29 - PHP 5.6/7.0/7.1/7.2/7.3/7.4 - MariaDB 10.3 - GLPI master
Certifié ITILv3 - RPM pour Fedora, RHEL et CentOS sur https://blog.remirepo.net/

Offline

#5 2012-10-08 19:11:17

clint.grimsley
Member
Registered: 2012-07-04
Posts: 5

Re: GLPI webservices Python API

I don"t mean the "http" part of the URL, but the part between "host" and "/plugins/webs...". Default value should be "/glpi"

I see what you mean. That makes sense.

Default is now "/glpi". It can be changed by setting the BASEURL property after instantiating the GLPI class.

It's added now.

Offline

Board footer

Powered by FluxBB