GLPI SDK written in Python.
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:
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
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"
]print"Getting all Tickets: "printjson.dumps(glpi.get_all('ticket'),
indent=4,
separators=(',', ': '),
sort_keys=True)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)print"Getting Ticket with ID 1: "printjson.dumps(glpi.get('ticket', 1),
indent=4,
separators=(',', ': '),
sort_keys=True)print"Getting 'My' profile: "printjson.dumps(glpi.get('getMyProfiles'),
indent=4,
separators=(',', ': '),
sort_keys=True)print"Getting 'Locations': "printjson.dumps(glpi.get('location'),
indent=4,
separators=(',', ': '),
sort_keys=True)TODO: create an full example with various Items available in GLPI Rest API.
See CONTRIBUTING.md