Documentation
¶
Overview ¶
Package goidoit is an https://www.i-doit.com/ API client implementation written in https://golang.org
Install using go get
go get github.com/cseeger-epages/i-doit-go-api
Initialize your API object
a, err := goidoit.NewLogin("https://example.com/src/jsonrpc.php", "yourapikey", "username", "password") if err != nil { log.Fatal(err) }
and do stuff like get your idoit version or search stuff etc.
v, err := a.Version() if err != nil { log.Fatal(err) } fmt.Println(v.Result[0]["version"]) s, err := a.Search("test") if err != nil { log.Fatal(err) } for _, v := range s.Result { fmt.Println(v) }
for Debuging use
goidoit.Debug(true)
and to disable TLS Certificate Verification (if you use self signed certs for i-doit)
goidoit.SkipTLSVerify(true)
Index ¶
- func Debug(v bool)
- func GetParams(a API, parameters interface{}) interface{}
- func SkipTLSVerify(v bool)
- type API
- func (a *API) CreateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error)
- func (a *API) CreateObj(Params interface{}) (GenericResponse, error)
- func (a *API) DelCatObj(ObjID int, CatgID string, CateID string) (GenericResponse, error)
- func (a *API) DeleteObj(deleteMe interface{}) (GenericResponse, error)
- func (a *API) GetCat(objID int, query interface{}) (GenericResponse, error)
- func (a *API) GetDialog(category, property string) (GenericResponse, error)
- func (a *API) GetObjTypeCat(query interface{}) (GenericResponse, error)
- func (a *API) GetObject(query interface{}) (GenericResponse, error)
- func (a *API) GetObjectByType(objType string, obj interface{}) (GenericResponse, error)
- func (a *API) GetObjectsByType(objType string) (GenericResponse, error)
- func (a *API) GetReport(RepID int) (GenericResponse, error)
- func (a API) IsLoggedIn() bool
- func (a *API) Login() error
- func (a API) Logout() error
- func (a *API) Quickpurge(ids interface{}) (GenericResponse, error)
- func (a API) Request(method string, parameters interface{}) (Response, error)
- func (a *API) Search(query string) (GenericResponse, error)
- func (a *API) UpdateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error)
- func (a *API) UpdateObj(Params interface{}) (GenericResponse, error)
- func (a *API) Version() (GenericResponse, error)
- type APIMethods
- type APIkey
- type F1
- type F2
- type GenericResponse
- type IdoitError
- type OF1
- type OF2
- type OSF1
- type Request
- type Response
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetParams ¶
func GetParams(a API, parameters interface{}) interface{}
GetParams is used to append nessesary parameters to user provided one
func SkipTLSVerify ¶
func SkipTLSVerify(v bool)
SkipTLSVerify disable SSL/TLS verification for self signed certificates
Types ¶
type API ¶
type API struct {
URL, APIkey, Username, Password, SessionID string
}
API struct used for implementing the apiMethods interface
func (*API) CreateCat ¶
func (a *API) CreateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error)
CreateCat creates a category given by its category ID and the defined content in params for a given object ID
func (*API) CreateObj ¶
func (a *API) CreateObj(Params interface{}) (GenericResponse, error)
CreateObj creates an object
func (*API) DeleteObj ¶
func (a *API) DeleteObj(deleteMe interface{}) (GenericResponse, error)
DeleteObj delete/archive/purge an object
func (*API) GetCat ¶
func (a *API) GetCat(objID int, query interface{}) (GenericResponse, error)
GetCat returns the category defined by query for an object given by its object ID
func (*API) GetDialog ¶
func (a *API) GetDialog(category, property string) (GenericResponse, error)
GetDialog returns the dialog+ defined values
func (*API) GetObjTypeCat ¶
func (a *API) GetObjTypeCat(query interface{}) (GenericResponse, error)
GetObjTypeCat returns the objecttype category
func (*API) GetObject ¶
func (a *API) GetObject(query interface{}) (GenericResponse, error)
GetObject function returns an object matching the given query
func (*API) GetObjectByType ¶
func (a *API) GetObjectByType(objType string, obj interface{}) (GenericResponse, error)
GetObjectByType function return an object of a specific type
func (*API) GetObjectsByType ¶
func (a *API) GetObjectsByType(objType string) (GenericResponse, error)
GetObjectsByType returns multiple objects of the given type
func (*API) GetReport ¶
func (a *API) GetReport(RepID int) (GenericResponse, error)
GetReport returns the report given by its id
func (*API) Quickpurge ¶
func (a *API) Quickpurge(ids interface{}) (GenericResponse, error)
Quickpurge ftw
func (*API) Search ¶
func (a *API) Search(query string) (GenericResponse, error)
Search implements the idoit.search method
func (*API) UpdateCat ¶
func (a *API) UpdateCat(ObjID int, CatgID string, Params interface{}) (GenericResponse, error)
UpdateCat updates a category given by its category ID and the defined content in params for a given object ID
func (*API) UpdateObj ¶
func (a *API) UpdateObj(Params interface{}) (GenericResponse, error)
UpdateObj updates an object
func (*API) Version ¶
func (a *API) Version() (GenericResponse, error)
Version implements idoit.version method
type APIMethods ¶
type APIMethods interface { // idoit.login using X-RPC-AUTH // goidoit.NewLogin wraps this function // eg. idoit.NewLogin(<url>, <api-key>, <username>, <password>) Login() error // check login state IsLoggedIn() bool // Destroy X-RPC-Session Logout() error // i-doit api request structure // as defined in https://kb.i-doit.com/pages/viewpage.action?pageId=7831613 // also there is a list of methods available Request(string, interface{}) (Response, error) // search CMDB using a string // // The search function does handle type assertions // for simple output usage Search(string) (GenericResponse, error) // version information Version() (GenericResponse, error) // get object(s) data, // input can be of type int, []int, string or a custom filter struct GetObject(interface{}) (GenericResponse, error) // shortcut function for Type Filter using C__OBJTYPE const GetObjectByType(string, interface{}) (GenericResponse, error) // shortcut function for get all objects of type <C__OBJTYPE__> GetObjectsByType(string) (GenericResponse, error) // get Object Type Categories using category id or constant // eg. GetObjTypeCat("C__OBJTYPE__PERSON") // or GetObjTypeCat(50) GetObjTypeCat(interface{}) (GenericResponse, error) // create objects using struct CreateObj(interface{}) (GenericResponse, error) // update object UpdateObj(interface{}) (GenericResponse, error) /* Delete/Archive/Purge object, input can be int (using the object id) or data := struct { Id int `json:"id"` Status string `json:"status"` } where Id represents the object id and Status can be C__RECORD_STATUS__ARCHIVED C__RECORD_STATUS__DELETED C__RECORD_STATUS__PURGE */ DeleteObj(interface{}) (GenericResponse, error) // fast delete option where archive, delete and purge will be executed one after another // accepts id or []id as input Quickpurge(interface{}) (GenericResponse, error) // get categorys for object using object id and category id or category constant // eg. GetCat(20,50) // or GetCat(20,"C__CATG__CUSTOM_FIELD_TEST") GetCat(int, interface{}) (GenericResponse, error) // create category using struct CreateCat(int, string, interface{}) (GenericResponse, error) // update category using struct UpdateCat(int, string, interface{}) (GenericResponse, error) // delete entry from category DelCatObj(int, string, string) (GenericResponse, error) // get report data via id GetReport(int) (GenericResponse, error) }
APIMethods is the interface describing all importand functions
type F1 ¶
type F1 struct {
Data []int `json:"ids"`
}
F1 implements an object filter type int or []int
type GenericResponse ¶
type GenericResponse struct { Jsonrpc string Result []map[string]interface{} Error IdoitError }
GenericResponse implements a generic i-doit api response structure the map is used to handle type assertions
func TypeAssertResult ¶
func TypeAssertResult(data Response) (GenericResponse, error)
TypeAssertResult is a generic type assert function
type IdoitError ¶
type IdoitError struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data"` }
IdoitError implements i-doit api error structure
type Request ¶
type Request struct { Version string `json:"version"` Method string `json:"method"` Params interface{} `json:"params"` ID int `json:"id"` }
Request implements i-doit api request structure
type Response ¶
type Response struct { Jsonrpc string `json:"jsonrpc"` Result interface{} `json:"result"` Error IdoitError `json:"error"` }
Response implements i-doit api response structure
func ParseResponse ¶
ParseResponse parses json response