GLPI is a library that allows you to connect to the GLPI API. The first version can only query the computers part with the possibility of accessing the fields of the plugins.
-
Get informations of computer with id
computer, err := glpi.GetComputer( IdOfComputer)
-
Get all computer into GLPI computers, err := glpi.GetAllComputers()
-
Find a computer with criteria, here I am looking for all computers that contains "srv"
listcriterias := make([]CriteriaSearch, 1, 1) listcriterias[0] = CriteriaSearch{ Link: "AND", Field: "Name", Searchtype: "contains" Name: "srv" } computersSearch, nbreComputer, err := glpi.SearchComputers(listcriterias, Range{Min: 0, Max: 10})
-
Find a computer with fields from a plugin, here the fields had id 12230 ( Use a part 5 for find "ID" field )
type ComputerAddField struct { Id int
json:"2"
Name stringjson:"1"
Company stringjson:"12230"
} forcedisplay := make([]interface{}, 3) forcedisplay[0] = 1 forcedisplay[0] = 2 forcedisplay[2] = 76665interfaceListComputerInterface, nbreComputer, err := glpi.SearchWithName("Computer", ComputerAddField{}, listcriterias, forcedisplay, Range{Min: 0, Max: 10})
-
Find a fields of items, here the fields had id 12230
mapOptions,err:=glpi.ListSearchOptions(Computer{}) for id, fieldFeature := range mapOptions { fmt.Println(id, ": ", fieldFeature.Name) }
Now it's your turn. My library does not use all the items but it is relatively easy to complete ;)
© VALMIR, 2022~time.Now
Released under the [MIT License]