Skip to content

Repository files navigation

glpi-sdk-python

Build StatusPyPi version

GLPI SDK written in Python.

Description

This SDK is written in Python to help developers integrate their apps, APIS and scripts in GLPI infrastructure. This SDK abstract the GLPI Rest API.

To usage it, you should have username, password and API-Token from your GLPI server.

See also:

Install

Just install from:

  • PyPi:

    pip install glpi
  • repository (development):

    pip install -e git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi
  • requirements.txt (development)

    pip install -r requirements-dev.txt

Usage

You should enable the GLPI API and generate an App Token.

Please, export these environments variables with yours config:

export username = "GLPI_USER"export password = "GLPI_USER"export url = 'http://glpi.example.com/apirest.php'export glpi_app_token = "GLPI_API_TOKEN"

Then import it in your script and create a glpi API connection:

importosfromglpiimportGLPIurl=os.getenv("GLPI_API_URL") orNoneuser=os.getenv("GLPI_USERNAME") orNonepassword=os.getenv("GLPI_PASSWORD") orNonetoken=os.getenv("GLPI_APP_TOKEN") orNoneglpi=GLPI(url, token, (user, password))

To usage the SDK, you just set the DBTM item that you want and get information from GLPI.

The Item value must be valid, otherwise you will get the following error.

[
"ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM",
"resource not found or not an instance of CommonDBTM; view documentation in your browser at http://<GLPI_URL>/apirest.php/#ERROR_RESOURCE_NOT_FOUND_NOR_COMMONDBTM"
]

Get all Tickets

print"Getting all Tickets: "printjson.dumps(glpi.get_all('ticket'),
indent=4,
separators=(',', ': '),
sort_keys=True)

Create an Ticket

ticket_payload= {
'name': 'New ticket from SDK',
'content': '>>>> Content of ticket created by SDK API <<<'
}
ticket_dict=glpi.create('ticket', ticket_payload)
ifisinstance(ticket_dict, dict):
print"The ticket request was sent. See results: "printjson.dumps(ticket_dict,
indent=4,
separators=(',', ': '),
sort_keys=True)

Get ticket by ID

print"Getting Ticket with ID 1: "printjson.dumps(glpi.get('ticket', 1),
indent=4,
separators=(',', ': '),
sort_keys=True)

Profile information

print"Getting 'My' profile: "printjson.dumps(glpi.get('getMyProfiles'),
indent=4,
separators=(',', ': '),
sort_keys=True)

Location

print"Getting 'Locations': "printjson.dumps(glpi.get('location'),
indent=4,
separators=(',', ': '),
sort_keys=True)

Full example

TODO: create an full example with various Items available in GLPI Rest API.

CONTRIBUTING

See CONTRIBUTING.md

About

Upstream Repo: https://github.com/truly-systems/glpi-sdk-python << GLPI SDK written in python.

Resources

Contributing

Stars

7 stars

Watchers

3 watching

Forks

Releases

Packages

Contributors

Languages