ims

package
v1.26.0-beta1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

package ims provides basic support for Incident Management System (IMS) integration, such as ServiceDesk Plus, ServiceNow, etc.

Index

Constants

View Source
const (
	PROFILE              = "__itrs_profile"
	INCIDENT_UPDATE_ONLY = "__incident_update_only"
	INCIDENT_CORRELATION = "__incident_correlation"
)
View Source
const (
	// ServiceNow fields
	SNOW_CMDB_CI_FIELD     = "cmdb_ci"
	SNOW_CORRELATION_FIELD = "correlation_id"
	SNOW_SYS_ID_FIELD      = "sys_id"
	SNOW_USER_NAME_FIELD   = "user_name"

	// ServiceNow tables
	SNOW_SYS_USER_TABLE_DEFAULT = "sys_user"
	SNOW_INCIDENT_TABLE_DEFAULT = "incident"
	SNOW_CMDB_TABLE_DEFAULT     = "cmdb_ci"

	// internal fields
	SNOW_CORRELATION     = "__snow_correlation"
	SNOW_CMDB_CI_DEFAULT = "__snow_cmdb_ci_default"
	SNOW_CMDB_SEARCH     = "__snow_cmdb_search"
	SNOW_CMDB_TABLE      = "__snow_cmdb_table"
	SNOW_INCIDENT_TABLE  = "__snow_incident_table"
)

Variables

View Source
var Endpoints = []Endpoint{}

Functions

func CorrelationID

func CorrelationID(data string) string

func NewClient

func NewClient(cf *ClientConfig) *rest.Client

NewClient creates a new rest.Client for the given URL and configuration. The client is NOT cached as each execution is a single request to the first remote proxy that responds.

func ProcessActionGroup

func ProcessActionGroup(cf *config.Config, ag ActionGroup, incident Values) bool

ProcessActionGroup evaluates the config structure and if the caller should stop processing (break) then returns `true`. The evaluation is in the following order:

  • `if`: one or more strings that are evaluated and the results parsed as a Go boolean (using strconv.ParseBool). As soon as any `if` returns a false value, evaluation stops and the function returns false
  • `set`: an object that sets the fields, unordered, to the value passed through expansion with config.ExpandString
  • `unset`: unset the list of field names
  • `subgroup`: evaluate a sub-group, terminating evaluation if the group includes `break` (after evaluating any `if` actions as true)
  • `break`: break returns true to the caller, allow them to stop processing early. This is used to stop evaluation in a parent
  • `exit`: stops further processing and exits the program immediately with an exit code given. This is used to stop processing in a parent when the child group has done everything needed and no further processing is required.

func RegisterEndpoint

func RegisterEndpoint(method, path string, handler http.HandlerFunc)

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, r *http.Request, status int) error

WriteJSONResponse writes the given value as JSON to the http.ResponseWriter with the specified status code. If there is an error encoding the value to JSON, it returns the error but does not write an error response to the client, as this function is intended to be used for writing successful responses. The caller should handle writing error responses separately if needed.

Types

type ActionGroup

type ActionGroup struct {
	If       []string          `json:"if,omitempty"`
	Set      map[string]string `json:"set,omitempty"`
	Unset    []string          `json:"unset,omitempty"`
	Subgroup []ActionGroup     `json:"subgroup,omitempty"`
	Break    []string          `json:"break,omitempty"`
	Exit     []string          `json:"exit,omitempty"`
}

type ClientConfig

type ClientConfig struct {
	URL     string        `json:"url,omitempty"`
	Token   string        `json:"token,omitempty"`
	Timeout time.Duration `json:"timeout,omitzero"`

	TLS struct {
		SkipVerify bool   `json:"skip-verify,omitzero"`
		Chain      []byte `json:"chain,omitempty"`
	} `json:"tls"`

	Trace bool `json:"trace,omitempty"`
}

type ContextKey

type ContextKey string
const (
	ContextKeyConfig   ContextKey = "config"   // Context key for passing configuration to handlers, type is *config.Config
	ContextKeyResponse ContextKey = "response" // Context key for passing response to handlers, type is *ims.Response
)

type Endpoint

type Endpoint struct {
	Method  string // HTTP method (e.g. "POST", "GET")
	Path    string // URL path (e.g. "/create", "/update") relative to application base path and including any path parameters (e.g. "/create/{id}")
	Handler http.HandlerFunc
}

type LogTransport

type LogTransport struct {
	Transport http.RoundTripper
}

func (*LogTransport) RoundTrip

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

type Response

type Response struct {
	StartTime    time.Time  `json:"start_time,omitzero"`     // time the request was received by the gateway
	EndTime      time.Time  `json:"end_time,omitzero"`       // time the response is sent by the gateway
	Duration     float64    `json:"duration,omitzero"`       // duration of processing the request in seconds
	Status       string     `json:"status,omitempty"`        // as per http.Response.Status from remote IMS, empty if request failed before reaching IMS
	StatusCode   int        `json:"status_code,omitempty"`   // as per http.Response.StatusCode from remote IMS, empty if request failed before reaching IMS
	Error        string     `json:"error,omitempty"`         // error message if applicable
	ResultDetail string     `json:"result_detail,omitempty"` // error or success detail if applicable
	Action       string     `json:"action,omitempty"`        // action taken by the gateway, e.g. "Created", "Updated", "Ignored", etc.
	ID           string     `json:"id,omitempty"`            // ID of created or updated incident if applicable
	Data         []string   `json:"data,omitempty"`          // any additional data returned by the gateway, e.g. for query results
	DataTable    [][]string `json:"data_table,omitempty"`    // table of data, if applicable. first row is column names, subsequent rows are values
	RawResponse  any        `json:"raw_response,omitempty"`
}

Response is the standard response from the IMS gateway, which may include the status code and message from the gateway itself, as well as any data returned by the gateway and the ID of the created or updated incident if applicable. The ProxyResponse field can be used to include the raw response from the proxy for debugging or logging purposes.

type Results

type Results []results

type SnowResult

type SnowResult struct {
	Results Results `json:"result,omitempty"`
	Error   struct {
		Message string `json:"message"`
		Detail  string `json:"detail"`
	} `json:"error"`
	Status string `json:"status,omitempty"`
}

snowResult is the response from ServiceNow. It contains the results of the request, which is a slice of results. It also contains an error message if the request failed. The status field is used to indicate the status of the request. If the request was successful, the status will be "success". If the request failed, the status will be "error". The error field contains the error message and detail if the request failed. The results field contains the results of the request.

type SnowResultsResponse

type SnowResultsResponse struct {
	Fields  []string `json:"fields,omitempty"`
	Results Results  `json:"results,omitempty"`
}

type Values

type Values map[string]string

Values is a simple map of string key/value pairs that can be used to represent incident fields and values. This is used throughout the IMS package to represent the fields and values of an incident, as well as the configuration for a variety of operations.

Jump to

Keyboard shortcuts

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