-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGLPIClient.py
More file actions
1386 lines (1190 loc) · 49.7 KB
/
GLPIClient.py
File metadata and controls
1386 lines (1190 loc) · 49.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
#-*- coding:utf-8 -*-
#import urllib, urllib2
import xmlrpclib
#import simplejson as json
import pprint
import sys, os, warnings
import getpass
class Client:
""".. note:: If any boolean arguments are defined, they're \
automatically added to the GET request, which means the \
webservices API will treat them as being true. You've been warned. """
def __init__(self, url=None):
"""
Create a CLient instance
:type url: string
:param url: URL to the xmlrpc.php file (http://localhost/plugins/webservices/xmlrpc.php)
"""
if url:
self.url=url
def __request__(self,params):
return self.url + urllib.urlencode(params)
def connect(self,login_name=None,login_password=None):
"""
Connect to a running GLPI instance that has the webservices
plugin enabled.
Returns True if connection was successful.
:type login_name: string
:type login_password: string
:param login_name: your GLPI username
:param login_password: your GLPI password
"""
self.login_name = None
self.login_password = None
if login_name: self.login_name = login_name
if login_password: self.login_password = login_password
self.server = xmlrpclib.Server(self.url)
if self.login_name != None and self.login_password != None:
# params = {'login_name':login_name,
# 'login_password':login_password}
# 'login_password':login_password,
# 'method':'glpi.doLogin'}
params = {'login_name':login_name,
'username':login_name,
'login_password':login_password,
'password':login_password
}
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
response = self.server.glpi.doLogin(params)
try:
# session_id = json.loads(response)['session']
session_id = response['session']
self.session = session_id
return True
except:
raise Exception("Login incorrect or server down")
else:
warnings.warn("Connected anonymously, will only be able to use non-authenticated methods")
return self
"""
Un-authenticated methods
"""
def get_server_status(self,_help=None):
"""
Gets server status information from the GLPI server, mostly
stating that things are OK.
:type _help: bool
:param _help: get usage information
"""
# params = {'method':'glpi.status'}
if _help: params['help'] = _help
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
# return json.loads(response)
response = self.server.glpi.status()
return response
def test(self,_help=None):
"""
Simple ping test method.
Returns version information of GLPI and of plugins that provide methods
:type _help: boolean
:param _help: get usage information
"""
# params = {'method':'glpi.test'}
if _help: params['help'] = _help
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
# return json.loads(response)
response = self.server.glpi.test()
return response
# listAllMethods METHOD NOT KNOWN ???
def list_all_methods(self,_help=None):
"""
Returns a list of all methods allowed to the current client
:type _help: boolean
:param _help: get usage information
"""
# params = {'method':'glpi.listAllMethods'}
if _help: params['help'] = _help
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
# return json.loads(response)
response = self.server.listAllMethods()
return response
def list_entities(self,count=None,_help=None):
"""
Returns a list of current entities defined by server
configuration for the client, or currently B{activated} for
the user (when authenticated)
:type _help: boolean
:param _help: get usage information
"""
# params = {'method':'glpi.listAllMethods'}
params = {}
if self.session: params['session'] = self.session
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
# return json.loads(response)
response = self.server.listEntities(params)
return response
def list_know_base_items(self, faq=None, category=None,
contains=None, count=None, _help=None):
"""
Returns a list of Knowbase or FAQ items available for the
current user (when authenticated) or in the public FAQ (if
configured)
:type faq: boolean
:type category: integer
:type contains: string
:type count: list
:type _help: boolean
:param faq: defaults to 0, returns FAQ
:param category: ID of the category to search in
:param contains: string to search for
:param count: iterable containing start and limit integers
:param _help: get usage information
"""
# params = {'method':'glpi.listKnowBaseItems'}
params = {}
if self.session: params['session'] = self.session
if faq: params['faq'] = faq
if category: params['category'] = category
if contains: params['contains'] = contains
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# request = urllib2.Request(self.url + urllib.urlencode(params))
# response = urllib2.urlopen(request).read()
# return json.loads(response)
response = self.server.glpi.listKnowBaseItems()
return response
# TODO :
# def get_know_base_item
# TODO :
# def get_document
"""
User context methods
"""
def disconnect(self):
"""
Return a hashtable with message = Bye
"""
params = {'session':self.session}
response = self.server.glpi.doLogout(params)
return response
def get_my_info(self):
"""
# Returns JSON serialized information about the currently logged in user.
Return a hashtable about the currently logged in user.
"""
# params = {'method':'glpi.getMyInfo',
# 'session':self.session}
params = {'session':self.session}
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.getMyInfo(params)
return response
def list_my_profiles(self):
"""
# Returns JSON serialized profile information about the currently logged in user.
Return a array of hashtable about the profile of currently logged in user.
"""
# params = {'method':'glpi.listMyProfiles',
# 'session':self.session}
params = {'session':self.session}
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listMyProfiles(params)
return response
# TODO :
# def set_my_profile
def list_my_entities(self):
"""
# Returns JSON serialized informations about the entities of the currently logged in user.
Return a hashtable if succeed of new selected profile of the currently logged in user.
"""
# params = {'method':'glpi.listMyEntities',
# 'session':self.session}
params = {'session':self.session}
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listMyEntities(params)
return response
# TODO :
# def set_my_entity
"""
Information retrieval methods
"""
def get_ticket(self,ticket_id,id2name=None,_help=None):
"""
# Returns a JSON serialized ticket
Return a hashtable
:type ticket_id: integer
:type id2name: string
:type _help: boolean
:param ticket_id: ID of the ticket being requested
:param id2name: option to enable id to name translation of dropdown fields
:param _help: return JSON serialized help about the API call
"""
# params = {'method':'glpi.getTicket',
# 'ticket':ticket_id,
# 'session':self.session}
params = {'session':self.session,
'ticket':ticket_id}
if id2name: params['id2name'] = str(id2name)
if _help: params['help'] = help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.getTicket(params)
return response
def get_object(self,itemtype,_id,show_label=None,
show_name=None,with_networkport=None,
_help=None):
"""
Returns an object from the GLPI server. itemtype can take `one of the following <https://forge.indepnet.net/embedded/glpi/annotated.html>`_
:type itemtype: string
:type _id: integer
:type show_label: boolean
:type show_name: boolean
:type _help: boolean
:param itemtype: type of the item being requested
:param _id: ID of the item being requested
:param show_label: show label
:param show_name: show name
:param _help: get usage information
"""
# params = {'method':'glpi.getObject',
# 'session':self.session}
params = {'session':self.session}
if itemtype: params['itemtype'] = itemtype
if _id: params['id'] = _id
if show_label: params['show_label'] = show_label
if show_name: params['show_name'] = show_name
if with_networkport: params['with_networkport'] = with_networkport
if _help: params['help'] = _help
print (params)
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.getObject(params)
return response
# DEPRECATED ! SEE GETOBJECT
# def get_computer(self,computer_id,**kwargs):
# """
# Returns a JSON serialized computer object from the GLPI server
#
# :type computer_id: integer
# :type id2name: boolean
# :type infocoms: boolean
# :type contracts: boolean
# :type networkports: boolean
# :type help: boolean
# :param computer_id: computerID
# :param id2name: option to enable id to name translation of dropdown fields
# :param infocoms: return infocoms associated with the computer
# :param contracts: return contracts associated with the network equipment
# :param networkports: return information about computer's network ports
# :param help: get usage information
# """
# params = {'method':'glpi.getComputer',
# 'session': self.session,
# 'computer':computer_id}
#
# ###################### Tue Oct 9 17:22:34 EDT 2012 ##############
# # I realized today that I don't like to type very much, using
# # kwargs is cleaner, if anyone has a major issue with that,
# # speak now or forever hold your peace. -CDG
# ################ old stuff here ##################################
# # print self.__request__(params)
# # if id2name: params['id2name'] = id2name
# # if infocoms: params['infocoms'] = infocoms
# # if contracts: params['contracts'] = contracts
# # if networkports: params['networkports'] = networkports
# # if _help: params['help'] = _help
#
# for arg in kwargs:
# params[arg] = kwargs[arg]
# print (params)
#
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
# DEPRECATED ! SEE GETITEMINFOCOMS
# TODO : replace by
# def get_item_infocoms
def get_computer_infocoms(self,computer_id,id2name=None,_help=None):
"""
# Return a JSON serialized list of computer infocoms from the GLPI server.
Return a hashtable
:type computer_id: integer
:type id2name: boolean
:type _help: boolean
:param computer_id: ID of the computer
:param id2name: associate labels with IDs and return with the rest of the JSON result
:param _help: return JSON serialized information about this API call
"""
params = {'method':'glpi.getComputerInfoComs',
'session':self.session,
'id':computer_id}
if id2name: params['id2name'] = id2name
if _help: params['help'] = _help
response = urllib2.urlopen(self.__request__(params))
return json.loads(response.read())
# DEPRECATED ! SEE GETITEMCONTRACTS
# TODO : replace by
# def get_item_contracts
def get_computer_contracts(self,computer_id,id2name=None,_help=None):
"""
Return a JSON serialized list of computer contracts from the
GLPI server.
:type computer_id: integer
:type id2name: boolean
:type _help: boolean
:param computer_id: ID of the computer
:param id2name: associate labels with IDs and return with the rest of the JSON result
:param _help: return JSON serialized information about this API call
"""
params = {'method':'glpi.getComputerContracts',
'session':self.session}
if id2name: params['id2name'] = id2name
if _help: params['help'] = _help
response = urllib2.urlopen(self.__request__(params))
return json.loads(response.read())
# DEPRECATED ! SEE GETOBJECT
# def get_network_equipment(self,network_equipment_id,id2name=None,infocoms=None,
# contracts=None,networkports=None,_help=None):
# """
# Return a JSON serialized network object from the GLPI
# server.
#
# :type network_equipment_id: integer
# :type id2name: boolean
# :type infocoms: boolean
# :type contracts: boolean
# :type networkports: boolean
# :type _help: boolean
# :param network_equipment_id: ID of the network equipment
# :param id2name: associate labels with IDs and return with the rest of the JSON result
# :param infocoms: return infocoms associated with the network equipment
# :param contracts: return contracts associated with the network equipment
# :param networkports: return information about the equipments network ports
# :param _help: return JSON serialized information about this API call
# """
# params = {'method':'glpi.getNetworkEquipment',
# 'session':self.session,
# 'id':network_equipment_id}
#
# if id2name: params['id2name'] = id2name
# if infocoms: params['infocoms'] = infocoms
# if contracts: params['contracts'] = contracts
# if networkports: params['networkports'] = networkports
# if _help: params['help'] = _help
#
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
# DEPRECATED ! SEE GETITEMINFOCOMS
# def get_infocoms(self,_id,itemtype,id2name=None,_help=None):
# """
# Return a JSON serialized list of computer's financial
# information from the GLPI server.
#
# :type _id: integer
# :type itemtype: integer
# :type id2name: boolean
# :type _help: boolean
# :param _id: object id
# :param itemtype: the object type
# :param id2name: option to enable id to name translation of dropdown fields
# :param _help: Get help from the server
# """
# params = {'method':'glpi.getInfoComs',
# 'session':self.session,
# 'id':infocoms_id,
# 'itemtype':itemtype}
# if id2name: params['id2name'] = id2name
# if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
# DEPRECATED ! SEE GETITEMCONTRACTS
# def get_contracts(self,_id,id2name=None,_help=None):
# """
# Return a JSON serialized list of contracts from the GLPI server.
#
# :type _id: integer
# :type id2name: boolean
# :type _help: boolean
# :param _id: computer id
# :param id2name: option to enable id to name translation of dropdown fields
# :param _help: get help from server
# """
# params = {'method':'glpi.getContracts',
# 'session':self.session,
# 'id':_id}
# if id2name: params['id2name'] = id2name
# if _help: params['help'] = _help
#
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
def get_network_ports(self,_id,itemtype,id2name=None,_help=None):
"""
Return a JSON serialized list of network ports from the GLPI
server.
:type _id: integer
:type itemtype: string
:type id2name: boolean
:type _help: boolean
:param _id: object ID
:param itemtype: values can be:
- Computer
- Peripheral
- NetworkEquipment
- Phone
- Printer
:param id2name: option to enable id to name translation of dropdown fields
:param _help: get help from server about this api call
"""
# params = {'method':'glpi.getNetworkports',
# 'session':self.session,
# 'id':_id,
# 'itemtype':itemtype}
params = {'session':self.session,
'id':_id,
'itemtype':itemtype}
if id2name: params['id2name'] = id2name
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.getNetworkports(params)
return response
# DEPRECATED ! SEE LISTOBJECTS
# def list_computers(self,count=None,_help=None):
# """
# Return a JSON serialized list of computers from the GLPI
# server.
#
# :type count: list
# :type _help: boolean
# :param count: iterable containing start and limit integers
# :param _help: get help from server about this API call
# """
# params = {'method':'glpi.listComputers',
# 'session':self.session}
# if count:
# if len(count) < 2:
# raise Exception("List needs to include a start and limit integer")
# if len(count) == 2:
# params['start'] = count[0]
# params['limit'] = count[1]
# if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
def list_dropdown_values(self,dropdown,_id=None,parent=None,name=None,
helpdesk=None,criteria=None,count=None,_help=None):
"""
Return a list of dropdown menus from the GLPI server.
:type dropdown: string
:type _id: integer
:type name: string
:type helpdesk: string
:type criteria: string
:type count: list
:type _help: boolean
:param dropdown: name of the dropdown, must be a GLPI class. Special dropdowns are:
- ticketstatus
- ticketurgency
- ticketimpact
- tickettype
- ticketpriority
- ticketglobalvalidation
- ticketvalidationstatus
:param _id: id of the entry
:param name: optional string (mysql % joker allowed)
:param helpdesk: filter on 'is_helpdeskvisible' attribute (TicketCategory) (deprecated, use criteria=helpdesk intead)
:param criteria: filter on a boolean attribute (is_xxx)
:param count: iterable containing start and limit integers
:param _help: get usage information
"""
# params = {'method':'glpi.listDropdownValues',
# 'session':self.session,
# 'dropdown':dropdown}
params = {'session':self.session,
'dropdown':dropdown}
if _id: params['id'] = _id
if parent: params['parent'] = parent
if name: params['name'] = name
if helpdesk: params['helpdesk'] = helpdesk
if criteria: params['criteria'] = criteria
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listDropdownValues(params)
return response
def list_groups(self,mine=None,parent=None,under=None,withparent=None,filter=None,
count=None,_help=None):
"""
Return a JSON serialized list of groups from the GLPI server.
:type mine: boolean
:type parent: integer
:type under: integer
:type withparent: boolean
:type filter: string
:type count: list
:type _help: boolean
:param mine: only retrieve groups of connected user
:param parent: only retrieve groups under selected parent (group ID)
:param under: only retrive child groups of selected one (group ID)
:param withparent: also search for recursive group in parent's entities
:param filter: filter, options include:
- is_requester
- is_assign
- is_notify
- is_itemgroup
- is_usergroup
:param count: iterable containing start and limit integers
:param _help: get usage information
"""
# params = {'method':'glpi.listGroups',
# 'session':self.session}
params = {'session':self.session}
if mine: params['mine'] = mine
if parent: params['parent'] = parent
if under: params['under'] = under
if withparent: params['withparent'] = withparent
if filter: params['filter'] = filter
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listGroups(params)
return response
def list_helpdesk_items(self,itemtype,id2name=None,count=None,_help=None):
"""
Return a JSON serialized list of helpdesk items from the GLPI
server.
:type itemtype: string
:type id2name: boolean
:type count: list
:type _help: boolean
:param itemtype: list *allowed* items for the authenticated user to open a helpdesk ticket on, can be:
- my: returns all my devices
- empty: returns general helpdesk items
:param id2name: option to enable id to name translation of dropdown menus
:param count: iterable containing start and limit integers
:param _help: option to get usage information
"""
# params = {'method':'glpi.listHelpdeskItems',
# 'session':self.session,
# 'itemtype':itemtype}
params = {'session':self.session,
'itemtype':itemtype}
if id2name: params['id2name'] = id2name
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listHelpdeskItems(params)
return response
def list_helpdesk_types(self,count=None,_help=None):
"""
Return a JSON serialized list of helpdesk types from the GLPI
server.
:type count: list
:type _help: boolean
:param count: iterable containing start and limit integers
:param _help: get usage information
"""
# params = {'method':'glpi.listHelpdeskTypes',
# 'session':self.session}
params = {'session':self.session}
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.glpi.listHelpdeskTypes(params)
return response
def list_inventory_objects(self,count=None,_help=None):
"""
Return a JSON serialized list of inventory objects from the
GLPI server.
User must be a super admin to use this method.
:type count: list
:type _help: boolean
:param count: list including start and limit
:param _help: get usage information
"""
# params = {'method':'glpi.listInventoryObjects',
# 'session':self.session}
params = {'session':self.session}
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.glpi.listInventoryObjects(params)
return response
def list_objects(self, itemtype, location_name=None,
locations_id=None, name=None, otherserial=None,
room=None, building=None, serial=None,
show_label=None, count=None, _help=None):
"""
Return as list of objects from the GLPI server.
User must be a super admin to use this method.
:type itemtype: string
:type location_name: string
:type locations_id: integer
:type name: string
:type otherserial: string
:type room: string
:type building: string
:type serial: string
:type show_label: boolean
:type count: list
:type _help: boolean
:param itemtype: **required** itemtypes are plentiful and `available here <https://forge.indepnet.net/embedded/glpi/hierarchy.html>`_
:param location_name:
:param locations_id:
:param name:
:param otherserial:
:param room:
:param building:
:param serial:
:param show_label:
:param count: list including start and limit
:param _help: get usage information
.. note:: link in itemtypes param is a of all GLPI classes, some are not retrievable through webservices.
"""
# params = {'method':'glpi.listObjects',
# 'session':self.session,
# 'itemtype':itemtype}
params = {'session':self.session,
'itemtype':itemtype}
if location_name: params['location_name'] = location_name
if locations_id: params['location_id'] = locations_id
if name: params['name'] = name
if otherserial: params['otherserial'] = otherserial
if room: params['room'] = room
if building: params['building'] = building
if serial: params['serial'] = serial
if show_label: params['show_label'] = show_label
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listObjects(params)
return response
def list_tickets(self,mine=None,user=None, recipient=None,
group=None, mygroups=None, category=None,
status=None, startdate=None, enddate=None,
itemtype=None, item=None, entity=None,
satisfaction=None, approval=None, approver=None,
order=None, id2name=None, count=None,
_help=None):
"""
Return a JSON serialized list of tickets from the GLPI server.
:type mine: bool
:type user: int
:type recipient: int
:type group: int
:type mygroups: bool
:type category: int
:type status: string
:type startdate: datetime
:type enddate: datetime
:type itemtype: string
:type item: int
:type entity: int
:type satisfaction: int
:type approval: string
:type approver: int
:type order: list
:type count: list
:type id2name: bool
:type _help: bool
:param mine: list tickets of user B{or} recipient
:param user: ID of the victim: person concerned by the ticket
:param recipient: ID of the requestor: person who created the ticket
:param group: ID of the requestor group (must have show_all_ticket or show_group_ticket right)
:param mygroups: list of groups of current user
:param category: ID of the category of the ticket
:param status: status of the ticket, must be:
- notold
- old
- process
- waiting
- old_done
- new
- old_notdone
- assign
- plan
- all
:param startdate: start of the period where the ticket is active (close date after this)
:param enddate: end of the period where the ticket is active (open date before this)
:param itemtype: ID of the type of the item (see L{GLPIClient.list_helpdesk_types})
:param item: ID of the item, requires itemtype
:param entity: ID of the entity of the ticket
:param satisfaction: only closed tickets with a satisfaction survey:
0. all
1. waiting
2. answered
:param approval: only tickets with a validation request:
- all
- waiting
- accepted
- pending
:param approver: user ID, only tickets with a validation request sent to this user
:param order: list of allowed key names:
- id
- date
- closedate
- date_mod
- status
- users_id
- groups_id
- entities_id
- priority
:param id2name: option to enable id to name translation of dropdown menus
:param count: iterable including start and limit integers
:param _help: get usage information
"""
# params = {'method':'glpi.listTickets',
# 'session':self.session}
params = {'session':self.session}
if mine: params['mine'] = mine
if user: params['user'] = user
if recipient: params['recipient'] = recipient
if group: params['group'] = group
if mygroups: params['mygroups'] = mygroups
if category: params['category'] = category
if status: params['status'] = status
if startdate: params['startdate'] = startdate
if enddate: params['enddate'] = enddate
if itemtype: params['itemtype'] = itemtype
if item: params['item'] = item
if entity: params['entity'] = entity
if satisfaction: params['satisfaction'] = satisfaction
if approval: params['approval'] = approval
if approver: params['approver'] = approver
if order: params['order'] = order
if id2name: params['id2name'] = id2name
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listTickets(params)
return response
def list_users(self, user=None, group=None, location=None,
login=None, name=None, entity=None, parent=None,
order=None, count=None, _help=None):
"""
Return a JSON serialized list of users from the GLPI server.
:type user: int
:type group: int
:type location: int
:type login: string
:type name: string
:type entity: int
:type parent: bool
:type order: list
:type count: list
:type _help: bool
:param user: ID of user, returns single user
:param group: ID of group
:param location: ID of location
:param login: login name (mysql % joker allowed)
:param name: name (mysql % joker allowed)
:param entity: ID of entity
:param parent: search or not for user with recursive right on parent entities (default: True)
:param order: order of the result, must be one or more of the following,:
- id
- name
- login
:param count: iterable including start and limit integers
:param _help: get usage information
.. note:: order defaults to 'id'
"""
# params = {'method':'glpi.listUsers',
# 'session':self.session}
params = {'session':self.session}
if user: params['user'] = user
if group: params['group'] = group
if location: params['location'] = location
if login: params['login'] = login
if name: params['name'] = name
if entity: params['entity'] = entity
if parent: params['parent'] = parent
if order: params['order'] = order
if count:
if len(count) < 2:
raise Exception("List needs to include a start and limit integer")
if len(count) == 2:
params['start'] = count[0]
params['limit'] = count[1]
if _help: params['help'] = _help
# response = urllib2.urlopen(self.__request__(params))
# return json.loads(response.read())
response = self.server.glpi.listUsers(params)
return response
"""
Action methods
"""