goglpi

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2022 License: MIT Imports: 8 Imported by: 0

README

GoGLPI

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.

Examples:

  1. Get informations of computer with id

    computer, err := glpi.GetComputer( IdOfComputer)

  2. Get all computer into GLPI computers, err := glpi.GetAllComputers()

  3. 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})

  4. 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 string json:"1" Company string json:"12230" } forcedisplay := make([]interface{}, 3) forcedisplay[0] = 1 forcedisplay[0] = 2 forcedisplay[2] = 76665

    interfaceListComputerInterface, nbreComputer, err := glpi.SearchWithName("Computer", ComputerAddField{}, listcriterias, forcedisplay, Range{Min: 0, Max: 10})

  5. 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 ;)

License

© VALMIR, 2022~time.Now

Released under the [MIT License]

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Certificate added in v0.0.2

type Certificate struct {
	Id                  int `json:"ID"`
	Name                string
	Otherserial         string
	Entities_id         int
	Is_recursive        int
	Comment             string
	Is_deleted          int
	Is_demplate         int
	Template_name       string
	Certificatetypes_Id int
	DnsName             string
	Dns_suffix          string
	Users_id_tech       int
	Groups_id_tech      int
	Locations_id        int
	Manufacturers_id    int
	Contact             string
	Contact_num         string
	Users_id            int
	Is_autosign         int
	Date_expiration     string // not format standard json
	States_id           int
	Command             string
	Certificate_request string
	Certificate_item    string
	Date_creation       string
	Date_mod            string
}

type Certificates added in v0.0.2

type Certificates []Certificate

GLPI struct Certificate

type Computer

type Computer struct {
	Id                   int `json:"2"`
	Entities_id          int
	Entities             string `json:"80"`
	Name                 string `json:"1"`
	Serial               string
	Otherserial          string
	Contact              string
	Contact_num          string //
	Users_id_tech        int
	Groups_id_tech       int
	Comment              string
	Date_mod             string // Beware full date had not a good format
	Autoupdatesystems_id int
	Locations_id         int
	Networks_id          int
	Computermodels_id    int
	Computertypes_id     int
	Is_template          int
	Template_name        string //
	Manufacturers_id     int
	Is_deleted           int
	Is_dynamic           int
	Users_id             int
	Groups_id            int
	States_id            int
	Ticket_tco           string
	Uuid                 string
	Date_creation        string // Beware full date had not a good format
	Links                Links
}

type Computers

type Computers []Computer

GLPI struct Computer

type CriteriaSearch

type CriteriaSearch struct {
	Link       string
	Field      interface{}
	Searchtype string
	Value      interface{}
}

CriteriaSearch:

type GLPI

type GLPI struct {
	Session_token string
	// contains filtered or unexported fields
}

GLPI struct

func Init

func Init(url, apptoken, usertoken string) (*GLPI, error)

Init: Init glpi connexion

func (GLPI) GetAllCertificates added in v0.0.2

func (glpi GLPI) GetAllCertificates() (*Certificates, error)

GetCertificate: Get all Certificate

func (GLPI) GetAllComputers

func (glpi GLPI) GetAllComputers() (*Computers, error)

GetAllComputers: Get all computers Beacare full Entities membre is not complete ( use search )

func (GLPI) GetCertificate added in v0.0.2

func (glpi GLPI) GetCertificate(id int) (*Certificate, error)

GetCertificate: Get info of Certificate

func (GLPI) GetComputer

func (glpi GLPI) GetComputer(id int) (*Computer, error)

GetComputer: Get info of computer

func (GLPI) ListSearchOptions

func (glpi GLPI) ListSearchOptions(item Item) (map[int]SearchOption, error)

ListSearchOptions: Get all fields for requesting tiem

func (GLPI) Search

func (glpi GLPI) Search(item Item, criterias []CriteriaSearch, forcedisplays []interface{}, rangeLimit Range) (interface{}, int, error)

Search: Search information for item ( Computer, ...)

func (GLPI) SearchComputers

func (glpi GLPI) SearchComputers(criterias []CriteriaSearch, rangeLimit Range) ([]Computer, int, error)

Search computer by criterias, return Computer with IdComputer,Name and Entity

func (GLPI) SearchWithName

func (glpi GLPI) SearchWithName(itemName string, item Item, criterias []CriteriaSearch, forcedisplays []interface{}, rangeLimit Range) (interface{}, int, error)

Search: Search information for customer item ( Computer with Entity, ...)

type Item

type Item interface{}

type Items

type Items []Item
type Link struct {
	Rel  string
	Href string
}
type Links []Link

Link: Struct link information GLPI

type Range

type Range struct {
	Min int
	Max int
}

Range of search

func (Range) String

func (rangeLimit Range) String() string

type SearchOption

type SearchOption struct {
	Name     string
	Table    string
	Field    string
	Datatype string
	Uid      string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL