servicenow

package
v0.0.0-...-5c79d48 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ResolutionStateResolved is the incident state for a resolved incident
	ResolutionStateResolved = "6"
	// ResolutionStateClosed is the incident state for a closed incident
	ResolutionStateClosed = "7"
)
View Source
const (
	// DateTimeFormat is the time format used by servicenow
	DateTimeFormat = "2006-01-02 15:04:05"
)

Variables

This section is empty.

Functions

func EncodePluginData

func EncodePluginData(data PluginData) map[string]string

EncodePluginData serializes a PluginData struct into a string map.

Types

type App

type App struct {
	*lib.Process
	common.BaseApp

	PluginName string
	// contains filtered or unexported fields
}

App is a wrapper around the base app to allow for extra functionality.

func NewServiceNowApp

func NewServiceNowApp(ctx context.Context, conf *Config) (*App, error)

NewServicenowApp initializes a new teleport-servicenow app and returns it.

func (*App) Err

func (a *App) Err() error

Err returns the error app finished with.

func (*App) Run

func (a *App) Run(ctx context.Context) error

Run initializes and runs a watcher and a callback server

func (*App) WaitReady

func (a *App) WaitReady(ctx context.Context) (bool, error)

WaitReady waits for access request watcher to start up.

type Bot

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

Bot is a serviceNow client that works with AccessRequests. It's responsible for formatting and ServiceNow incidents when an action occurs with an access request: a new request popped up, or a request is processed/updated.

func (*Bot) BroadcastAccessRequestMessage

func (b *Bot) BroadcastAccessRequestMessage(ctx context.Context, _ []common.Recipient, reqID string, reqData pd.AccessRequestData) (data accessrequest.SentMessages, err error)

BroadcastAccessRequestMessage creates a ServiceNow incident.

func (*Bot) CheckHealth

func (b *Bot) CheckHealth(ctx context.Context) error

CheckHealth checks if the bot can connect to its messaging service

func (*Bot) FetchRecipient

func (b *Bot) FetchRecipient(ctx context.Context, recipient string) (*common.Recipient, error)

FetchRecipient isn't used by the ServicenoPlugin

func (*Bot) PostReviewReply

func (b *Bot) PostReviewReply(ctx context.Context, _ string, incidentID string, review types.AccessReview) error

PostReviewReply posts an incident work note.

func (Bot) SendReviewReminders

func (b Bot) SendReviewReminders(ctx context.Context, recipients []common.Recipient, accessList *accesslist.AccessList) error

SendReviewReminders will send a review reminder that an access list needs to be reviewed.

func (*Bot) SupportedApps

func (b *Bot) SupportedApps() []common.App

SupportedApps are the apps supported by this bot.

func (*Bot) UpdateMessages

func (b *Bot) UpdateMessages(ctx context.Context, reqID string, data pd.AccessRequestData, incidentData accessrequest.SentMessages, reviews []types.AccessReview) error

UpdateMessages add notes to the incident containing updates to status. This will also resolve incidents based on the resolution tag.

type Client

type Client struct {
	ClientConfig
	// contains filtered or unexported fields
}

Client is a wrapper around resty.Client.

func NewClient

func NewClient(conf ClientConfig) (*Client, error)

NewClient creates a new Servicenow client for managing incidents.

func (*Client) CheckHealth

func (snc *Client) CheckHealth(ctx context.Context) error

CheckHealth pings servicenow to check if it is reachable.

func (*Client) CreateIncident

func (snc *Client) CreateIncident(ctx context.Context, reqID string, reqData RequestData) (Incident, error)

CreateIncident creates an servicenow incident.

func (*Client) GetOnCall

func (snc *Client) GetOnCall(ctx context.Context, rotaID string) ([]string, error)

GetOnCall returns the current users on-call for the given rota ID.

func (*Client) GetUserName

func (snc *Client) GetUserName(ctx context.Context, userID string) (string, error)

GetUserName returns the name for the given user ID

func (*Client) PostReviewNote

func (snc *Client) PostReviewNote(ctx context.Context, incidentID string, review types.AccessReview) error

PostReviewNote posts a note once a new request review appears.

func (*Client) ResolveIncident

func (snc *Client) ResolveIncident(ctx context.Context, incidentID string, resolution Resolution) error

ResolveIncident resolves an incident and posts a note with resolution details.

type ClientConfig

type ClientConfig struct {
	// APIEndpoint is the endpoint for the Servicenow API
	// api url of the form  https://instance.service-now.com/ with optional trailing '/'
	APIEndpoint string

	// WebProxyURL is the Teleport address used when building the bodies of the incidents
	// allowing links to the access requests to be built
	WebProxyURL *url.URL

	// ClusterName is the name of the Teleport cluster.
	ClusterName string

	// Username is the username used by the client for basic auth.
	Username string
	// APIToken is the token used for basic auth.
	APIToken string
	// CloseCode is the ServiceNow close code that incidents will be closed with.
	CloseCode string

	// StatusSink receives any status updates from the plugin for
	// further processing. Status updates will be ignored if not set.
	StatusSink common.StatusSink
}

ClientConfig is the config for the servicenow client.

type Config

type Config struct {
	common.BaseConfig
	ClientConfig
	ServiceNow common.GenericAPIConfig

	// Teleport is a handle to the client to use when communicating with
	// the Teleport auth server. The ServiceNow app will create a gRPC-based
	// client on startup if this is not set.
	Client teleport.Client

	// TeleportUser is the name of the Teleport user that will act
	// as the access request approver
	TeleportUser string
}

Config stores the full configuration for the teleport-servicenow plugin to run.

func (*Config) CheckAndSetDefaults

func (c *Config) CheckAndSetDefaults() error

CheckAndSetDefaults checks the config struct for any logical errors, and sets default values if some values are missing. If critical values are missing and we can't set defaults for them, this will return an error.

func (*Config) NewBot

func (c *Config) NewBot(clusterName, webProxyAddr string) (common.MessagingBot, error)

NewBot initializes the new Servicenow message generator (ServicenowBot) takes GenericAPIConfig as an argument.

type Incident

type Incident struct {
	// IncidentID is the sys_id of the incident
	IncidentID string `json:"sys_id,omitempty"`
	// ShortDescription contains a brief summary of the incident.
	ShortDescription string `json:"short_description,omitempty"`
	// Description contains the description of the incident.
	Description string `json:"description,omitempty"`
	// CloseCode contains the close code of the incident once it is resolved.
	CloseCode string `json:"close_code,omitempty"`
	// CloseNotes contains the closing comments on the incident once it is resolved.
	CloseNotes string `json:"close_notes,omitempty"`
	// IncidentState contains the current state the incident is in.
	IncidentState string `json:"incident_state,omitempty"`
	// WorkNotes contains comments on the progress of the incident.
	WorkNotes string `json:"work_notes,omitempty"`
	// Caller is the user on whose behalf the incident is being created. (Must be an existing servicenow user)
	Caller string `json:"caller_id,omitempty"`
	// AssignedTo is the ServiceNow user the incident is assigned.
	AssignedTo string `json:"assigned_to,omitempty"`
}

Incident represents a serviceNow incident.

type PluginData

type PluginData struct {
	RequestData
	ServiceNowData
}

PluginData is a data associated with access request that we store in Teleport using UpdatePluginData API.

func DecodePluginData

func DecodePluginData(dataMap map[string]string) (data PluginData, err error)

DecodePluginData deserializes a string map to PluginData struct.

type RequestData

type RequestData struct {
	// User is the requesting user.
	User string
	// Roles are the roles being requested.
	Roles []string
	// Created is the request creation timestamp.
	Created time.Time
	// RequestReason is the reason for the request.
	RequestReason string
	// ReviewCount is the number of the of the reviews on the access request.
	ReviewsCount int
	// Resolution is the final resolution of the access request.
	Resolution Resolution
	// SystemAnnotations contains key value annotations for the request.
	SystemAnnotations map[string][]string
	// Resources are the resources being requested.
	Resources []string
	// SuggestedReviewers are the suggested reviewers for this access request.
	SuggestedReviewers []string
}

RequestData stores a slice of some request fields in a convenient format.

type Resolution

type Resolution struct {
	// State is the state of the servicenow incident
	State string
	// Reason is the reason the incident is being closed.
	Reason string
}

Resolution stores the resolution state and the servicenow close code.

type ServiceNowData

type ServiceNowData struct {
	// IncidentID is the serviceNow sys_id of the incident
	IncidentID string
}

ServiceNowData is the data associated with access request that we store in Teleport using UpdatePluginData API.

Jump to

Keyboard shortcuts

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