hpsm

package module
v0.0.0-...-319827d Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2019 License: MIT Imports: 14 Imported by: 0

README

go-hpsm

HP Service Manager Rest API Go wrapper.

Requirements

  • HP SM 9.35+
  • Go 1.13

Examples

Get

Retrieves a single incident

const username = ""
const password = ""
const baseURL = ""

tp := hpsm.BasicAuthTransport{
    Username: username,
    Password: password,
}
client, err := hpsm.NewClient(tp.Client(), baseURL)
if err != nil {
    fmt.Printf("\nerror: %v\n", err)
    return
}
im, _, err := client.Incident.Get("IM13696192")
if err != nil {
    fmt.Printf("\nerror: %v\n", err)
    return
}
fmt.Println(im)

Query all incidents

const username = ""
const password = ""
const baseURL = ""

tp := hpsm.BasicAuthTransport{
    Username: username,
    Password: password,
}
client, err := hpsm.NewClient(tp.Client(), baseURL)
if err != nil {
    fmt.Printf("\nerror: %v\n", err)
    return
}
ims, _, err := client.Incident.Search("(IMTicketStatus=\"Open\" or IMTicketStatus=\"Reopened\" or IMTicketStatus=\"Work in progress\")", nil)
if err != nil {
    fmt.Printf("\nerror: %v\n", err)
    return
}
for _, im := range ims {
    fmt.Println(im)
}
TODO
  • Close Incident
  • Create Incident
  • Create Incident With Attachments
  • Resolve incident
  • Update incident

Most of the code adapted from go-jira.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. The caller is responsible to analyze the response body. The body can contain JSON (if the error is intended) or xml.

func NewSMError

func NewSMError(resp *http.Response, httpError error) error

NewSMError creates a new Service Manager Error

Types

type AuthenticationService

type AuthenticationService struct {
	// contains filtered or unexported fields
}

AuthenticationService handles authentication for the Service Manager instance / API.

type BasicAuthTransport

type BasicAuthTransport struct {
	Username string
	Password string

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

BasicAuthTransport is an http.RoundTripper that authenticates all requests using HTTP Basic Authentication with the provided username and password.

func (*BasicAuthTransport) Client

func (t *BasicAuthTransport) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated using HTTP Basic Authentication. This is a nice little bit of sugar so we can just get the client instead of creating the client in the calling code. If it's necessary to send more information on client init, the calling code can always skip this and set the transport itself.

func (*BasicAuthTransport) RoundTrip

func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface. We just add the basic auth and return the RoundTripper for this transport type.

type Client

type Client struct {

	// Services used for talking to different parts of the API.
	Authentication *AuthenticationService
	Incident       *IMService
	// contains filtered or unexported fields
}

A Client manages communication with the API.

func NewClient

func NewClient(httpClient httpClient, baseURL string) (*Client, error)

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (*http.Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. If specified, the value pointed to by body is JSON encoded and included as the request body.

type CookieAuthTransport

type CookieAuthTransport struct {
	Username string
	Password string
	AuthURL  string

	// SessionObject is the authenticated cookie string.s
	// It's passed in each call to prove the client is authenticated.
	SessionObject []*http.Cookie

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

CookieAuthTransport is an http.RoundTripper that authenticates all requests using cookie-based authentication.

Note that it is generally preferable to use HTTP BASIC authentication with the REST API. However, this resource may be used to mimic the behaviour of login page (e.g. to display login errors to a user).

func (*CookieAuthTransport) Client

func (t *CookieAuthTransport) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated using cookie authentication

func (*CookieAuthTransport) RoundTrip

func (t *CookieAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip adds the session object to the request.

type Error

type Error struct {
	HTTPError     error
	ErrorMessages []string          `json:"errorMessages"`
	Errors        map[string]string `json:"errors"`
}

Error message from the Service Manager

func (*Error) Error

func (e *Error) Error() string

Error is a short string representing the error

func (*Error) LongError

func (e *Error) LongError() string

LongError is a full representation of the error as a string

type IM

type IM struct {
	AffectedCI      string                `json:"AffectedCI"`
	Area            string                `json:"Area"`
	Assignee        string                `json:"Assignee"`
	AssignmentGroup string                `json:"AssignmentGroup"`
	Category        string                `json:"Category"`
	ClosedBy        string                `json:"ClosedBy"`
	ClosedTime      time.Time             `json:"ClosedTime"`
	ClosureCode     string                `json:"ClosureCode"`
	Company         string                `json:"Company"`
	Description     []string              `json:"Description"`
	Impact          string                `json:"Impact"`
	IncidentID      string                `json:"IncidentID"`
	Location        string                `json:"Location"`
	OpenTime        time.Time             `json:"OpenTime"`
	OpenedBy        string                `json:"OpenedBy"`
	ProblemType     string                `json:"ProblemType"`
	SLAAgreementID  int                   `json:"SLAAgreementID"`
	Service         string                `json:"Service"`
	Solution        []string              `json:"Solution"`
	Status          string                `json:"Status"`
	Subarea         string                `json:"Subarea"`
	TicketOwner     string                `json:"TicketOwner"`
	Title           string                `json:"Title"`
	UpdatedBy       string                `json:"UpdatedBy"`
	UpdatedTime     time.Time             `json:"UpdatedTime"`
	Urgency         string                `json:"Urgency"`
	OtherFields     tcontainer.MarshalMap // Rest of the fields should go here.
}

IM represents a Service Manager incident.

func (*IM) MarshalJSON

func (i *IM) MarshalJSON() ([]byte, error)

MarshalJSON is a custom JSON marshal function for the IM struct. It handles custom fields and maps those from / to "OtherFields" key.

func (*IM) UnmarshalJSON

func (i *IM) UnmarshalJSON(data []byte) error

UnmarshalJSON is a custom JSON marshal function for the IM struct. It handles custom fields and maps those from / to "OtherFields" key.

type IMService

type IMService struct {
	// contains filtered or unexported fields
}

IMService handles IMs for the API.

func (*IMService) Get

func (s *IMService) Get(incidentID string) (*IM, *http.Response, error)

Get returns a full representation of the incident for the given id.

func (*IMService) Search

func (s *IMService) Search(q string, options *SearchOptions) ([]IM, *http.Response, error)

Search will search for incidents according to the query

type SearchOptions

type SearchOptions struct {
	// Sort: The sort field and order to be returned. {primaryField}:{ascending|descending}[,{secondaryField}]
	Sort string `url:"sort,omitempty"`
	// StartAt: The starting index of the returned projects. Base index: 0.
	StartAt int `url:"start,omitempty"`
	// Indicates the number of collection members to be included in the response. Min value: 1.
	Count int `url:"count,omitempty"`
	// Represents a collection. Values: summary, condense (default), expand.
	View string `url:"view,omitempty"`
}

SearchOptions specifies the optional parameters to methods that support pagination.

type Session

type Session struct {
	Cookies []*http.Cookie
}

Session represents a Session JSON response by the API.

Directories

Path Synopsis
examples
get

Jump to

Keyboard shortcuts

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