infocmdb

package
v1.1.1-0...-115938a Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ErrFailedToCreateInfoCMDB  = errors.New("failed to create infocmdb object")
	ErrNoCredentials           = errors.New("must provide credentials")
	ErrNotImplemented          = errors.New("not implemented")
	ErrNoResult                = errors.New("query returned no result")
	ErrTooManyResults          = errors.New("query returned to many results, expected one")
	ErrWebserviceResponseNotOk = errors.New("webservice response was not ok")
)
View Source
var (
	ErrLoginFailed = errors.New("login status not ok")
)

Functions

This section is empty.

Types

type AttributeValueType

type AttributeValueType string
const (
	ATTRIBUTE_VALUE_TYPE_TEXT    AttributeValueType = "value_text"
	ATTRIBUTE_VALUE_TYPE_DATE    AttributeValueType = "value_date"
	ATTRIBUTE_VALUE_TYPE_DEFAULT AttributeValueType = "value_default"
	ATTRIBUTE_VALUE_TYPE_CI      AttributeValueType = "value_ci"
)

type CiRelationDirection

type CiRelationDirection string
const (
	CI_RELATION_DIRECTION_ALL             CiRelationDirection = "all"
	CI_RELATION_DIRECTION_DIRECTED_FROM   CiRelationDirection = "directed_from"
	CI_RELATION_DIRECTION_DIRECTED_TO     CiRelationDirection = "directed_to"
	CI_RELATION_DIRECTION_BIDIRECTIONAL   CiRelationDirection = "bidirectional"
	CI_RELATION_DIRECTION_OMNIDIRECTIONAL CiRelationDirection = "omnidirectional"
)

type Cmdb

type Cmdb struct {
	Config Config
	Cache  *cache.Cache
}

func New

func New() (i *Cmdb)

New returns a new Cmdb Client to access the V1 Api

func (*Cmdb) CallWebservice

func (i *Cmdb) CallWebservice(method string, service string, serviceName string, params url.Values, variable interface{}) (err error)
Example (Post_query)
cmdb := Cmdb{}
utilTesting.New().SetValidConfig(&cmdb.Config)

params := url.Values{
	"argv1": {"1"},
}

ret := ""
err := cmdb.CallWebservice(http.MethodPost, "query", "int_getListOfCiIdsOfCiType", params, &ret)
if err != nil {
	log.Error(err)
	return
}
fmt.Println("Post: ", ret)
Output:

Post:  {"status":"OK","data":[{"ciid":"1"},{"ciid":"2"}]}

func (*Cmdb) LoadConfig

func (i *Cmdb) LoadConfig(config Config)

func (*Cmdb) LoadConfigFile

func (i *Cmdb) LoadConfigFile(path string) (err error)
Example (Fail)
i := Cmdb{}
err := i.LoadConfigFile("/test_missing.yml")
if err != nil {
	fmt.Println("loading failed")
	return
}
fmt.Printf("Config: %v\n", i.Config)
fmt.Printf("BasePath: %s\n", i.Config.CmdbBasePath)
Output:

loading failed

func (*Cmdb) Login

func (i *Cmdb) Login() error
Example
cmdb := Cmdb{}
utilTesting.New().SetValidConfig(&cmdb.Config)

err := cmdb.Login()
if err != nil {
	log.Error(err)
	return
}

fmt.Printf("Login ok, ApiKey(len): %d\n", len(cmdb.Config.ApiKey))
Output:

Login ok, ApiKey(len): 30
Example (With_ApiKey)
cmdb := Cmdb{}
utilTesting.New().SetValidConfig(&cmdb.Config)

err := cmdb.Login()
if err != nil {
	log.Error(err)
	return
}

fmt.Printf("Login ok, ApiKey(len): %d\n", len(cmdb.Config.ApiKey))
Output:

Login ok, ApiKey(len): 30

func (*Cmdb) LoginWithApiKey

func (i *Cmdb) LoginWithApiKey(url string, apikey string) error

func (*Cmdb) LoginWithUserPass

func (i *Cmdb) LoginWithUserPass(apiUrl string, username string, password string) error

func (*Cmdb) SendNotification

func (i *Cmdb) SendNotification(notifyName string, params NotifyParams) (resp NotificationResponse, err error)

func (*Cmdb) Webservice

func (i *Cmdb) Webservice(ws string, params url.Values) (r string, err error)

Webservice queries a given webservice with all params supplied Returns err != nil if query fails

Example (Int_getListOfCiIdsOfCiType)
cmdb := Cmdb{}
utilTesting.New().SetValidConfig(&cmdb.Config)

err := cmdb.Login()
if err != nil {
	log.Error(err)
	return
}

params := url.Values{}
params.Add("argv1", "1")
ret, err := cmdb.Webservice("int_getListOfCiIdsOfCiType", params)
if err != nil {
	log.Error(err)
	return
}
fmt.Printf("Return: %v\n", ret)
Output:

Return: {"status":"OK","data":[{"ciid":"1"},{"ciid":"2"}]}

type Config

type Config struct {
	ApiUrl       string `yaml:"apiUrl"`
	ApiUser      string `yaml:"apiUser"`
	ApiPassword  string `yaml:"apiPassword"`
	ApiKey       string
	CmdbBasePath string `yaml:"CmdbBasePath"`
}

type NotificationResponse

type NotificationResponse struct {
	SentTo []SendNotificationData
}

type NotifyParams

type NotifyParams struct {
	From             string
	FromName         string
	Recipients       []string
	RecipientsCC     []string
	RecipientsBCC    []string
	Subject          string
	AttachmentsPaths []string
	OtherParams      map[string]string
}

type ResponseStatus

type ResponseStatus struct {
	Status string `json:"status"`
}

type ResultLogin

type ResultLogin struct {
	Status string `json:"status"`
	ApiKey string `json:"apikey"`
}

type SendNotificationData

type SendNotificationData struct {
	Type    string `json:"type"`
	Address string `json:"address"`
}

Jump to

Keyboard shortcuts

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